Skip to content

Commit 449fa08

Browse files
committed
remove PageValues Struct
Signed-off-by: karthik2804 <[email protected]>
1 parent 52c3341 commit 449fa08

File tree

2 files changed

+11
-32
lines changed

2 files changed

+11
-32
lines changed

src/content.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use chrono::{DateTime, Utc};
1010
use pulldown_cmark as markdown;
1111

1212
use crate::rhai_engine::custom_rhai_engine_init;
13-
use crate::template::PageValues;
1413

1514
use handlebars::Handlebars;
1615

@@ -86,7 +85,7 @@ pub fn all_pages(
8685
dir: PathBuf,
8786
show_unpublished: bool,
8887
skip_cache: bool,
89-
) -> anyhow::Result<BTreeMap<String, PageValues>> {
88+
) -> anyhow::Result<BTreeMap<String, Content>> {
9089
if skip_cache {
9190
let index_cache: IndexCache = all_pages_load(dir, show_unpublished)?;
9291
return Ok(index_cache.contents);
@@ -163,7 +162,7 @@ pub fn all_pages(
163162
}
164163

165164
pub struct IndexCache {
166-
contents: BTreeMap<String, PageValues>,
165+
contents: BTreeMap<String, Content>,
167166
cache_expiration: Option<DateTime<Utc>>,
168167
}
169168

@@ -190,7 +189,7 @@ pub fn all_pages_load(dir: PathBuf, show_unpublished: bool) -> anyhow::Result<In
190189
match raw_data.parse::<Content>() {
191190
Ok(content) => {
192191
if show_unpublished || content.published {
193-
contents.insert(f.to_string_lossy().to_string(), content.into());
192+
contents.insert(f.to_string_lossy().to_string(), content);
194193
} else {
195194
// find earliest unpublished article to save timestamp to refresh cache
196195
let article_date = content.head.date;

src/template.rs

+8-28
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct SiteInfo {
4747
#[derive(Serialize)]
4848
pub struct TemplateContext {
4949
request: BTreeMap<String, String>,
50-
page: PageValues,
50+
page: Content,
5151
site: SiteValues,
5252
/// A copy of the environment variables
5353
///
@@ -69,26 +69,7 @@ pub struct TemplateContext {
6969
#[derive(Serialize)]
7070
pub struct SiteValues {
7171
info: SiteInfo,
72-
pages: BTreeMap<String, PageValues>,
73-
}
74-
75-
/// The structured values sent to the template renderer.
76-
/// The body should be legal HTML that can be inserted within the <body> tag.
77-
#[derive(Serialize, Deserialize)]
78-
pub struct PageValues {
79-
pub head: Head,
80-
pub body: String,
81-
pub published: bool,
82-
}
83-
84-
impl From<Content> for PageValues {
85-
fn from(c: Content) -> Self {
86-
PageValues {
87-
body: c.body,
88-
head: c.head,
89-
published: c.published,
90-
}
91-
}
72+
pages: BTreeMap<String, Content>,
9273
}
9374

9475
/// Renderer can execute a handlebars template and render the results into HTML.
@@ -190,14 +171,13 @@ impl<'a> Renderer<'a> {
190171
}
191172

192173
/// Given values and a site object, render a template.
193-
pub fn render_template<T: Into<PageValues>>(
174+
pub fn render_template(
194175
&self,
195-
values: T,
176+
content: Content,
196177
info: SiteInfo,
197178
request: HeaderMap,
198179
) -> anyhow::Result<String> {
199-
let page: PageValues = values.into();
200-
let tpl = page
180+
let tpl = content
201181
.head
202182
.template
203183
.clone()
@@ -210,7 +190,7 @@ impl<'a> Renderer<'a> {
210190
}
211191

212192
let ctx = TemplateContext {
213-
page,
193+
page: content,
214194
request: request_headers,
215195
site: SiteValues {
216196
// Right now, we literally include ALL OF THE CONTENT in its rendered
@@ -279,8 +259,8 @@ fn pages_helper(
279259
///
280260
/// It should be assumed that all data passed into this function will be visible to the
281261
/// end user.
282-
pub fn error_values(title: &str, msg: &str) -> PageValues {
283-
PageValues {
262+
pub fn error_values(title: &str, msg: &str) -> Content {
263+
Content {
284264
head: Head {
285265
title: title.to_string(),
286266
date: Some(chrono::Utc::now()),

0 commit comments

Comments
 (0)