add favicon
This commit is contained in:
parent
b6e803cfee
commit
45981bdb3d
37 changed files with 245 additions and 4 deletions
|
@ -28,3 +28,4 @@ walkdir = "2.3.3"
|
|||
ulid = "1.0.0"
|
||||
url = "2.5.0"
|
||||
base64 = "0.21.7"
|
||||
chrono = "0.4.35"
|
||||
|
|
|
@ -19,6 +19,7 @@ use walkdir::WalkDir;
|
|||
use crate::{
|
||||
cli::parse::parse_tree_with_diagnostics,
|
||||
config::{Config, ConfigDerivedData},
|
||||
fun::seasons::Season,
|
||||
html::{
|
||||
breadcrumbs::breadcrumbs_to_html,
|
||||
navmap::{build_navigation_map, NavigationMap},
|
||||
|
@ -68,13 +69,15 @@ pub struct Thumbnail {
|
|||
#[derive(Serialize)]
|
||||
struct StaticTemplateData<'a> {
|
||||
config: &'a Config,
|
||||
season: Option<Season>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct PageTemplateData<'a> {
|
||||
pub config: &'a Config,
|
||||
pub page: Page,
|
||||
pub feeds: &'a HashMap<String, Feed>,
|
||||
config: &'a Config,
|
||||
page: Page,
|
||||
feeds: &'a HashMap<String, Feed>,
|
||||
season: Option<Season>,
|
||||
}
|
||||
|
||||
impl Generator {
|
||||
|
@ -231,7 +234,13 @@ impl Generator {
|
|||
for (name, &file_id) in &template_file_ids {
|
||||
let filename = name.rsplit_once('/').unwrap_or(("", name)).1;
|
||||
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,
|
||||
Err(error) => {
|
||||
Self::wrangle_handlebars_error_into_diagnostic(
|
||||
|
@ -307,6 +316,7 @@ impl Generator {
|
|||
tree,
|
||||
},
|
||||
feeds: &feeds,
|
||||
season: Season::current(),
|
||||
};
|
||||
let template_name = roots
|
||||
.attributes
|
||||
|
|
1
crates/treehouse/src/fun.rs
Normal file
1
crates/treehouse/src/fun.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod seasons;
|
78
crates/treehouse/src/fun/seasons.rs
Normal file
78
crates/treehouse/src/fun/seasons.rs
Normal 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);
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ use log::{error, info, warn};
|
|||
|
||||
mod cli;
|
||||
mod config;
|
||||
mod fun;
|
||||
mod html;
|
||||
mod paths;
|
||||
mod state;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue