add filename to template title

This commit is contained in:
Crispy 2024-04-26 23:14:06 +02:00
parent b89934d3ac
commit 07daad708b
3 changed files with 15 additions and 12 deletions

View file

@ -14,13 +14,13 @@ pub fn convert_document(markdown: &str) -> String {
if state == S::Code {
html += "</pre>\n";
state = S::None;
continue;
}
} else {
if state == S::P {
html += "</p>\n";
}
state = S::Code;
html += "<pre>\n";
}
continue;
}

View file

@ -11,7 +11,8 @@ use convert::convert_document;
const SRC_DIR: &str = "write";
const OUT_DIR: &str = "site";
const CONTENT_MARKER: &str = "CONTENT HERE";
const CONTENT_MARKER: &str = "{CONTENT}";
const FILENAME_MARKER: &str = "{FILENAME}";
const TEMPLATE_FILE: &str = "template.html";
const DEFAULT_TEMPLATE: &[u8] = include_bytes!("../template.html");
@ -61,10 +62,12 @@ fn convert_file(path: &Path) -> Result {
let out_path = out_path.with_extension("html");
let markdown = read_to_string(path)?;
let html = convert_document(&markdown);
let content = convert_document(&markdown);
let template = read_to_string(TEMPLATE_FILE)?;
let html = template.replacen(CONTENT_MARKER, &html, 1);
let filename = path.file_stem().unwrap().to_string_lossy().to_string();
let html = template
.replacen(CONTENT_MARKER, &content, 1)
.replace(FILENAME_MARKER, &filename);
DirBuilder::new()
.recursive(true)

View file

@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TITLE HERE</title>
<title>Title - {FILENAME}</title>
</head>
<body>
CONTENT HERE
{CONTENT}
</body>
</html>