Properly handle creation/update dates
This commit is contained in:
parent
632f35ce62
commit
4d1e3e0cbf
245
Cargo.lock
generated
245
Cargo.lock
generated
|
@ -2,18 +2,75 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[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]]
|
||||
name = "anyhow"
|
||||
version = "1.0.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.1.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "538b056773ee67775e422d15c33169f5415706855814b96505c84ee942f2bae2"
|
||||
dependencies = [
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
|
@ -26,6 +83,29 @@ version = "0.15.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
|
||||
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]]
|
||||
name = "indexmap"
|
||||
version = "2.6.0"
|
||||
|
@ -42,6 +122,27 @@ version = "0.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19fa1db3b285830176c8a940d4e3376679772bee9f58a83dd9285a4a54e30f6e"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.72"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.161"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
|
@ -53,6 +154,7 @@ name = "moonythm"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"jotdown",
|
||||
"once_cell",
|
||||
"pulldown-latex",
|
||||
|
@ -60,6 +162,15 @@ dependencies = [
|
|||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.20.2"
|
||||
|
@ -122,6 +233,12 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.85"
|
||||
|
@ -173,6 +290,134 @@ version = "1.0.13"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.6.20"
|
||||
|
|
|
@ -13,3 +13,4 @@ toml = "0.8.19"
|
|||
# Waiting for https://github.com/rust-lang/rust/issues/109737
|
||||
# before switching to the std version.
|
||||
once_cell = "1.20.2"
|
||||
chrono = { version = "0.4.38", features = ["serde"] }
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
{ role=config }
|
||||
``` =toml
|
||||
created-at = "2024-10-31T15:28:OO"
|
||||
created_at = "2024-11-02T05:13:44+01:00"
|
||||
```
|
||||
|
||||
[home](/)
|
||||
|
||||
----
|
||||
|
||||
# Why I love arcaea
|
||||
|
||||
_Tuesday, October 10, 2024_
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
git show --quiet \
|
||||
--format=%ad \
|
||||
--date=format:"%F" \
|
||||
$(git log --format="%ad %H" \
|
||||
--date=format:%s \
|
||||
--grep="\[date skip\]" \
|
||||
--invert-grep $1 \
|
||||
| sort --reverse \
|
||||
| awk '{ print $2 }' \
|
||||
| head -n1
|
||||
)
|
27
src/html.rs
27
src/html.rs
|
@ -4,6 +4,8 @@ use std::collections::HashMap;
|
|||
|
||||
use anyhow::anyhow;
|
||||
use anyhow::bail;
|
||||
use chrono::DateTime;
|
||||
use chrono::TimeZone;
|
||||
use jotdown::Alignment;
|
||||
use jotdown::Container;
|
||||
use jotdown::Event;
|
||||
|
@ -464,8 +466,15 @@ impl<'s> Writer<'s> {
|
|||
// some metadata on hand.
|
||||
let meta = self.metadata.unwrap();
|
||||
while let Some(label) = renderer.next(&mut out)? {
|
||||
if label == "updated_on" {
|
||||
write!(&mut out, "{}", meta.last_modified)?;
|
||||
if label == "posted_on" {
|
||||
if let Some(d) = meta.config.created_at {
|
||||
write!(&mut out, "Posted on ")?;
|
||||
write_datetime(&d, &mut out)?;
|
||||
} else {
|
||||
write!(&mut out, "Still being conjured ")?;
|
||||
}
|
||||
} else if label == "updated_on" {
|
||||
write_datetime(&meta.last_modified, &mut out)?;
|
||||
} else if label == "word_count" {
|
||||
let wc = meta.word_count;
|
||||
if wc < 400 {
|
||||
|
@ -700,6 +709,20 @@ fn write_escape(
|
|||
}
|
||||
out.write_str(s)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn write_datetime<T: TimeZone>(
|
||||
datetime: &DateTime<T>,
|
||||
mut out: impl std::fmt::Write,
|
||||
) -> std::fmt::Result {
|
||||
let datetime = datetime.to_utc();
|
||||
write!(
|
||||
&mut out,
|
||||
"<time datetime={}>{}</time>",
|
||||
datetime,
|
||||
datetime.format("%a, %d %b %Y")
|
||||
)
|
||||
}
|
||||
// }}}
|
||||
// {{{ Footnotes
|
||||
/// Helper to aggregate footnotes for rendering at the end of the document. It will cache footnote
|
||||
|
|
|
@ -22,13 +22,13 @@ fn copy_recursively(from: &Path, to: &Path) -> anyhow::Result<()> {
|
|||
fn generate_page(path: &Path) -> anyhow::Result<()> {
|
||||
let content_path = PathBuf::from_str("content")?.join(path);
|
||||
|
||||
let djot_input = std::fs::read_to_string(content_path).unwrap();
|
||||
let djot_input = std::fs::read_to_string(&content_path).unwrap();
|
||||
let mut out = String::new();
|
||||
|
||||
let mut page_renderer = template!("templates/page.html", &mut out)?;
|
||||
|
||||
let events = jotdown::Parser::new(&djot_input);
|
||||
let metadata = PageMetadata::new(events, path.to_owned())?;
|
||||
let metadata = PageMetadata::new(events, content_path)?;
|
||||
|
||||
while let Some(label) = page_renderer.current() {
|
||||
if label == "content" {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
use std::{fmt::Write, path::PathBuf, process::Command};
|
||||
|
||||
use anyhow::{anyhow, bail, Context};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use jotdown::{Container, Event};
|
||||
use serde::Deserialize;
|
||||
|
||||
|
@ -9,7 +10,7 @@ use crate::html;
|
|||
|
||||
#[derive(Deserialize, Debug, Default)]
|
||||
pub struct PageConfig {
|
||||
created_at: Option<String>,
|
||||
pub created_at: Option<DateTime<FixedOffset>>,
|
||||
}
|
||||
|
||||
impl PageConfig {
|
||||
|
@ -37,7 +38,7 @@ pub struct PageMetadata {
|
|||
pub toc: Vec<Heading>,
|
||||
pub word_count: usize,
|
||||
pub path: PathBuf,
|
||||
pub last_modified: String,
|
||||
pub last_modified: DateTime<FixedOffset>,
|
||||
}
|
||||
|
||||
impl PageMetadata {
|
||||
|
@ -53,12 +54,21 @@ impl PageMetadata {
|
|||
.first()
|
||||
.ok_or_else(|| anyhow!("No heading found to infer title from"))?;
|
||||
|
||||
let last_modified_output = Command::new("scripts/last_modified.sh")
|
||||
let last_modified_output = Command::new("git")
|
||||
.arg("log")
|
||||
.arg("-1")
|
||||
.arg(r#"--pretty=format:%cI"#)
|
||||
.arg(&path)
|
||||
.output()
|
||||
.with_context(|| anyhow!("Could not read the last modification date for file"))?
|
||||
.stdout;
|
||||
let last_modified = String::from_utf8(last_modified_output)?;
|
||||
let last_modified = DateTime::parse_from_rfc3339(&last_modified).with_context(|| {
|
||||
anyhow!(
|
||||
"Failed to parse datetime returned by git '{}'",
|
||||
last_modified
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(Self {
|
||||
title: title.to_owned(),
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
<ul>
|
||||
<li>
|
||||
<!-- TODO: use actual date -->
|
||||
Posted on 2020-11-23 by <a href="about:blank">prescientmoon</a> on their
|
||||
{{posted_on}} by <a href="about:blank">prescientmoon</a> on their
|
||||
<a href="moonythm.dev">website</a>
|
||||
</li>
|
||||
<li>
|
||||
|
|
Loading…
Reference in a new issue