Trim file extensions off of page titles.
This commit is contained in:
12
src/lib.rs
12
src/lib.rs
@@ -88,6 +88,11 @@ impl Historian {
|
||||
url.push('/');
|
||||
}
|
||||
Some(Page {
|
||||
title: if metadata.is_file() {
|
||||
file_path.file_stem().unwrap().to_str().unwrap().to_owned()
|
||||
} else {
|
||||
base_name.to_owned()
|
||||
},
|
||||
full_name: name.to_owned(),
|
||||
name: base_name,
|
||||
url,
|
||||
@@ -116,6 +121,7 @@ impl Historian {
|
||||
let base_name = split_path.next().unwrap().to_owned();
|
||||
|
||||
Page {
|
||||
title: name.to_owned(),
|
||||
full_name: name.to_owned(),
|
||||
name: base_name,
|
||||
url,
|
||||
@@ -251,6 +257,7 @@ fn commit_includes_file(repository: &Repository, commit: &Commit, path: &Path) -
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Page {
|
||||
pub title: String,
|
||||
pub full_name: String,
|
||||
pub name: String,
|
||||
pub path: PathBuf,
|
||||
@@ -287,6 +294,10 @@ fn render_markdown (content: &tera::Value, args: &HashMap<String, tera::Value>)
|
||||
Ok(tera::Value::String(html_output))
|
||||
}
|
||||
|
||||
fn file_stem (content: &tera::Value, args: &HashMap<String, tera::Value>) -> tera::Result<tera::Value> {
|
||||
Ok(tera::Value::String(Path::new(content.as_str().expect("as_str")).file_stem().expect("file_stem").to_str().expect("to_str").to_owned()))
|
||||
}
|
||||
|
||||
impl PageRenderer {
|
||||
pub fn new() -> PageRenderer {
|
||||
Self::with_template_path(DEFAULT_TEMPLATES_PATH)
|
||||
@@ -295,6 +306,7 @@ impl PageRenderer {
|
||||
pub fn with_template_path(template_path: &str) -> PageRenderer {
|
||||
let mut tera = tera::Tera::new(&format!("{template_path}/**/*.html")).unwrap();
|
||||
tera.register_filter("markdown", render_markdown);
|
||||
tera.register_filter("file_stem", file_stem);
|
||||
PageRenderer {
|
||||
template_root: template_path.into(),
|
||||
tera
|
||||
|
||||
Reference in New Issue
Block a user