Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sonata"
version = "0.1.5"
version = "0.1.7"
edition = "2021"
authors = ["clearloop"]
description = "The static site generator."
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
version:
required: true
description: The version of sonata to install
default: "0.1.4"
default: "0.1.7"

runs:
using: composite
Expand Down
2 changes: 1 addition & 1 deletion blog/posts/2023-12-29-hello-world.md
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
12 changes: 7 additions & 5 deletions blog/templates/head.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

<!-- twitter -->
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="{{tab}}">
<meta name="twitter:image" content="{{ximage}}">
<meta name="twitter:description" content="{{ description }}">
<!-- <meta name="twitter:site" content="@sonata"> -->
<!-- <meta name="twitter:creator" content="@sonata"> -->
<meta name="twitter:site" content="@{{ site }}">
<meta name="twitter:creator" content="@{{ twitter }}">

<!-- og -->
<meta property="og:title" content="{{tab}}">
<meta property="og:description" content="{{ description }}">
<meta property="og:image" content="{{ image }}">

<!-- theme -->
<link rel="stylesheet" href="{{ base }}theme.css">

Expand Down
2 changes: 1 addition & 1 deletion blog/templates/post.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<article class="prose dark:prose-invert pt-6 max-w-5xl mx-auto">
<h1 class="underline">{{ post.title }}</h1>
<div class="text text-zinc-500 font-bold">
{{ post.formatted_date }} · <a href="{{{ post.profile_url }}}" target="_blank">{{{ post.author }}}</a>
{{ post.formatted_date }} · <a href="https://x.com/{{{ post.twitter }}}" target="_blank">{{{ post.author }}}</a>
</div>
<div class="mt-6">
{{{ post.content }}}
Expand Down
22 changes: 10 additions & 12 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ impl App<'_> {
pub fn data(&self, mut value: Value) -> Result<Value> {
let mut map = Map::<String, Value>::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(),
Expand All @@ -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);
}
Expand Down Expand Up @@ -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:?} ...");
}
}
Expand Down Expand Up @@ -181,6 +177,8 @@ impl App<'_> {
serde_json::json!({
"post": post,
"tab": post.meta.title,
"description": post.meta.description,
"twitter": post.meta.twitter,
}),
)
}
Expand Down
20 changes: 16 additions & 4 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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(),
Expand All @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down