move away from serde_yml (ai garbage..) to serde_yaml_ng

This commit is contained in:
zyl 2025-01-27 12:00:20 -08:00
parent 855d29d9c4
commit 6edcb6a190
Signed by: zyl
SSH key fingerprint: SHA256:uxxbSXbdroP/OnKBGnEDk5q7EKB2razvstC/KmzdXXs
9 changed files with 43 additions and 44 deletions

34
Cargo.lock generated
View file

@ -115,12 +115,6 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "anyhow"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
[[package]] [[package]]
name = "atom_syndication" name = "atom_syndication"
version = "0.12.6" version = "0.12.6"
@ -1449,16 +1443,6 @@ dependencies = [
"redox_syscall", "redox_syscall",
] ]
[[package]]
name = "libyml"
version = "0.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3302702afa434ffa30847a83305f0a69d6abd74293b6554c18ec85c7ef30c980"
dependencies = [
"anyhow",
"version_check",
]
[[package]] [[package]]
name = "linked-hash-map" name = "linked-hash-map"
version = "0.5.6" version = "0.5.6"
@ -2398,18 +2382,16 @@ dependencies = [
] ]
[[package]] [[package]]
name = "serde_yml" name = "serde_yaml_ng"
version = "0.0.12" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59e2dd588bf1597a252c3b920e0143eb99b0f76e4e082f4c92ce34fbc9e71ddd" checksum = "7b4db627b98b36d4203a7b458cf3573730f2bb591b28871d916dfa9efabfd41f"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"itoa 1.0.14", "itoa 1.0.14",
"libyml",
"memchr",
"ryu", "ryu",
"serde", "serde",
"version_check", "unsafe-libyaml",
] ]
[[package]] [[package]]
@ -2938,6 +2920,12 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
[[package]] [[package]]
name = "url" name = "url"
version = "2.5.4" version = "2.5.4"
@ -3127,7 +3115,7 @@ dependencies = [
"rayon", "rayon",
"rss", "rss",
"serde", "serde",
"serde_yml", "serde_yaml_ng",
"syntect", "syntect",
"tera", "tera",
"time", "time",

View file

@ -31,7 +31,7 @@ pulldown-cmark = {version = "0.12", default-features = false, features = [
rayon = "1" rayon = "1"
rss = {version = "2", features = ["validation"]} rss = {version = "2", features = ["validation"]}
serde = {version = "1", features = ["derive"]} serde = {version = "1", features = ["derive"]}
serde_yml = "0.0.12" serde_yaml_ng = "0.10"
syntect = "5" syntect = "5"
tera = "1" tera = "1"
time = {version = "0.3", features = ["serde-human-readable"]} time = {version = "0.3", features = ["serde-human-readable"]}

View file

@ -25,7 +25,7 @@ struct TemplateData<'a, T> {
/// Custom template data. /// Custom template data.
pub data: T, pub data: T,
/// Userdata supplied from the page. /// Userdata supplied from the page.
pub userdata: serde_yml::Value, pub userdata: serde_yaml_ng::Value,
} }
/// Struct used to build the site. /// Struct used to build the site.
@ -189,7 +189,7 @@ impl SiteBuilder {
let new_html = self.build_page_raw( let new_html = self.build_page_raw(
PageMetadata { PageMetadata {
template: Some(template.to_string()), template: Some(template.to_string()),
userdata: serde_yml::to_value(attr_map)?, userdata: serde_yaml_ng::to_value(attr_map)?,
is_partial: true, is_partial: true,
..Default::default() ..Default::default()
}, },
@ -267,7 +267,8 @@ impl SiteBuilder {
#[allow(clippy::single_match)] #[allow(clippy::single_match)]
match command { match command {
"cdn" => { "cdn" => {
new_src = self.site.config.cdn_url(&new_src)?.to_string(); new_src =
self.site.config.cdn_url(&new_src)?.to_string();
} }
_ => new_src = src, _ => new_src = src,
} }
@ -291,7 +292,8 @@ impl SiteBuilder {
)?; )?;
} }
"cdn" => { "cdn" => {
new_href = self.site.config.cdn_url(&new_href)?.to_string(); new_href =
self.site.config.cdn_url(&new_href)?.to_string();
} }
_ => { _ => {
new_href = href; new_href = href;

View file

@ -30,7 +30,7 @@ impl Extra {
match self { match self {
Self::Basic => { Self::Basic => {
let data: BasicData = serde_yml::from_value(data.inner.clone())?; let data: BasicData = serde_yaml_ng::from_value(data.inner.clone())?;
let content = builder.tera.render(&data.template, &tera::Context::new())?; let content = builder.tera.render(&data.template, &tera::Context::new())?;
append_to(&page, &content, "main.page") append_to(&page, &content, "main.page")
} }
@ -46,7 +46,7 @@ pub struct ExtraData {
pub name: String, pub name: String,
/// The inner data for the extra. /// The inner data for the extra.
#[serde(flatten)] #[serde(flatten)]
pub inner: serde_yml::Value, pub inner: serde_yaml_ng::Value,
} }
/// Gets the extra for the given value. /// Gets the extra for the given value.
@ -90,7 +90,7 @@ fn resource_list_outside(
resources: Vec<ResourceTemplateData<'r>>, resources: Vec<ResourceTemplateData<'r>>,
} }
let data: ResourceListData = serde_yml::from_value(data.inner.clone())?; let data: ResourceListData = serde_yaml_ng::from_value(data.inner.clone())?;
let res_builder = builder let res_builder = builder
.resource_builders .resource_builders

View file

@ -32,7 +32,7 @@ where
pub fn parse(input: String) -> eyre::Result<Self> { pub fn parse(input: String) -> eyre::Result<Self> {
if input.starts_with("---\n") { if input.starts_with("---\n") {
if let Some((frontmatter, content)) = input[3..].split_once("\n---\n") { if let Some((frontmatter, content)) = input[3..].split_once("\n---\n") {
let data = serde_yml::from_str(frontmatter)?; let data = serde_yaml_ng::from_str(frontmatter)?;
return Ok(Self { return Ok(Self {
content: content.to_string(), content: content.to_string(),
data, data,
@ -56,7 +56,7 @@ where
if let Some(data) = &self.data { if let Some(data) = &self.data {
output.push_str("---\n"); output.push_str("---\n");
output.push_str(&serde_yml::to_string(data)?); output.push_str(&serde_yaml_ng::to_string(data)?);
output.push_str("---\n\n"); output.push_str("---\n\n");
} }

View file

@ -100,7 +100,9 @@ impl SiteConfig {
if !config_path.exists() { if !config_path.exists() {
eyre::bail!("no site config found!"); eyre::bail!("no site config found!");
} }
Ok(serde_yml::from_str(&std::fs::read_to_string(config_path)?)?) Ok(serde_yaml_ng::from_str(&std::fs::read_to_string(
config_path,
)?)?)
} }
} }
@ -129,7 +131,7 @@ pub struct PageMetadata {
pub extra: Option<ExtraData>, pub extra: Option<ExtraData>,
/// Custom values passed to the base template. /// Custom values passed to the base template.
#[serde(default)] #[serde(default)]
pub userdata: serde_yml::Value, pub userdata: serde_yaml_ng::Value,
/// Whether this page being rendered is a partial. Set by the builder, not your page metadata. /// Whether this page being rendered is a partial. Set by the builder, not your page metadata.
#[serde(skip)] #[serde(skip)]
pub is_partial: bool, pub is_partial: bool,

View file

@ -135,7 +135,7 @@ fn main() -> eyre::Result<()> {
let config = SiteConfig::new(base_url.clone(), cdn_url.unwrap_or(base_url), title); let config = SiteConfig::new(base_url.clone(), cdn_url.unwrap_or(base_url), title);
std::fs::write( std::fs::write(
cli.site.join(SiteConfig::FILENAME), cli.site.join(SiteConfig::FILENAME),
serde_yml::to_string(&config)?, serde_yaml_ng::to_string(&config)?,
)?; )?;
DEFAULT_PROJECT.extract(&cli.site)?; DEFAULT_PROJECT.extract(&cli.site)?;
std::fs::create_dir(cli.site.join(webdog::ROOT_PATH))?; std::fs::create_dir(cli.site.join(webdog::ROOT_PATH))?;
@ -227,7 +227,7 @@ fn main() -> eyre::Result<()> {
config.resources.insert(id.clone(), resource_config); config.resources.insert(id.clone(), resource_config);
std::fs::write(config_path, serde_yml::to_string(&config)?)?; std::fs::write(config_path, serde_yaml_ng::to_string(&config)?)?;
let resource_path = cli.site.join(webdog::RESOURCES_PATH).join(&id); let resource_path = cli.site.join(webdog::RESOURCES_PATH).join(&id);
std::fs::create_dir_all(&resource_path)?; std::fs::create_dir_all(&resource_path)?;
@ -240,7 +240,7 @@ fn main() -> eyre::Result<()> {
tags: vec!["first".to_string()], tags: vec!["first".to_string()],
cdn_file: None, cdn_file: None,
desc: Some(format!("This is the first {name} :)")), desc: Some(format!("This is the first {name} :)")),
inner: serde_yml::Value::Null, inner: serde_yaml_ng::Value::Null,
draft: true, draft: true,
}, },
)?; )?;
@ -256,7 +256,11 @@ fn main() -> eyre::Result<()> {
title, title,
template, template,
} => { } => {
let page_path = cli.site.join(webdog::PAGES_PATH).join(&id).with_extension("md"); let page_path = cli
.site
.join(webdog::PAGES_PATH)
.join(&id)
.with_extension("md");
let dir = page_path.parent().expect("should never fail"); let dir = page_path.parent().expect("should never fail");
if page_path.exists() { if page_path.exists() {
eprintln!("page already exists!"); eprintln!("page already exists!");
@ -310,7 +314,7 @@ fn main() -> eyre::Result<()> {
tags, tags,
cdn_file: None, cdn_file: None,
desc: description, desc: description,
inner: serde_yml::Value::Null, inner: serde_yaml_ng::Value::Null,
draft: !skip_draft, draft: !skip_draft,
}, },
)?; )?;

View file

@ -10,8 +10,11 @@ use serde::{Deserialize, Serialize};
use time::{format_description::well_known::Rfc2822, OffsetDateTime}; use time::{format_description::well_known::Rfc2822, OffsetDateTime};
use crate::{ use crate::{
builder::SiteBuilder, frontmatter::FrontMatterRequired, link_list::Link, builder::SiteBuilder,
util::{self, format_timestamp}, PageMetadata, frontmatter::FrontMatterRequired,
link_list::Link,
util::{self, format_timestamp},
PageMetadata,
}; };
/// Metadata for resources. /// Metadata for resources.
@ -30,7 +33,7 @@ pub struct ResourceMetadata {
pub desc: Option<String>, pub desc: Option<String>,
/// Extra resource data not included. /// Extra resource data not included.
#[serde(flatten)] #[serde(flatten)]
pub inner: serde_yml::Value, pub inner: serde_yaml_ng::Value,
/// Whether the resource is a draft. Drafts can be committed without being published to the live site. /// Whether the resource is a draft. Drafts can be committed without being published to the live site.
#[serde(default)] #[serde(default)]
pub draft: bool, pub draft: bool,

View file

@ -95,7 +95,7 @@ fn create(
builder.build_all_resources()?; builder.build_all_resources()?;
} }
} else if relative_path.display().to_string() == SiteConfig::FILENAME { } else if relative_path.display().to_string() == SiteConfig::FILENAME {
let new_config = serde_yml::from_str(&std::fs::read_to_string(path)?)?; let new_config = serde_yaml_ng::from_str(&std::fs::read_to_string(path)?)?;
builder.site.config = new_config; builder.site.config = new_config;
builder.reload()?; builder.reload()?;
builder.build_all()?; builder.build_all()?;