Add page title overrides.

This commit is contained in:
Dorian 2019-07-10 09:23:03 -04:00
parent 4d77fc403a
commit 488df5f1ed
2 changed files with 18 additions and 2 deletions

View File

@ -152,6 +152,7 @@ pub struct Site {
pub menu: MenuItemsWrapper,
pub config: ConfigWrapper,
pub pages: HashMap<String, Value>,
#[serde(skip_deserializing)]
links: HashMap<String, Value>,
@ -168,6 +169,7 @@ impl Default for Site {
menu: Default::default(),
config: Default::default(),
links: HashMap::new(),
pages: HashMap::new(),
}
}
}
@ -222,6 +224,7 @@ impl Queryable<schema::sites::SqlType, diesel::pg::Pg> for Site {
menu: MenuItemsWrapper(menu),
config: ConfigWrapper(config),
links: HashMap::new(),
pages: HashMap::new(),
}
}
}

View File

@ -173,7 +173,20 @@ fn main() {
let content = read_to_string(source_path).unwrap();
// TODO: Be able to extract the title from the header of the markdown content.
let title = format!("Rookeries :: {}", &slug);
let title = match &project_site.pages.get(&slug) {
Some(page_entry) => {
let page_title = match page_entry.get("title") {
Some(title_) => {
let title_str = serde_json::to_string(title_).unwrap();
title_str.replacen("\"", "", 2)
},
None => format!("Rookeries :: {}", &slug),
};
page_title
},
None => format!("Rookeries :: {}", &slug).to_string(),
};
info!("{} Compiling \"{}\" page", "".green(), &slug.green());
Page {
@ -213,6 +226,7 @@ fn main() {
let plugin_list = vec!["hello-world", "rookeries-link"];
let mut ctx = tera::Context::new();
ctx.insert("site", &project_site);
// TODO: Ensure getting the right page as documented in the landingPage
ctx.insert("current_page", "index");
ctx.insert("plugins", &plugin_list);
let render_page_str = render_engine.render("index", &ctx).unwrap();
@ -256,7 +270,6 @@ fn main() {
let page_json_filename = format!("{}.json", &page.slug);
write(api_pages_path.join(&page_json_filename), page_json).expect("Failed to write the page json");
info!("{} Created the API representation of the \"{}\" page.", "".green(), &page.slug.green());
}
// Bring in the static file directory.