add filename to template title
This commit is contained in:
parent
b89934d3ac
commit
07daad708b
3 changed files with 15 additions and 12 deletions
|
@ -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 {
|
if state == S::P {
|
||||||
html += "</p>\n";
|
html += "</p>\n";
|
||||||
}
|
}
|
||||||
state = S::Code;
|
state = S::Code;
|
||||||
html += "<pre>\n";
|
html += "<pre>\n";
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -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)
|
||||||
|
|
|
@ -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>
|
Loading…
Reference in a new issue