diff --git a/src/render.rs b/src/render.rs
index 859c7bd..cb3a917 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -67,7 +67,11 @@ struct PageContext {
// The pathname part of the URL
pathname: String,
// The current query string
- query: String
+ query: String,
+ // Summary of the current page
+ // regardless of its type
+ // For use in tags
+ description: String
}
#[derive(Serialize)]
@@ -148,11 +152,12 @@ fn build_handlebars() -> Handlebars<'static> {
return hbs;
}
-fn build_page_context(url: &Url) -> PageContext {
+fn build_page_context(url: &Url, description: String) -> PageContext {
PageContext {
base_url: url.origin(),
pathname: url.pathname(),
- query: url.search()
+ query: url.search(),
+ description
}
}
@@ -168,7 +173,7 @@ async fn _render_homepage(url: Url, tpl_name: &str) -> MyResult {
.map_err(|_| Error::BadRequest("Failed to parse query string".into()))?;
let mut context = HomePageContext {
blog: &ROOT_CONTEXT,
- page: build_page_context(&url),
+ page: build_page_context(&url, ROOT_CONTEXT.description.into()),
posts: vec![],
prev: None,
next: None
@@ -225,7 +230,7 @@ pub async fn render_post(url: Url, post: blog::Post) -> MyResult {
let post_cache = blog::PostContentCache::find_or_render(&post).await;
let context = PostContext {
blog: &ROOT_CONTEXT,
- page: build_page_context(&url),
+ page: build_page_context(&url, strip_html_tags(&post_cache.summary)),
title: post.title,
url: post.url,
timestamp: post.timestamp,
diff --git a/src/utils.rs b/src/utils.rs
index 5b63db5..5552e3b 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -171,4 +171,10 @@ fn default_maxage() -> u64 {
60 * 60 * 24 * 7 // default to a week
}
-include!(concat!(env!("OUT_DIR"), "/build_timestamp.rs"));
\ No newline at end of file
+include!(concat!(env!("OUT_DIR"), "/build_timestamp.rs"));
+
+// Strip HTML tags from a string via JS binding
+pub fn strip_html_tags(s: &str) -> String {
+ let js_str: JsString = s.into();
+ js_str.replace_by_pattern(&RegExp::new("(<([^>]+)>)", "ig"), "").into()
+}
\ No newline at end of file
diff --git a/theme/default/head.hbs b/theme/default/head.hbs
index e2d5d0b..d45877c 100644
--- a/theme/default/head.hbs
+++ b/theme/default/head.hbs
@@ -1,6 +1,7 @@
+
{{ #if title }}{{ title }} - {{ blog.title }}{{ else }}{{ blog.title }}{{ /if }}