From 71d5ac1e373386501a92a2bd4228409b83697bfb Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 24 Jan 2026 21:36:58 -0700 Subject: [PATCH] refactor: switch to flat .html output (suckless style) - src/content.rs: output_path() now returns slug.html instead of slug/index.html for regular content. - src/templates.rs: All hrefs use explicit .html extension. Nav links point to index.html, blog.index.html, about.html. Blog post links use ./slug.html format. - src/main.rs: Adjust depth values (root=0, blog posts=1). No more directory-per-page overhead. file:// navigation works without directory listings. True suckless structure. --- src/content.rs | 8 ++++---- src/main.rs | 4 ++-- src/templates.rs | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/content.rs b/src/content.rs index 37e053f..04eb827 100644 --- a/src/content.rs +++ b/src/content.rs @@ -75,7 +75,7 @@ impl Content { } /// Compute the output path relative to the output directory. - /// e.g., content/blog/foo.md → blog/foo/index.html + /// e.g., content/blog/foo.md → blog/foo.html pub fn output_path(&self, content_root: &Path) -> PathBuf { let relative = self .source_path @@ -84,14 +84,14 @@ impl Content { match self.kind { ContentKind::Section => { - // _index.md → parent/index.html + // _index.md → parent/index.html (listing pages stay as index.html) let parent = relative.parent().unwrap_or(Path::new("")); parent.join("index.html") } _ => { - // Regular content → parent/slug/index.html + // Regular content → parent/slug.html (flat structure) let parent = relative.parent().unwrap_or(Path::new("")); - parent.join(&self.slug).join("index.html") + parent.join(format!("{}.html", self.slug)) } } } diff --git a/src/main.rs b/src/main.rs index 5812b26..e1aa34e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ fn process_blog_posts(content_dir: &Path, output_dir: &Path) -> Result Result<()> { let content = Content::from_path(&path, ContentKind::Page)?; let html_body = render::markdown_to_html(&content.body); - let page = templates::render_page(&content.frontmatter, &html_body, 1); + let page = templates::render_page(&content.frontmatter, &html_body, 0); write_output(output_dir, content_dir, &content, page.into_string())?; } diff --git a/src/templates.rs b/src/templates.rs index 7ef6af0..dc6c6d0 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -33,7 +33,7 @@ pub fn render_post(frontmatter: &Frontmatter, content_html: &str, depth: usize) @if !frontmatter.tags.is_empty() { ul.tags { @for tag in &frontmatter.tags { - li { a href=(format!("{}/tags/{}/", prefix, tag)) { (tag) } } + li { a href=(format!("{}/tags/{}.html", prefix, tag)) { (tag) } } } } } @@ -91,8 +91,8 @@ pub fn render_blog_index(title: &str, posts: &[Content], depth: usize) -> Markup ul.post-list { @for post in posts { li { - // Posts are siblings in the same directory - a href=(format!("./{}/", post.slug)) { + // Posts are .html files in the same directory + a href=(format!("./{}.html", post.slug)) { span.title { (post.frontmatter.title) } @if let Some(ref date) = post.frontmatter.date { time.date { (date) } @@ -153,10 +153,10 @@ fn base_layout(title: &str, content: Markup, depth: usize) -> Markup { } body { nav { - a href=(format!("{}/", prefix)) { "nrd.sh" } - a href=(format!("{}/blog/", prefix)) { "blog" } - a href=(format!("{}/projects/", prefix)) { "projects" } - a href=(format!("{}/about/", prefix)) { "about" } + a href=(format!("{}/index.html", prefix)) { "nrd.sh" } + a href=(format!("{}/blog/index.html", prefix)) { "blog" } + a href=(format!("{}/projects/index.html", prefix)) { "projects" } + a href=(format!("{}/about.html", prefix)) { "about" } } main { (content)