From 3c6c04a1f303cc4792a88e6ead8f82069064ae24 Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Fri, 14 Jul 2023 17:18:42 -0700 Subject: [PATCH] remove PageValues Struct Signed-off-by: karthik2804 --- src/content.rs | 5 ++--- src/template.rs | 36 ++++++++---------------------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/content.rs b/src/content.rs index 77308b4..6960044 100644 --- a/src/content.rs +++ b/src/content.rs @@ -10,7 +10,6 @@ use chrono::{DateTime, Utc}; use pulldown_cmark as markdown; use crate::rhai_engine::custom_rhai_engine_init; -use crate::template::PageValues; use handlebars::Handlebars; @@ -86,7 +85,7 @@ pub fn all_pages( dir: PathBuf, show_unpublished: bool, skip_cache: bool, -) -> anyhow::Result> { +) -> anyhow::Result> { if skip_cache { let index_cache: IndexCache = all_pages_load(dir, show_unpublished)?; return Ok(index_cache.contents); @@ -163,7 +162,7 @@ pub fn all_pages( } pub struct IndexCache { - contents: BTreeMap, + contents: BTreeMap, cache_expiration: Option>, } diff --git a/src/template.rs b/src/template.rs index 20ba58c..80d8698 100644 --- a/src/template.rs +++ b/src/template.rs @@ -47,7 +47,7 @@ pub struct SiteInfo { #[derive(Serialize)] pub struct TemplateContext { request: BTreeMap, - page: PageValues, + page: Content, site: SiteValues, /// A copy of the environment variables /// @@ -69,26 +69,7 @@ pub struct TemplateContext { #[derive(Serialize)] pub struct SiteValues { info: SiteInfo, - pages: BTreeMap, -} - -/// The structured values sent to the template renderer. -/// The body should be legal HTML that can be inserted within the tag. -#[derive(Serialize, Deserialize)] -pub struct PageValues { - pub head: Head, - pub body: String, - pub published: bool, -} - -impl From for PageValues { - fn from(c: Content) -> Self { - PageValues { - body: c.body, - head: c.head, - published: c.published, - } - } + pages: BTreeMap, } /// Renderer can execute a handlebars template and render the results into HTML. @@ -190,14 +171,13 @@ impl<'a> Renderer<'a> { } /// Given values and a site object, render a template. - pub fn render_template>( + pub fn render_template( &self, - values: T, + content: Content, info: SiteInfo, request: HeaderMap, ) -> anyhow::Result { - let page: PageValues = values.into(); - let tpl = page + let tpl = content .head .template .clone() @@ -210,7 +190,7 @@ impl<'a> Renderer<'a> { } let ctx = TemplateContext { - page, + page: content, request: request_headers, site: SiteValues { // Right now, we literally include ALL OF THE CONTENT in its rendered @@ -279,8 +259,8 @@ fn pages_helper( /// /// It should be assumed that all data passed into this function will be visible to the /// end user. -pub fn error_values(title: &str, msg: &str) -> PageValues { - PageValues { +pub fn error_values(title: &str, msg: &str) -> Content { + Content { head: Head { title: title.to_string(), date: Some(chrono::Utc::now()),