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('/');
|
url.push('/');
|
||||||
}
|
}
|
||||||
Some(Page {
|
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(),
|
full_name: name.to_owned(),
|
||||||
name: base_name,
|
name: base_name,
|
||||||
url,
|
url,
|
||||||
@@ -116,6 +121,7 @@ impl Historian {
|
|||||||
let base_name = split_path.next().unwrap().to_owned();
|
let base_name = split_path.next().unwrap().to_owned();
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
|
title: name.to_owned(),
|
||||||
full_name: name.to_owned(),
|
full_name: name.to_owned(),
|
||||||
name: base_name,
|
name: base_name,
|
||||||
url,
|
url,
|
||||||
@@ -251,6 +257,7 @@ fn commit_includes_file(repository: &Repository, commit: &Commit, path: &Path) -
|
|||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
|
pub title: String,
|
||||||
pub full_name: String,
|
pub full_name: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
@@ -287,6 +294,10 @@ fn render_markdown (content: &tera::Value, args: &HashMap<String, tera::Value>)
|
|||||||
Ok(tera::Value::String(html_output))
|
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 {
|
impl PageRenderer {
|
||||||
pub fn new() -> PageRenderer {
|
pub fn new() -> PageRenderer {
|
||||||
Self::with_template_path(DEFAULT_TEMPLATES_PATH)
|
Self::with_template_path(DEFAULT_TEMPLATES_PATH)
|
||||||
@@ -295,6 +306,7 @@ impl PageRenderer {
|
|||||||
pub fn with_template_path(template_path: &str) -> PageRenderer {
|
pub fn with_template_path(template_path: &str) -> PageRenderer {
|
||||||
let mut tera = tera::Tera::new(&format!("{template_path}/**/*.html")).unwrap();
|
let mut tera = tera::Tera::new(&format!("{template_path}/**/*.html")).unwrap();
|
||||||
tera.register_filter("markdown", render_markdown);
|
tera.register_filter("markdown", render_markdown);
|
||||||
|
tera.register_filter("file_stem", file_stem);
|
||||||
PageRenderer {
|
PageRenderer {
|
||||||
template_root: template_path.into(),
|
template_root: template_path.into(),
|
||||||
tera
|
tera
|
||||||
|
|||||||
Reference in New Issue
Block a user