From 07daad708b79d48084a7441796604303ac2f9092 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 26 Apr 2024 23:14:06 +0200 Subject: [PATCH] add filename to template title --- src/convert.rs | 12 ++++++------ src/main.rs | 11 +++++++---- template.html | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/convert.rs b/src/convert.rs index 0a211e6..2e81fd2 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -14,13 +14,13 @@ pub fn convert_document(markdown: &str) -> String { if state == S::Code { html += "\n"; state = S::None; - continue; + } else { + if state == S::P { + html += "

\n"; + } + state = S::Code; + html += "
\n";
 			}
-			if state == S::P {
-				html += "

\n"; - } - state = S::Code; - html += "
\n";
 			continue;
 		}
 
diff --git a/src/main.rs b/src/main.rs
index 13add86..2027512 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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)
diff --git a/template.html b/template.html
index 67f63de..7d852ce 100644
--- a/template.html
+++ b/template.html
@@ -4,11 +4,11 @@
 
 	
 	
-	TITLE HERE
+	Title - {FILENAME}
 
 
 
-	CONTENT HERE
+	{CONTENT}
 
 
 
\ No newline at end of file