From 1bf265f14b01296a6f803b261bb084de7dea58d9 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 31 Jan 2026 13:59:05 -0700 Subject: [PATCH] fix(feed): derive URLs from content paths Replace hardcoded "/blog/{slug}.html" URL pattern with dynamic path derivation using Content.output_path(). This ensures feed URLs work correctly for any content location, not just blog posts. --- src/feed.rs | 7 +++++-- src/main.rs | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/feed.rs b/src/feed.rs index b1afdc7..5e7b017 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -2,9 +2,10 @@ use crate::config::SiteConfig; use crate::content::Content; +use std::path::Path; /// Generate an Atom 1.0 feed from blog posts. -pub fn generate_atom_feed(posts: &[Content], config: &SiteConfig) -> String { +pub fn generate_atom_feed(posts: &[Content], config: &SiteConfig, content_root: &Path) -> String { let base_url = config.base_url.trim_end_matches('/'); // Use the most recent post date as feed updated time, or fallback @@ -16,7 +17,9 @@ pub fn generate_atom_feed(posts: &[Content], config: &SiteConfig) -> String { let mut entries = String::new(); for post in posts { - let post_url = format!("{}/blog/{}.html", base_url, post.slug); + // Derive URL from output path (e.g., blog/foo.html → /blog/foo.html) + let relative_path = post.output_path(content_root); + let post_url = format!("{}/{}", base_url, relative_path.display()); let post_date = post .frontmatter .date diff --git a/src/main.rs b/src/main.rs index 9444837..1400e3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,7 @@ fn run() -> Result<()> { generate_blog_index(output_dir, &posts, &config, &nav)?; // 2b. Generate Atom feed - generate_feed(output_dir, &posts, &config)?; + generate_feed(output_dir, &posts, &config, content_dir)?; // 3. Process standalone pages (discovered dynamically) process_pages(content_dir, output_dir, &config, &nav)?; @@ -135,11 +135,16 @@ fn generate_blog_index( } /// Generate the Atom feed -fn generate_feed(output_dir: &Path, posts: &[Content], config: &config::SiteConfig) -> Result<()> { +fn generate_feed( + output_dir: &Path, + posts: &[Content], + config: &config::SiteConfig, + content_dir: &Path, +) -> Result<()> { let out_path = output_dir.join("feed.xml"); eprintln!("generating: {}", out_path.display()); - let feed_xml = feed::generate_atom_feed(posts, config); + let feed_xml = feed::generate_atom_feed(posts, config, content_dir); fs::write(&out_path, feed_xml).map_err(|e| Error::WriteFile { path: out_path.clone(),