From 06d5d0f39004a7115dceaa8ab642904720325fd9 Mon Sep 17 00:00:00 2001 From: xfnw Date: Thu, 20 Jun 2024 15:02:57 -0400 Subject: [PATCH] html: specify html lang --- src/html.rs | 26 +++++++++++++------------- templates/page.html | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/html.rs b/src/html.rs index 48cb5fc..eef259b 100644 --- a/src/html.rs +++ b/src/html.rs @@ -14,8 +14,9 @@ use std::{cmp::min, collections::BTreeMap, error::Error, fs, io::Write, path::Pa struct PageHtml<'a> { title: String, body: String, + lang: String, + author: String, commit: &'a str, - author: &'a str, modified: NaiveDateTime, year: i32, numdir: usize, @@ -292,17 +293,9 @@ pub fn generate_page( let (created, author) = ctime.get(&full_path).ok_or("missing creation time")?; let modified = mtime.get(&full_path).ok_or("missing modification time")?.0; - let author = res - .keywords() - .find(|k| k.key().eq_ignore_ascii_case("AUTHOR")) - .map(|k| k.value().trim().to_string()) - .unwrap_or_else(|| author.to_string()); - - let year = if let Some(Ok(year)) = res - .keywords() - .find(|k| k.key().eq_ignore_ascii_case("YEAR")) - .map(|k| k.value().trim().parse()) - { + let author = get_keyword(&res, "AUTHOR").unwrap_or_else(|| author.to_string()); + let lang = get_keyword(&res, "LANGUAGE").unwrap_or_else(|| "en".to_string()); + let year = if let Some(Ok(year)) = get_keyword(&res, "YEAR").map(|k| k.parse()) { year } else { DateTime::from_timestamp(created.seconds(), 0) @@ -324,8 +317,9 @@ pub fn generate_page( let template = PageHtml { title: title.clone(), body: html_export.exp.finish(), + lang, + author, commit: short_id, - author: &author, modified: DateTime::from_timestamp(modified.seconds(), 0) .ok_or("broken modification date")? .naive_utc(), @@ -351,6 +345,12 @@ pub fn generate_page( Ok(()) } +fn get_keyword(res: &orgize::Org, keyword: &str) -> Option { + res.keywords() + .find(|k| k.key().eq_ignore_ascii_case(keyword)) + .map(|k| k.value().trim().to_string()) +} + #[cfg(test)] mod tests { use crate::html::*; diff --git a/templates/page.html b/templates/page.html index da387ea..6fe9b7b 100644 --- a/templates/page.html +++ b/templates/page.html @@ -1,5 +1,5 @@ - +