implement manual summary marker

This commit is contained in:
Peter Cai 2020-04-11 19:15:34 +08:00
parent 48dd6cbabc
commit f714591b25
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
2 changed files with 18 additions and 2 deletions

View File

@ -120,11 +120,18 @@ impl Post {
// library updates. Updaing this value invalidates all // library updates. Updaing this value invalidates all
// existing cache and they will be recompiled when someone // existing cache and they will be recompiled when someone
// visits. // visits.
const CACHE_VERSION: &'static str = "0007"; const CACHE_VERSION: &'static str = "0008";
// The prefix path used for caching remote images // The prefix path used for caching remote images
pub const IMG_CACHE_PREFIX: &'static str = "/imgcache/"; pub const IMG_CACHE_PREFIX: &'static str = "/imgcache/";
// The divider for summary
// Insert this into the article as a standalone line to
// make everything above it the summary. DO NOT insert
// it within paragraph or anything else otherwise
// the layout may break.
const SUMMARY_DIVIDER: &'static str = "<!-- More -->";
// Cached version of rendered blog content HTMLs // Cached version of rendered blog content HTMLs
// compiled from Markdown // compiled from Markdown
// This is needed because // This is needed because
@ -145,6 +152,11 @@ pub struct PostContentCache {
version: String, version: String,
// Digest of the original content // Digest of the original content
orig_digest: String, orig_digest: String,
// Summary can be defined by inserting SUMMARY_DIVIDER
// into the article. Everything before this tag will be
// the summary. Becuase it's an HTML comment, it won't
// show up in the rendered result.
pub summary: String,
// Compiled content in HTML // Compiled content in HTML
pub content: String pub content: String
} }
@ -283,6 +295,10 @@ impl PostContentCache {
uuid: post.uuid.clone(), uuid: post.uuid.clone(),
version: CACHE_VERSION.to_owned(), version: CACHE_VERSION.to_owned(),
orig_digest: crate::utils::sha1(&post.content).await, orig_digest: crate::utils::sha1(&post.content).await,
summary: match html_output.find(SUMMARY_DIVIDER) {
None => html_output.clone(),
Some(x) => (&html_output[0..x]).to_owned()
},
content: html_output content: html_output
} }
} }

View File

@ -160,7 +160,7 @@ pub async fn render_homepage(url: Url) -> MyResult<String> {
title: post.title, title: post.title,
url: post.url, url: post.url,
timestamp: post.timestamp, timestamp: post.timestamp,
summary: post_cache.content // TODO: make actual summaries summary: post_cache.summary
}); });
} }
hbs.render("home.hbs", &context) hbs.render("home.hbs", &context)