feat: add Atom feed generation
- src/feed.rs: New module with generate_atom_feed() that produces Atom 1.0 XML from blog posts. Uses config.base_url for absolute entry URLs. Includes xml_escape() helper. - src/main.rs: Wire mod feed and call generate_feed() after blog index generation. Outputs to public/feed.xml. - src/templates.rs: Add <link rel="alternate" type="application/atom+xml"> autodiscovery link to page head using config.base_url. Feed includes title, author, updated timestamp, and entries with title, link, id, updated, and summary for each blog post.
This commit is contained in:
20
src/main.rs
20
src/main.rs
@@ -6,6 +6,7 @@ mod config;
|
||||
mod content;
|
||||
mod css;
|
||||
mod error;
|
||||
mod feed;
|
||||
mod highlight;
|
||||
mod render;
|
||||
mod templates;
|
||||
@@ -45,6 +46,9 @@ fn run() -> Result<()> {
|
||||
posts.sort_by(|a, b| b.frontmatter.date.cmp(&a.frontmatter.date));
|
||||
generate_blog_index(output_dir, &posts, &config)?;
|
||||
|
||||
// 2b. Generate Atom feed
|
||||
generate_feed(output_dir, &posts, &config)?;
|
||||
|
||||
// 3. Process standalone pages (about, collab)
|
||||
process_pages(content_dir, output_dir, &config)?;
|
||||
|
||||
@@ -122,6 +126,22 @@ fn generate_blog_index(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Generate the Atom feed
|
||||
fn generate_feed(output_dir: &Path, posts: &[Content], config: &config::SiteConfig) -> Result<()> {
|
||||
let out_path = output_dir.join("feed.xml");
|
||||
eprintln!("generating: {}", out_path.display());
|
||||
|
||||
let feed_xml = feed::generate_atom_feed(posts, config);
|
||||
|
||||
fs::write(&out_path, feed_xml).map_err(|e| Error::WriteFile {
|
||||
path: out_path.clone(),
|
||||
source: e,
|
||||
})?;
|
||||
|
||||
eprintln!(" → {}", out_path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Process standalone pages in content/ (about.md, collab.md)
|
||||
fn process_pages(content_dir: &Path, output_dir: &Path, config: &config::SiteConfig) -> Result<()> {
|
||||
for name in ["about.md", "collab.md"] {
|
||||
|
||||
Reference in New Issue
Block a user