index : paprika

A blogging platform written in Rust for Cloudflare Workers, integrated with Standard Notes

diff options
context:
space:
mode:
authorPeter Cai <[email protected]>2020-04-14 21:11:21 +0800
committerPeter Cai <[email protected]>2020-04-14 21:11:21 +0800
commitd6b479ec15616ae48dfcdceaa254c2bfa86e92bf (patch)
treeb92f49b494c89f37a2c9587914f257e4807aa464
parent1183250d3bf8293f91f5c27f117b9676e0920423 (diff)
downloadpaprika-d6b479ec15616ae48dfcdceaa254c2bfa86e92bf.tar.gz
support per-post theme_config in custom metadata
-rw-r--r--src/blog.rs4
-rw-r--r--src/render.rs6
-rw-r--r--src/sn.rs7
3 files changed, 13 insertions, 4 deletions
diff --git a/src/blog.rs b/src/blog.rs
index 6f32ed9..d9bf530 100644
--- a/src/blog.rs
+++ b/src/blog.rs
@@ -71,7 +71,9 @@ pub struct Post {
// We keep the original content here
// so that we could make changes to the Markdown parser
// in the future; we won't be stuck with a parsed version
- pub content: String
+ pub content: String,
+ // Some arbitrary data that could be used by the theme
+ pub theme_config: Option<serde_json::Value>
}
impl Post {
diff --git a/src/render.rs b/src/render.rs
index 2386d40..859c7bd 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -94,7 +94,8 @@ struct PostContext {
title: String,
url: String,
timestamp: u64,
- content: String
+ content: String,
+ theme_config: Option<serde_json::Value>
}
lazy_static! {
@@ -228,7 +229,8 @@ pub async fn render_post(url: Url, post: blog::Post) -> MyResult<String> {
title: post.title,
url: post.url,
timestamp: post.timestamp,
- content: post_cache.content
+ content: post_cache.content,
+ theme_config: post.theme_config
};
HANDLEBARS.render("post.hbs", &context)
diff --git a/src/sn.rs b/src/sn.rs
index df88045..a76c7b4 100644
--- a/src/sn.rs
+++ b/src/sn.rs
@@ -96,6 +96,8 @@ struct CustomMetadata {
// `unlist` takes precedence over this alias
unlisted: Option<bool>,
url: Option<String>,
+ // Same as Post.theme_config
+ theme_config: Option<serde_json::Value>,
timestamp: Option<String> // Should be something `js_sys::Date::parse` could handle
}
@@ -187,11 +189,13 @@ async fn create_or_update_post(req: Request, url: Url) -> MyResult<Response> {
let text = data.items[0].content.text.clone();
let title = data.items[0].content.title.clone();
let (custom_metadata, text) = parse_custom_metadata_from_content(text);
+ let theme_config = custom_metadata.as_ref().and_then(|it| it.theme_config.clone());
let metadata = build_metadata(custom_metadata, &uuid, &title);
let post = match blog::Post::find_by_uuid(&uuid).await {
Ok(mut post) => {
post.content = text;
post.title = title;
+ post.theme_config = theme_config;
// Update metadata if custom ones are present
if metadata.has_custom_url {
@@ -210,7 +214,8 @@ async fn create_or_update_post(req: Request, url: Url) -> MyResult<Response> {
uuid: uuid,
title: title,
content: text,
- timestamp: metadata.timestamp
+ timestamp: metadata.timestamp,
+ theme_config: theme_config
}
}
};