From a42639578bc6d7b132491ed893be679aaf0bf88f Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 3 Apr 2025 02:03:14 +0800 Subject: [PATCH 1/6] feat(app): support description in posts --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- src/app.rs | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41e4541..dd9cd5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1616,7 +1616,7 @@ dependencies = [ [[package]] name = "sonata" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "async-lock", diff --git a/Cargo.toml b/Cargo.toml index c3cc50f..cb352d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sonata" -version = "0.1.5" +version = "0.1.6" edition = "2021" authors = ["clearloop"] description = "The static site generator." diff --git a/README.md b/README.md index 1fed6ee..6b0818a 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ jobs: contents: write steps: - uses: actions/checkout@v4 - - uses: clearloop/sonata@0.0.7 + - uses: clearloop/sonata@0.1.6 - name: Build the site run: sonata build blog diff --git a/src/app.rs b/src/app.rs index 9bd14aa..d9e5de9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -181,6 +181,7 @@ impl App<'_> { serde_json::json!({ "post": post, "tab": post.meta.title, + "description": post.meta.description, }), ) } From 48620620b9bf3d7305b659c270781da85da8cf7c Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 3 Apr 2025 02:22:16 +0800 Subject: [PATCH 2/6] chore(action): use 0.1.6 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index bc97d57..04a82fd 100644 --- a/action.yml +++ b/action.yml @@ -8,7 +8,7 @@ inputs: version: required: true description: The version of sonata to install - default: "0.1.4" + default: "0.1.6" runs: using: composite From 661e204c631c3563923476458e406edd3a72bc71 Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 3 Apr 2025 02:48:44 +0800 Subject: [PATCH 3/6] feat(hbs): complete twitter card --- blog/posts/2023-12-29-hello-world.md | 2 +- blog/templates/head.hbs | 12 +++++++----- blog/templates/post.hbs | 2 +- src/app.rs | 21 +++++++++------------ src/manifest.rs | 20 ++++++++++++++++---- src/post.rs | 2 +- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/blog/posts/2023-12-29-hello-world.md b/blog/posts/2023-12-29-hello-world.md index 8155921..804b7c7 100644 --- a/blog/posts/2023-12-29-hello-world.md +++ b/blog/posts/2023-12-29-hello-world.md @@ -1,6 +1,6 @@ --- author: clearloop -profile_url: https://x.com/tianyi_gc +twitter: https://x.com/tianyi_gc description: The example post of sonata. labels: [sonata] title: Hello, World! diff --git a/blog/templates/head.hbs b/blog/templates/head.hbs index ad1b08c..61ef3bd 100644 --- a/blog/templates/head.hbs +++ b/blog/templates/head.hbs @@ -7,12 +7,14 @@ - - - - - + + + + + + + diff --git a/blog/templates/post.hbs b/blog/templates/post.hbs index 9406f32..eaa1ca5 100644 --- a/blog/templates/post.hbs +++ b/blog/templates/post.hbs @@ -2,7 +2,7 @@

{{ post.title }}

- {{ post.formatted_date }} · {{{ post.author }}} + {{ post.formatted_date }} · {{{ post.author }}}
{{{ post.content }}} diff --git a/src/app.rs b/src/app.rs index d9e5de9..8e9b666 100644 --- a/src/app.rs +++ b/src/app.rs @@ -62,9 +62,15 @@ impl App<'_> { pub fn data(&self, mut value: Value) -> Result { let mut map = Map::::new(); + map.insert("site".into(), self.manifest.site.clone().into()); map.insert("title".into(), self.manifest.title.clone().into()); map.insert("base".into(), self.manifest.base.clone().into()); - map.insert("ximage".into(), self.manifest.ximage.clone().into()); + map.insert("image".into(), self.manifest.image.clone().into()); + map.insert("twitter".into(), self.manifest.site.clone().into()); + map.insert( + "favicon".into(), + format!("/{}", self.manifest.favicon.file_name()?).into(), + ); map.insert( "description".into(), self.manifest.description.clone().into(), @@ -74,13 +80,6 @@ impl App<'_> { map.insert("livereload".into(), LIVERELOAD_ENDPOINT.into()); } - if self.manifest.favicon.exists() { - map.insert( - "favicon".into(), - format!("/{}", self.manifest.favicon.file_name()?).into(), - ); - } - if let Some(data) = value.as_object_mut() { map.append(data); } @@ -112,14 +111,11 @@ impl App<'_> { } else if self.manifest.public.exists() && self.manifest.public.is_sub(&path)? { tracing::trace!("copying public: {path:?} ..."); self.manifest.copy_public()?; - } else if self.manifest.favicon.exists() && self.manifest.favicon.is_sub(&path)? { - tracing::trace!("rendering favicon: {path:?} ..."); - self.render_favicon()?; } else if self.manifest.templates.exists() && self.manifest.templates.is_sub(&path)? { tracing::info!("reloading templates ..."); templates_changed = true; self.register_templates()?; - } else { + } else if self.manifest.favicon.exists() && self.manifest.favicon == path { tracing::trace!("skipping {path:?} ..."); } } @@ -182,6 +178,7 @@ impl App<'_> { "post": post, "tab": post.meta.title, "description": post.meta.description, + "twitter": post.meta.twitter, }), ) } diff --git a/src/manifest.rs b/src/manifest.rs index 04adc3f..3f549b1 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -26,6 +26,11 @@ title = "sonata" #[derive(Debug, Clone, Deserialize, Serialize)] #[cfg_attr(feature = "cli", derive(Parser))] pub struct Manifest { + /// The site name. + #[serde(default = "default::site")] + #[cfg_attr(feature = "cli", clap(long, default_value = ""))] + pub site: String, + /// The name of the site. #[cfg_attr(feature = "cli", clap(long, default_value = "sonata"))] pub title: String, @@ -65,9 +70,9 @@ pub struct Manifest { #[cfg_attr(feature = "cli", clap(short, long, default_value = "templates"))] pub templates: PathBuf, - #[serde(default = "default::ximage")] + #[serde(default = "default::image")] #[cfg_attr(feature = "cli", clap(short, long, default_value = "ximage"))] - pub ximage: String, + pub image: String, /// The path of the theme. /// @@ -208,9 +213,10 @@ impl Manifest { impl Default for Manifest { fn default() -> Self { Self { + site: "sonata".to_string(), title: "sonata".to_string(), base: "".to_string(), - ximage: "".to_string(), + image: "".to_string(), description: "".to_string(), favicon: default::favicon(), out: default::out(), @@ -233,12 +239,18 @@ mod default { /// The default theme. pub const DEFAULT_THEME: &str = include_str!("../blog/theme/theme.css"); + /// Default implementation of the site name. + pub fn site() -> String { + "".to_string() + } + /// Default implementation of the base URL. pub fn base() -> String { "/".to_string() } - pub fn ximage() -> String { + /// Default implementation of the image. + pub fn image() -> String { "".to_string() } diff --git a/src/post.rs b/src/post.rs index 5ba41f1..18e6013 100644 --- a/src/post.rs +++ b/src/post.rs @@ -121,7 +121,7 @@ pub struct Meta { pub author: String, /// The profile url of the author. #[serde(default)] - pub profile_url: String, + pub twitter: String, /// The date of the post. #[serde(default)] pub date: NaiveDate, From b3cf70c2238dbfd787a4dbbd8acdfbddcc85e44d Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 3 Apr 2025 02:53:44 +0800 Subject: [PATCH 4/6] chore(twitter): use x handle instead of url --- blog/templates/post.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blog/templates/post.hbs b/blog/templates/post.hbs index eaa1ca5..9103bbd 100644 --- a/blog/templates/post.hbs +++ b/blog/templates/post.hbs @@ -2,7 +2,7 @@

{{ post.title }}

- {{ post.formatted_date }} · {{{ post.author }}} + {{ post.formatted_date }} · {{{ post.author }}}
{{{ post.content }}} From 40643e7decbf0090814558873dcd7b5d283cfccc Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 3 Apr 2025 02:54:49 +0800 Subject: [PATCH 5/6] chore(version): bumps version to 0.1.7 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd9cd5e..4c1fd91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1616,7 +1616,7 @@ dependencies = [ [[package]] name = "sonata" -version = "0.1.6" +version = "0.1.7" dependencies = [ "anyhow", "async-lock", diff --git a/Cargo.toml b/Cargo.toml index cb352d0..e34f49e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sonata" -version = "0.1.6" +version = "0.1.7" edition = "2021" authors = ["clearloop"] description = "The static site generator." From eeaa448193a2b11e2f6ce94b5e076202131c4dd5 Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 3 Apr 2025 03:01:53 +0800 Subject: [PATCH 6/6] chore(action): use 0.1.7 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 04a82fd..a8d5860 100644 --- a/action.yml +++ b/action.yml @@ -8,7 +8,7 @@ inputs: version: required: true description: The version of sonata to install - default: "0.1.6" + default: "0.1.7" runs: using: composite