Replace SVGs with custom icon font

This commit is contained in:
Luke Street
2025-04-25 23:50:25 -06:00
parent 0b13972571
commit 09b68b68be
10 changed files with 89 additions and 67 deletions
-28
View File
@@ -5,7 +5,6 @@ pub mod treemap;
use std::str::FromStr;
use axum::{
extract::Path,
http::{StatusCode, header},
response::{IntoResponse, Response},
};
@@ -17,33 +16,6 @@ pub fn image_mime_from_ext(ext: &str) -> Option<Mime> {
.map(|format| Mime::from_str(format.to_mime_type()).unwrap())
}
pub async fn get_asset(Path(filename): Path<String>) -> Result<Response, AppError> {
let path = join_normalized("assets", &filename);
let Some(ext) = path.extension() else {
return Err(AppError::Status(StatusCode::NOT_FOUND));
};
let content_type = if let Some(format) = image::ImageFormat::from_extension(ext) {
format.to_mime_type()
} else {
match ext.to_str() {
Some("svg") => mime::IMAGE_SVG.as_ref(),
_ => return Err(AppError::Status(StatusCode::NOT_FOUND)),
}
};
let output = tokio::fs::read(path).await?;
Ok((
[
(header::CONTENT_TYPE, content_type),
#[cfg(not(debug_assertions))]
(header::CACHE_CONTROL, "public, max-age=3600"),
#[cfg(debug_assertions)]
(header::CACHE_CONTROL, "no-cache"),
],
output,
)
.into_response())
}
pub async fn get_og() -> Result<Response, AppError> {
let path = join_normalized("assets", "og.svg");
let svg_src = tokio::fs::read_to_string(&path)
+2 -2
View File
@@ -44,8 +44,8 @@ pub async fn login(
}
Ok(html! {
(DOCTYPE)
html {
head lang="en" {
html lang="en" {
head {
meta charset="utf-8";
title { "Logging in... • decomp.dev" }
meta http-equiv="refresh" content=(format!("0;URL={redirect_url}"));
+1 -5
View File
@@ -133,11 +133,7 @@ pub fn nav_links() -> Markup {
a href="https://wiki.decomp.dev" { "Wiki" }
}
li {
a #theme-toggle href="#" title="Toggle theme" {
(PreEscaped(r#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="1.33em" height="1.33em">
<path d="M7.5,2C5.71,3.15 4.5,5.18 4.5,7.5C4.5,9.82 5.71,11.85 7.53,13C4.46,13 2,10.54 2,7.5A5.5,5.5 0 0,1 7.5,2M19.07,3.5L20.5,4.93L4.93,20.5L3.5,19.07L19.07,3.5M12.89,5.93L11.41,5L9.97,6L10.39,4.3L9,3.24L10.75,3.12L11.33,1.47L12,3.1L13.73,3.13L12.38,4.26L12.89,5.93M9.59,9.54L8.43,8.81L7.31,9.59L7.65,8.27L6.56,7.44L7.92,7.35L8.37,6.06L8.88,7.33L10.24,7.36L9.19,8.23L9.59,9.54M19,13.5A5.5,5.5 0 0,1 13.5,19C12.28,19 11.15,18.6 10.24,17.93L17.93,10.24C18.6,11.15 19,12.28 19,13.5M14.6,20.08L17.37,18.93L17.13,22.28L14.6,20.08M18.93,17.38L20.08,14.61L22.28,17.15L18.93,17.38M20.08,12.42L18.94,9.64L22.28,9.88L20.08,12.42M9.63,18.93L12.4,20.08L9.87,22.27L9.63,18.93Z" />
</svg>"#))
}
a #theme-toggle .icon-theme-light-dark href="#" title="Toggle theme" {}
}
}
}
+6 -6
View File
@@ -39,8 +39,8 @@ pub async fn manage(
Ok(html! {
(DOCTYPE)
html {
head lang="en" {
html lang="en" {
head {
meta charset="utf-8";
title { "Manage • decomp.dev" }
(header())
@@ -138,8 +138,8 @@ async fn render_new(
Ok(html! {
(DOCTYPE)
html {
head lang="en" {
html lang="en" {
head {
meta charset="utf-8";
title { "New Project • decomp.dev" }
(header())
@@ -351,8 +351,8 @@ async fn render_manage_project(
html! {
(DOCTYPE)
html {
head lang="en" {
html lang="en" {
head {
meta charset="utf-8";
title { (project_short_name) " • Manage" }
(header())
-1
View File
@@ -32,7 +32,6 @@ pub fn build_router() -> Router<AppState> {
.route("/manage/{owner}/{repo}", get(manage::manage_project))
.route("/manage/{owner}/{repo}", post(manage::manage_project_save))
.route("/manage/{owner}/{repo}/refresh", post(manage::manage_project_refresh))
.route("/assets/{*filename}", get(decomp_dev_images::get_asset))
.route("/og.png", get(decomp_dev_images::get_og))
.route("/", get(project::get_projects))
.route("/{owner}/{repo}", get(report::get_report))
+3 -4
View File
@@ -157,8 +157,8 @@ pub async fn get_projects(
let rendered = html! {
(DOCTYPE)
html {
head lang="en" {
html lang="en" {
head {
meta charset="utf-8";
title { "Projects • decomp.dev" }
(header())
@@ -251,8 +251,7 @@ fn project_fragment(
}
@if let Some(platform) = &info.project.platform {
@let platform_name = Platform::from_str(platform).map(|p| p.name()).unwrap_or(platform);
img class="platform-icon" src=(format!("/assets/platforms/{}.svg", platform))
alt=(platform_name) title=(platform_name) width="24" height="24";
span class=(format!("platform-icon icon-{platform}")) title=(platform_name) {}
}
}
h6 {
+24 -10
View File
@@ -664,8 +664,8 @@ async fn render_report(
Ok(html! {
(DOCTYPE)
html {
head lang="en" {
html lang="en" {
head {
meta charset="utf-8";
title { (project_short_name) " • Progress Report" }
(header())
@@ -710,9 +710,19 @@ async fn render_report(
details class="dropdown" {
summary {}
ul dir="rtl" {
li { a href=(project_history_path) { "History" } }
li {
a href=(project_history_path) {
"History "
span .icon-chart-line { " " }
}
}
@if can_manage {
li { a href=(project_manage_path) { "Manage" } }
li {
a href=(project_manage_path) {
"Manage "
span .icon-cog { " " }
}
}
}
}
}
@@ -764,20 +774,24 @@ async fn render_report(
div role="group" {
@if let Some(prev_commit_path) = prev_commit_path {
a role="button" class="outline secondary" href=(prev_commit_path) {
"Previous"
span .icon-left-open {}
" Previous"
}
} @else {
button disabled class="outline secondary" {
"Previous"
span .icon-left-open {}
" Previous"
}
}
@if let Some(next_commit_path) = next_commit_path {
a role="button" class="outline secondary" href=(next_commit_path) {
"Next"
"Next "
span .icon-right-open {}
}
} @else {
button disabled class="outline secondary" {
"Next"
"Next "
span .icon-right-open {}
}
}
@if let Some(latest_commit_path) = latest_commit_path {
@@ -899,8 +913,8 @@ async fn render_history(
Ok(html! {
(DOCTYPE)
html {
head lang="en" {
html lang="en" {
head {
meta charset="utf-8";
title { (project_short_name) " • Progress History" }
(header())