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.
This commit is contained in:
Timothy DeHerrera
2026-01-24 21:36:58 -07:00
parent b9be21156d
commit 71d5ac1e37
3 changed files with 13 additions and 13 deletions

View File

@@ -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))
}
}
}

View File

@@ -78,7 +78,7 @@ fn process_blog_posts(content_dir: &Path, output_dir: &Path) -> Result<Vec<Conte
let content = Content::from_path(path, ContentKind::Post)?;
let html_body = render::markdown_to_html(&content.body);
let page = templates::render_post(&content.frontmatter, &html_body, 2);
let page = templates::render_post(&content.frontmatter, &html_body, 1);
write_output(output_dir, content_dir, &content, page.into_string())?;
posts.push(content);
@@ -117,7 +117,7 @@ fn process_pages(content_dir: &Path, output_dir: &Path) -> 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())?;
}

View File

@@ -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)