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 { if state == S::Code {
html += "</pre>\n"; html += "</pre>\n";
state = S::None; state = S::None;
continue; } else {
if state == S::P {
html += "</p>\n";
}
state = S::Code;
html += "<pre>\n";
} }
if state == S::P {
html += "</p>\n";
}
state = S::Code;
html += "<pre>\n";
continue; continue;
} }

View file

@ -11,7 +11,8 @@ use convert::convert_document;
const SRC_DIR: &str = "write"; const SRC_DIR: &str = "write";
const OUT_DIR: &str = "site"; 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 TEMPLATE_FILE: &str = "template.html";
const DEFAULT_TEMPLATE: &[u8] = include_bytes!("../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 out_path = out_path.with_extension("html");
let markdown = read_to_string(path)?; let markdown = read_to_string(path)?;
let html = convert_document(&markdown); let content = convert_document(&markdown);
let template = read_to_string(TEMPLATE_FILE)?; 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() DirBuilder::new()
.recursive(true) .recursive(true)

View file

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