mirror of
https://github.com/RGBCube/Site
synced 2025-08-01 13:37:49 +00:00
Add metadata
This commit is contained in:
parent
23ba898583
commit
1c85d7e720
4 changed files with 51 additions and 5 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -310,6 +310,7 @@ dependencies = [
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
"serde",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"windows-targets 0.48.5",
|
"windows-targets 0.48.5",
|
||||||
]
|
]
|
||||||
|
@ -1165,6 +1166,19 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_yaml"
|
||||||
|
version = "0.9.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1bf28c79a99f70ee1f1d83d10c875d2e70618417fda01ad1785e027579d9d38"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
"unsafe-libyaml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook-registry"
|
name = "signal-hook-registry"
|
||||||
version = "1.4.1"
|
version = "1.4.1"
|
||||||
|
@ -1192,6 +1206,8 @@ dependencies = [
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
"minify-js",
|
"minify-js",
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
|
"serde",
|
||||||
|
"serde_yaml",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-http",
|
"tower-http",
|
||||||
|
@ -1435,6 +1451,12 @@ version = "0.1.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
|
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unsafe-libyaml"
|
||||||
|
version = "0.2.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
|
|
@ -14,7 +14,7 @@ axum = { version = "0.7.3", features = [ "macros" ] }
|
||||||
axum-server = { version = "0.6.0", features = [ "tls-rustls" ] }
|
axum-server = { version = "0.6.0", features = [ "tls-rustls" ] }
|
||||||
bytes = "1.5.0"
|
bytes = "1.5.0"
|
||||||
cargo_toml = "0.17.2"
|
cargo_toml = "0.17.2"
|
||||||
chrono = "0.4.31"
|
chrono = { version = "0.4.31", features = [ "serde" ] }
|
||||||
clap = { version = "4.4.12", features = [ "derive" ] }
|
clap = { version = "4.4.12", features = [ "derive" ] }
|
||||||
embed = { git = "https://github.com/RGBCube/embed-rs" }
|
embed = { git = "https://github.com/RGBCube/embed-rs" }
|
||||||
env_logger = "0.10.1"
|
env_logger = "0.10.1"
|
||||||
|
@ -23,6 +23,8 @@ maud = { git = "https://github.com/lambda-fairy/maud", features =
|
||||||
mime_guess = "2.0.4"
|
mime_guess = "2.0.4"
|
||||||
minify-js = "0.6.0"
|
minify-js = "0.6.0"
|
||||||
pulldown-cmark = "0.9.3"
|
pulldown-cmark = "0.9.3"
|
||||||
|
serde = { version = "1.0.195", features = [ "derive" ] }
|
||||||
|
serde_yaml = "0.9.30"
|
||||||
tokio = { version = "1.35.1", features = [ "full" ] }
|
tokio = { version = "1.35.1", features = [ "full" ] }
|
||||||
tower = "0.4.13"
|
tower = "0.4.13"
|
||||||
tower-http = { version = "0.5.0", features = [ "trace" ] }
|
tower-http = { version = "0.5.0", features = [ "trace" ] }
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
title: About
|
||||||
|
---
|
||||||
|
|
||||||
### Hi.
|
### Hi.
|
||||||
|
|
||||||
Test 123
|
Test 123
|
||||||
|
|
|
@ -13,7 +13,9 @@ use axum::{
|
||||||
IntoResponse,
|
IntoResponse,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use chrono::NaiveDate;
|
||||||
use maud::Markup;
|
use maud::Markup;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::not_found,
|
errors::not_found,
|
||||||
|
@ -24,7 +26,17 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static PAGES: LazyLock<HashMap<String, Markup>> = LazyLock::new(|| {
|
#[derive(Deserialize)]
|
||||||
|
struct Metadata {
|
||||||
|
title: String,
|
||||||
|
// TODO: Use these for blog articles.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
date: Option<NaiveDate>,
|
||||||
|
#[allow(dead_code)]
|
||||||
|
tags: Option<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
static PAGES: LazyLock<HashMap<String, (Metadata, Markup)>> = LazyLock::new(|| {
|
||||||
let routes_path = path::Path::new(file!())
|
let routes_path = path::Path::new(file!())
|
||||||
.parent()
|
.parent()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -44,10 +56,16 @@ static PAGES: LazyLock<HashMap<String, Markup>> = LazyLock::new(|| {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let content = String::from_utf8(file.content().to_vec()).unwrap();
|
||||||
|
|
||||||
|
let (metadata, content) = content.split_once("---").unwrap();
|
||||||
|
|
||||||
|
let metadata: Metadata = serde_yaml::from_str(metadata).unwrap();
|
||||||
|
|
||||||
log::info!("Adding page {path}");
|
log::info!("Adding page {path}");
|
||||||
pages.insert(
|
pages.insert(
|
||||||
path.to_string().strip_suffix(".md").unwrap().to_string(),
|
path.to_string().strip_suffix(".md").unwrap().to_string(),
|
||||||
markdown::parse(&String::from_utf8(file.content().to_vec()).unwrap()),
|
(metadata, markdown::parse(&content)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +73,9 @@ static PAGES: LazyLock<HashMap<String, Markup>> = LazyLock::new(|| {
|
||||||
});
|
});
|
||||||
|
|
||||||
pub async fn handler(Path(path): Path<String>) -> Response<Body> {
|
pub async fn handler(Path(path): Path<String>) -> Response<Body> {
|
||||||
if let Some(body) = PAGES.get(&path) {
|
if let Some((metadata, body)) = PAGES.get(&path) {
|
||||||
Html(text::create(Some("test"), Page::from_str(&path), &body).into_string()).into_response()
|
Html(text::create(Some(&metadata.title), Page::from_str(&path), &body).into_string())
|
||||||
|
.into_response()
|
||||||
} else {
|
} else {
|
||||||
not_found::handler().await.into_response()
|
not_found::handler().await.into_response()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue