add favicon

This commit is contained in:
liquidex 2024-03-08 22:40:19 +01:00
parent b6e803cfee
commit 45981bdb3d
37 changed files with 245 additions and 4 deletions

137
Cargo.lock generated
View file

@ -26,6 +26,21 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "anstream" name = "anstream"
version = "0.3.2" version = "0.3.2"
@ -201,6 +216,12 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "bumpalo"
version = "3.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa"
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
version = "1.14.3" version = "1.14.3"
@ -234,6 +255,20 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-targets 0.52.3",
]
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.3.22" version = "4.3.22"
@ -306,6 +341,12 @@ dependencies = [
"walkdir", "walkdir",
] ]
[[package]]
name = "core-foundation-sys"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.9" version = "0.2.9"
@ -693,6 +734,29 @@ dependencies = [
"tokio", "tokio",
] ]
[[package]]
name = "iana-time-zone"
version = "0.1.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.5.0" version = "0.5.0"
@ -757,6 +821,15 @@ dependencies = [
"rayon", "rayon",
] ]
[[package]]
name = "js-sys"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d"
dependencies = [
"wasm-bindgen",
]
[[package]] [[package]]
name = "lebe" name = "lebe"
version = "0.5.2" version = "0.5.2"
@ -1496,6 +1569,7 @@ dependencies = [
"anyhow", "anyhow",
"axum", "axum",
"base64", "base64",
"chrono",
"clap", "clap",
"codespan-reporting", "codespan-reporting",
"copy_dir", "copy_dir",
@ -1620,6 +1694,60 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
[[package]] [[package]]
name = "weezl" name = "weezl"
version = "0.1.8" version = "0.1.8"
@ -1657,6 +1785,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets 0.52.3",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.48.0" version = "0.48.0"

View file

@ -28,3 +28,4 @@ walkdir = "2.3.3"
ulid = "1.0.0" ulid = "1.0.0"
url = "2.5.0" url = "2.5.0"
base64 = "0.21.7" base64 = "0.21.7"
chrono = "0.4.35"

View file

@ -19,6 +19,7 @@ use walkdir::WalkDir;
use crate::{ use crate::{
cli::parse::parse_tree_with_diagnostics, cli::parse::parse_tree_with_diagnostics,
config::{Config, ConfigDerivedData}, config::{Config, ConfigDerivedData},
fun::seasons::Season,
html::{ html::{
breadcrumbs::breadcrumbs_to_html, breadcrumbs::breadcrumbs_to_html,
navmap::{build_navigation_map, NavigationMap}, navmap::{build_navigation_map, NavigationMap},
@ -68,13 +69,15 @@ pub struct Thumbnail {
#[derive(Serialize)] #[derive(Serialize)]
struct StaticTemplateData<'a> { struct StaticTemplateData<'a> {
config: &'a Config, config: &'a Config,
season: Option<Season>,
} }
#[derive(Serialize)] #[derive(Serialize)]
struct PageTemplateData<'a> { struct PageTemplateData<'a> {
pub config: &'a Config, config: &'a Config,
pub page: Page, page: Page,
pub feeds: &'a HashMap<String, Feed>, feeds: &'a HashMap<String, Feed>,
season: Option<Season>,
} }
impl Generator { impl Generator {
@ -231,7 +234,13 @@ impl Generator {
for (name, &file_id) in &template_file_ids { for (name, &file_id) in &template_file_ids {
let filename = name.rsplit_once('/').unwrap_or(("", name)).1; let filename = name.rsplit_once('/').unwrap_or(("", name)).1;
if !filename.starts_with('_') { if !filename.starts_with('_') {
let templated_html = match handlebars.render(name, &StaticTemplateData { config }) { let templated_html = match handlebars.render(
name,
&StaticTemplateData {
config,
season: Season::current(),
},
) {
Ok(html) => html, Ok(html) => html,
Err(error) => { Err(error) => {
Self::wrangle_handlebars_error_into_diagnostic( Self::wrangle_handlebars_error_into_diagnostic(
@ -307,6 +316,7 @@ impl Generator {
tree, tree,
}, },
feeds: &feeds, feeds: &feeds,
season: Season::current(),
}; };
let template_name = roots let template_name = roots
.attributes .attributes

View file

@ -0,0 +1 @@
pub mod seasons;

View file

@ -0,0 +1,78 @@
use chrono::{Datelike, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum Season {
Spring,
Summer,
Autumn,
Winter,
}
impl Season {
pub fn on(month: u32, day: u32) -> Option<Season> {
let md = (month, day);
Some(match () {
_ if ((1, 1)..=(3, 20)).contains(&md) => Season::Winter,
_ if ((3, 21)..=(6, 21)).contains(&md) => Season::Spring,
_ if ((6, 22)..=(9, 22)).contains(&md) => Season::Summer,
_ if ((9, 23)..=(12, 21)).contains(&md) => Season::Autumn,
_ if ((12, 22)..=(12, 31)).contains(&md) => Season::Winter,
// Just in case something really darn weird happens to the calendar.
_ => return None,
})
}
pub fn current() -> Option<Season> {
let now = Utc::now();
Self::on(now.month(), now.day())
}
}
#[cfg(test)]
mod tests {
use crate::fun::seasons::Season;
#[test]
fn all_the_seasons() {
assert_eq!(Season::on(0, 0), None);
assert_eq!(Season::on(1, 1), Some(Season::Winter));
assert_eq!(Season::on(1, 15), Some(Season::Winter));
assert_eq!(Season::on(1, 31), Some(Season::Winter));
assert_eq!(Season::on(2, 1), Some(Season::Winter));
assert_eq!(Season::on(2, 28), Some(Season::Winter));
assert_eq!(Season::on(2, 29), Some(Season::Winter));
assert_eq!(Season::on(3, 1), Some(Season::Winter));
assert_eq!(Season::on(3, 20), Some(Season::Winter));
assert_eq!(Season::on(3, 21), Some(Season::Spring));
assert_eq!(Season::on(3, 22), Some(Season::Spring));
assert_eq!(Season::on(4, 1), Some(Season::Spring));
assert_eq!(Season::on(4, 30), Some(Season::Spring));
assert_eq!(Season::on(5, 1), Some(Season::Spring));
assert_eq!(Season::on(5, 31), Some(Season::Spring));
assert_eq!(Season::on(6, 1), Some(Season::Spring));
assert_eq!(Season::on(6, 21), Some(Season::Spring));
assert_eq!(Season::on(6, 22), Some(Season::Summer));
assert_eq!(Season::on(6, 30), Some(Season::Summer));
assert_eq!(Season::on(7, 1), Some(Season::Summer));
assert_eq!(Season::on(7, 31), Some(Season::Summer));
assert_eq!(Season::on(8, 1), Some(Season::Summer));
assert_eq!(Season::on(8, 31), Some(Season::Summer));
assert_eq!(Season::on(9, 1), Some(Season::Summer));
assert_eq!(Season::on(9, 22), Some(Season::Summer));
assert_eq!(Season::on(9, 23), Some(Season::Autumn));
assert_eq!(Season::on(9, 30), Some(Season::Autumn));
assert_eq!(Season::on(10, 1), Some(Season::Autumn));
assert_eq!(Season::on(10, 31), Some(Season::Autumn));
assert_eq!(Season::on(11, 1), Some(Season::Autumn));
assert_eq!(Season::on(11, 30), Some(Season::Autumn));
assert_eq!(Season::on(12, 1), Some(Season::Autumn));
assert_eq!(Season::on(12, 21), Some(Season::Autumn));
assert_eq!(Season::on(12, 22), Some(Season::Winter));
assert_eq!(Season::on(12, 22), Some(Season::Winter));
assert_eq!(Season::on(12, 31), Some(Season::Winter));
assert_eq!(Season::on(12, 32), None);
assert_eq!(Season::on(21, 37), None);
}
}

View file

@ -11,6 +11,7 @@ use log::{error, info, warn};
mod cli; mod cli;
mod config; mod config;
mod fun;
mod html; mod html;
mod paths; mod paths;
mod state; mod state;

BIN
static/favicon/@16x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
static/favicon/@1x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

BIN
static/favicon/@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

BIN
static/favicon/@32x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
static/favicon/@4x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

BIN
static/favicon/@8x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -41,3 +41,16 @@ It just needs to be a string replacement.
<meta property="og:image" content="{{ page.thumbnail.url }}"> <meta property="og:image" content="{{ page.thumbnail.url }}">
<meta property="og:image:alt" content="{{ page.thumbnail.alt }}"> <meta property="og:image:alt" content="{{ page.thumbnail.alt }}">
{{/if}} {{/if}}
<link rel="icon" sizes="16x16" href="{{ config.site }}/static/favicon/{{ season }}@1x.png">
<link rel="icon" sizes="32x32" href="{{ config.site }}/static/favicon/{{ season }}@2x.png">
<link rel="icon" sizes="64x64" href="{{ config.site }}/static/favicon/{{ season }}@4x.png">
<link rel="icon" sizes="128x128" href="{{ config.site }}/static/favicon/{{ season }}@8x.png">
<link rel="icon" sizes="256x256" href="{{ config.site }}/static/favicon/{{ season }}@16x.png">
<link rel="icon" sizes="512x512" href="{{ config.site }}/static/favicon/{{ season }}@32x.png">
<link rel="apple-touch-icon" sizes="16x16" href="{{ config.site }}/static/favicon/{{ season }}@1x.png">
<link rel="apple-touch-icon" sizes="32x32" href="{{ config.site }}/static/favicon/{{ season }}@2x.png">
<link rel="apple-touch-icon" sizes="64x64" href="{{ config.site }}/static/favicon/{{ season }}@4x.png">
<link rel="apple-touch-icon" sizes="128x128" href="{{ config.site }}/static/favicon/{{ season }}@8x.png">
<link rel="apple-touch-icon" sizes="256x256" href="{{ config.site }}/static/favicon/{{ season }}@16x.png">
<link rel="apple-touch-icon" sizes="512x512" href="{{ config.site }}/static/favicon/{{ season }}@32x.png">