mirror of
https://github.com/zyllian/webdog.git
synced 2025-01-30 22:42:33 -08:00
move away from serde_yml (ai garbage..) to serde_yaml_ng
This commit is contained in:
parent
855d29d9c4
commit
6edcb6a190
9 changed files with 43 additions and 44 deletions
34
Cargo.lock
generated
34
Cargo.lock
generated
|
@ -115,12 +115,6 @@ dependencies = [
|
|||
"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]]
|
||||
name = "atom_syndication"
|
||||
version = "0.12.6"
|
||||
|
@ -1449,16 +1443,6 @@ dependencies = [
|
|||
"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]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.6"
|
||||
|
@ -2398,18 +2382,16 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_yml"
|
||||
version = "0.0.12"
|
||||
name = "serde_yaml_ng"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59e2dd588bf1597a252c3b920e0143eb99b0f76e4e082f4c92ce34fbc9e71ddd"
|
||||
checksum = "7b4db627b98b36d4203a7b458cf3573730f2bb591b28871d916dfa9efabfd41f"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"itoa 1.0.14",
|
||||
"libyml",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
"version_check",
|
||||
"unsafe-libyaml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2938,6 +2920,12 @@ version = "1.0.14"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||
|
||||
[[package]]
|
||||
name = "unsafe-libyaml"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.5.4"
|
||||
|
@ -3127,7 +3115,7 @@ dependencies = [
|
|||
"rayon",
|
||||
"rss",
|
||||
"serde",
|
||||
"serde_yml",
|
||||
"serde_yaml_ng",
|
||||
"syntect",
|
||||
"tera",
|
||||
"time",
|
||||
|
|
|
@ -31,7 +31,7 @@ pulldown-cmark = {version = "0.12", default-features = false, features = [
|
|||
rayon = "1"
|
||||
rss = {version = "2", features = ["validation"]}
|
||||
serde = {version = "1", features = ["derive"]}
|
||||
serde_yml = "0.0.12"
|
||||
serde_yaml_ng = "0.10"
|
||||
syntect = "5"
|
||||
tera = "1"
|
||||
time = {version = "0.3", features = ["serde-human-readable"]}
|
||||
|
|
|
@ -25,7 +25,7 @@ struct TemplateData<'a, T> {
|
|||
/// Custom template data.
|
||||
pub data: T,
|
||||
/// Userdata supplied from the page.
|
||||
pub userdata: serde_yml::Value,
|
||||
pub userdata: serde_yaml_ng::Value,
|
||||
}
|
||||
|
||||
/// Struct used to build the site.
|
||||
|
@ -189,7 +189,7 @@ impl SiteBuilder {
|
|||
let new_html = self.build_page_raw(
|
||||
PageMetadata {
|
||||
template: Some(template.to_string()),
|
||||
userdata: serde_yml::to_value(attr_map)?,
|
||||
userdata: serde_yaml_ng::to_value(attr_map)?,
|
||||
is_partial: true,
|
||||
..Default::default()
|
||||
},
|
||||
|
@ -267,7 +267,8 @@ impl SiteBuilder {
|
|||
#[allow(clippy::single_match)]
|
||||
match command {
|
||||
"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,
|
||||
}
|
||||
|
@ -291,7 +292,8 @@ impl SiteBuilder {
|
|||
)?;
|
||||
}
|
||||
"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;
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Extra {
|
|||
|
||||
match self {
|
||||
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())?;
|
||||
append_to(&page, &content, "main.page")
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ pub struct ExtraData {
|
|||
pub name: String,
|
||||
/// The inner data for the extra.
|
||||
#[serde(flatten)]
|
||||
pub inner: serde_yml::Value,
|
||||
pub inner: serde_yaml_ng::Value,
|
||||
}
|
||||
|
||||
/// Gets the extra for the given value.
|
||||
|
@ -90,7 +90,7 @@ fn resource_list_outside(
|
|||
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
|
||||
.resource_builders
|
||||
|
|
|
@ -32,7 +32,7 @@ where
|
|||
pub fn parse(input: String) -> eyre::Result<Self> {
|
||||
if input.starts_with("---\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 {
|
||||
content: content.to_string(),
|
||||
data,
|
||||
|
@ -56,7 +56,7 @@ where
|
|||
|
||||
if let Some(data) = &self.data {
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,9 @@ impl SiteConfig {
|
|||
if !config_path.exists() {
|
||||
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>,
|
||||
/// Custom values passed to the base template.
|
||||
#[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.
|
||||
#[serde(skip)]
|
||||
pub is_partial: bool,
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -135,7 +135,7 @@ fn main() -> eyre::Result<()> {
|
|||
let config = SiteConfig::new(base_url.clone(), cdn_url.unwrap_or(base_url), title);
|
||||
std::fs::write(
|
||||
cli.site.join(SiteConfig::FILENAME),
|
||||
serde_yml::to_string(&config)?,
|
||||
serde_yaml_ng::to_string(&config)?,
|
||||
)?;
|
||||
DEFAULT_PROJECT.extract(&cli.site)?;
|
||||
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);
|
||||
|
||||
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);
|
||||
std::fs::create_dir_all(&resource_path)?;
|
||||
|
@ -240,7 +240,7 @@ fn main() -> eyre::Result<()> {
|
|||
tags: vec!["first".to_string()],
|
||||
cdn_file: None,
|
||||
desc: Some(format!("This is the first {name} :)")),
|
||||
inner: serde_yml::Value::Null,
|
||||
inner: serde_yaml_ng::Value::Null,
|
||||
draft: true,
|
||||
},
|
||||
)?;
|
||||
|
@ -256,7 +256,11 @@ fn main() -> eyre::Result<()> {
|
|||
title,
|
||||
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");
|
||||
if page_path.exists() {
|
||||
eprintln!("page already exists!");
|
||||
|
@ -310,7 +314,7 @@ fn main() -> eyre::Result<()> {
|
|||
tags,
|
||||
cdn_file: None,
|
||||
desc: description,
|
||||
inner: serde_yml::Value::Null,
|
||||
inner: serde_yaml_ng::Value::Null,
|
||||
draft: !skip_draft,
|
||||
},
|
||||
)?;
|
||||
|
|
|
@ -10,8 +10,11 @@ use serde::{Deserialize, Serialize};
|
|||
use time::{format_description::well_known::Rfc2822, OffsetDateTime};
|
||||
|
||||
use crate::{
|
||||
builder::SiteBuilder, frontmatter::FrontMatterRequired, link_list::Link,
|
||||
util::{self, format_timestamp}, PageMetadata,
|
||||
builder::SiteBuilder,
|
||||
frontmatter::FrontMatterRequired,
|
||||
link_list::Link,
|
||||
util::{self, format_timestamp},
|
||||
PageMetadata,
|
||||
};
|
||||
|
||||
/// Metadata for resources.
|
||||
|
@ -30,7 +33,7 @@ pub struct ResourceMetadata {
|
|||
pub desc: Option<String>,
|
||||
/// Extra resource data not included.
|
||||
#[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.
|
||||
#[serde(default)]
|
||||
pub draft: bool,
|
||||
|
|
|
@ -95,7 +95,7 @@ fn create(
|
|||
builder.build_all_resources()?;
|
||||
}
|
||||
} 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.reload()?;
|
||||
builder.build_all()?;
|
||||
|
|
Loading…
Add table
Reference in a new issue