diff --git a/Cargo.lock b/Cargo.lock index bf772d8..f389f7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -630,6 +630,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "equivalent" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" + [[package]] name = "flate2" version = "1.0.26" @@ -751,7 +757,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 1.9.3", "slab", "tokio", "tokio-util", @@ -764,6 +770,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" + [[package]] name = "hermit-abi" version = "0.2.6" @@ -883,7 +895,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown 0.14.0", ] [[package]] @@ -1035,7 +1057,7 @@ dependencies = [ "serde-value", "serde_derive", "serde_json", - "serde_yaml", + "serde_yaml 0.8.26", "thread-id", "winapi", ] @@ -1221,7 +1243,7 @@ dependencies = [ "pulldown-cmark", "rss", "serde", - "serde_json", + "serde_yaml 0.9.22", "simple-log", "syntect", "tera", @@ -1343,7 +1365,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bd9647b268a3d3e14ff09c23201133a62589c658db02bb7388c7246aafe0590" dependencies = [ "base64", - "indexmap", + "indexmap 1.9.3", "line-wrap", "quick-xml", "serde", @@ -1592,12 +1614,25 @@ version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" dependencies = [ - "indexmap", + "indexmap 1.9.3", "ryu", "serde", "yaml-rust", ] +[[package]] +name = "serde_yaml" +version = "0.9.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "452e67b9c20c37fa79df53201dc03839651086ed9bbe92b3ca585ca9fdaa7d85" +dependencies = [ + "indexmap 2.0.0", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sha1" version = "0.10.5" @@ -2009,6 +2044,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "unsafe-libyaml" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1865806a559042e51ab5414598446a5871b561d21b6764f2eabb0dd481d880a6" + [[package]] name = "url" version = "2.4.0" diff --git a/Cargo.toml b/Cargo.toml index d3dd267..3726bd0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ log = "0.4.19" pulldown-cmark = "0.9.3" rss = "2.0.4" serde = { version = "1.0.164", features = ["derive"]} -serde_json = "1.0.97" +serde_yaml = "0.9.22" simple-log = "1.6.0" syntect = "5.0.0" tera = "1.19.0" diff --git a/example-site/pages.json b/example-site/pages.json deleted file mode 100644 index 224d8ac..0000000 --- a/example-site/pages.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "pages": [ - { - "file_path": "about.md", - "title": "About This Site", - "url": "/about/" - }, - { - "file_path": "joke.md", - "title": "Joke", - "url": "/joke/", - "alternate_urls": ["/trying-to-be-funny/"] - } - ] -} \ No newline at end of file diff --git a/example-site/pages.yml b/example-site/pages.yml new file mode 100644 index 0000000..ef44aeb --- /dev/null +++ b/example-site/pages.yml @@ -0,0 +1,11 @@ +pages: + + - file_path: about.md + title: About This Site + url: /about/ + + - file_path: joke.md + title: Joke + url: /joke/ + alternate_urls: + - /trying-to-be-funny/ diff --git a/example-site/posts.json b/example-site/posts.json deleted file mode 100644 index 7e323e6..0000000 --- a/example-site/posts.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "posts": [ - { - "file_path": "2023-01-01-hello-world.md", - "title": "Hello, world!", - "date": "2023-01-01 12:30:42", - "slug": "hello-world", - "tags": ["aaa", "hello", "testing"] - }, - { - "file_path": "2023-02-01-commonmark-testing.md", - "title": "CommonMark Testing", - "date": "2023-02-01", - "slug": "commonmark-testing", - "tags": ["testing"], - "alternate_urls": ["/testing/commonmark/"] - }, - { - "file_path": "2023-03-20-lorem-ipsum.md", - "title": "Lorem Ipsum", - "date": "2023-03-20 18:01", - "slug": "lorem-ipsum" - }, - { - "file_path": "2023-04-15-static-site-generators-are-boring.md", - "title": "Static Site Generators Are Boring", - "date": "2023-04-15", - "slug": "static-site-generators-are-boring", - "tags": ["aaa", "rant"] - }, - { - "file_path": "2023-06-27-donuts-are-pretty-great.md", - "title": "Donuts Are Pretty Great", - "date": "2023-06-27", - "slug": "donuts-are-pretty-great", - "tags": ["aaa", "donuts", "coffee"] - } - ], - "rss": { - "title": "My Site", - "description": "This is my site. There are others like it, but this one is mine.", - "url": "http://localhost:8080/", - "count": 10 - } -} \ No newline at end of file diff --git a/example-site/posts.yml b/example-site/posts.yml new file mode 100644 index 0000000..c535f40 --- /dev/null +++ b/example-site/posts.yml @@ -0,0 +1,47 @@ +posts: + + - file_path: 2023-01-01-hello-world.md + title: Hello, world! + date: 2023-01-01 12:30:42 + slug: hello-world + tags: + - aaa + - hello + - testing + + - file_path: 2023-02-01-commonmark-testing.md + title: CommonMark Testing + date: 2023-02-01 + slug: commonmark-testing + tags: + - testing + alternate_urls: + - /testing/commonmark/ + + - file_path: 2023-03-20-lorem-ipsum.md + title: Lorem Ipsum + date: 2023-03-20 18:01 + slug: lorem-ipsum + + - file_path: 2023-04-15-static-site-generators-are-boring.md + title: Static Site Generators Are Boring + date: 2023-04-15 + slug: static-site-generators-are-boring + tags: + - aaa + - rant + + - file_path: 2023-06-27-donuts-are-pretty-great.md + title: Donuts Are Pretty Great + date: 2023-06-27 + slug: donuts-are-pretty-great + tags: + - aaa + - donuts + - coffee + +rss: + title: My Site + description: This is my site. There are others like it, but this one is mine. + url: http://localhost:8080/ + count: 10 diff --git a/example-site/server.json b/example-site/server.json deleted file mode 100644 index e2599ab..0000000 --- a/example-site/server.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "bind_addr": "127.0.0.1", - "bind_port": 8080, - "static_files_path": "static", - "templates_path": "templates", - "pages_path": "pages", - "posts_path": "posts" -} \ No newline at end of file diff --git a/example-site/server.yml b/example-site/server.yml new file mode 100644 index 0000000..51d02b7 --- /dev/null +++ b/example-site/server.yml @@ -0,0 +1,6 @@ +bind_addr: 127.0.0.1 +bind_port: 8080 +static_files_path: static +templates_path: templates +pages_path: pages +posts_path: posts diff --git a/src/config.rs b/src/config.rs index 14bc057..575ddd1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -52,28 +52,28 @@ pub struct Posts { #[derive(Debug, thiserror::Error)] pub enum ConfigError { - #[error("Json config I/O error with path {0}")] + #[error("Config I/O error with path {0}")] IOError(PathBuf, #[source] std::io::Error), - #[error("Json deserialization error: {0}")] - SerdeJsonError(String), + #[error("Deserialization error: {0}")] + SerdeError(String), } -fn load_json_config(path: &PathBuf) -> Result +fn load_config(path: &PathBuf) -> Result where T: serde::de::DeserializeOwned, { let file = File::open(path).map_err(|e| ConfigError::IOError(path.clone(), e))?; let mut reader = BufReader::new(file); - match serde_json::from_reader(&mut reader) { + match serde_yaml::from_reader(&mut reader) { Ok(deserialized) => Ok(deserialized), - Err(err) => Err(ConfigError::SerdeJsonError(err.to_string())), + Err(err) => Err(ConfigError::SerdeError(err.to_string())), } } pub fn load_server(path: &PathBuf, site_root: &PathBuf) -> Result { - log::info!("Loading server json config from {:?}", path); - let mut server_config: Server = load_json_config(path)?; + log::info!("Loading server config from {:?}", path); + let mut server_config: Server = load_config(path)?; server_config.static_files_path = [site_root, &server_config.static_files_path].iter().collect(); server_config.templates_path = [site_root, &server_config.templates_path].iter().collect(); server_config.pages_path = [site_root, &server_config.pages_path].iter().collect(); @@ -86,13 +86,13 @@ pub fn load_content( posts_path: &PathBuf, server_config: &Server, ) -> Result<(Pages, Posts), ConfigError> { - log::info!("Loading pages json config from {:?}", pages_path); - let mut pages: Pages = load_json_config(pages_path)?; + log::info!("Loading pages config from {:?}", pages_path); + let mut pages: Pages = load_config(pages_path)?; for page in pages.pages.iter_mut() { page.file_path = [&server_config.pages_path, &page.file_path].iter().collect(); } - log::info!("Loading posts json config from {:?}", posts_path); - let mut posts: Posts = load_json_config(posts_path)?; + log::info!("Loading posts config from {:?}", posts_path); + let mut posts: Posts = load_config(posts_path)?; for post in posts.posts.iter_mut() { post.file_path = [&server_config.posts_path, &post.file_path].iter().collect(); } diff --git a/src/main.rs b/src/main.rs index 695990b..7081678 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,7 @@ async fn main() -> anyhow::Result<()> { let first_arg = args.first().unwrap_or(&String::new()).to_lowercase(); if first_arg == "-h" || first_arg == "--help" { println!("Usage: pbe "); - println!("Where SITE_ROOT is a path that contains the json config files and all content and web resources."); + println!("Where SITE_ROOT is a path that contains the config files and all content and web resources."); Ok(()) } else { let site_root = if first_arg.is_empty() { @@ -81,15 +81,15 @@ async fn main() -> anyhow::Result<()> { }; log::info!("Using site root {:?}", site_root); - let server_config_path: PathBuf = [&site_root, &"server.json".into()].iter().collect(); - let pages_config_path: PathBuf = [&site_root, &"pages.json".into()].iter().collect(); - let posts_config_path: PathBuf = [&site_root, &"posts.json".into()].iter().collect(); + let server_config_path: PathBuf = [&site_root, &"server.yml".into()].iter().collect(); + let pages_config_path: PathBuf = [&site_root, &"pages.yml".into()].iter().collect(); + let posts_config_path: PathBuf = [&site_root, &"posts.yml".into()].iter().collect(); log::info!("Loading config ..."); let server_config = config::load_server(&server_config_path, &site_root) // - .context("Loading server json config")?; + .context("Loading server config")?; let (pages_config, posts_config) = config::load_content(&pages_config_path, &posts_config_path, &server_config) // - .context("Loading content json configs")?; + .context("Loading content configs")?; log::info!("Initializing site data and content ..."); let site_service = site::SiteService::new(server_config.clone(), pages_config, posts_config)