diff --git a/docs/plans/api-stabilization.md b/docs/plans/api-stabilization.md index 15eb013..2dc1e9e 100644 --- a/docs/plans/api-stabilization.md +++ b/docs/plans/api-stabilization.md @@ -104,16 +104,16 @@ Items validated by codebase investigation: - [x] Update embedded frontmatter examples in documentation pages (7 files) - [x] Add `FeedConfig` and `SitemapConfig` structs to `config.rs` with `enabled: bool` (default `true`) - [x] Wire feed/sitemap config into `SiteConfig` deserialization - - [ ] Gate feed generation in `main.rs` on `config.feed.enabled` - - [ ] Gate sitemap generation in `main.rs` on `config.sitemap.enabled` + - [x] Gate feed generation in `main.rs` on `config.feed.enabled` + - [x] Gate sitemap generation in `main.rs` on `config.sitemap.enabled` - [x] Refactor `ConfigContext`: flat `nested_nav: bool` → nested `nav: NavContext { nested, toc }` - [x] Remove duplicate `base_url` top-level template variable injection - [x] Update `docs/templates/base.html`: `config.nested_nav` → `config.nav.nested`, `base_url` → `config.base_url` - [x] Delete `docs/templates/section/features.html` and `docs/templates/homepage.html` - [x] Add template section fallback in `render_section`: try `section/.html`, fall back to `section/default.html` - [x] Update/fix all existing tests to use TOML frontmatter - - [ ] Add new tests: TOML parsing, date validation (valid + invalid), feed/sitemap config gating - - [ ] Verify all 69 existing tests pass (updated for TOML) + - [x] Add new tests: TOML parsing, date validation (valid + invalid), feed/sitemap config gating + - [x] Verify all 69 existing tests pass (updated for TOML) 2. **Phase 2: Draft & Alias Features** — implement filtering and redirect generation - [ ] Filter items where `draft == true` from `collect_items()` results diff --git a/src/config.rs b/src/config.rs index d64d8f7..37c0cab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -161,4 +161,52 @@ mod tests { assert_eq!(config.paths.static_dir, PathBuf::from("assets")); assert_eq!(config.paths.templates, PathBuf::from("theme")); } + + #[test] + fn test_feed_sitemap_defaults() { + let toml = r#" + title = "Test" + author = "Author" + base_url = "https://example.com" + "#; + + let config: SiteConfig = toml::from_str(toml).unwrap(); + assert!(config.feed.enabled, "feed should be enabled by default"); + assert!( + config.sitemap.enabled, + "sitemap should be enabled by default" + ); + } + + #[test] + fn test_feed_disabled() { + let toml = r#" + title = "Test" + author = "Author" + base_url = "https://example.com" + + [feed] + enabled = false + "#; + + let config: SiteConfig = toml::from_str(toml).unwrap(); + assert!(!config.feed.enabled); + assert!(config.sitemap.enabled, "sitemap unaffected"); + } + + #[test] + fn test_sitemap_disabled() { + let toml = r#" + title = "Test" + author = "Author" + base_url = "https://example.com" + + [sitemap] + enabled = false + "#; + + let config: SiteConfig = toml::from_str(toml).unwrap(); + assert!(config.feed.enabled, "feed unaffected"); + assert!(!config.sitemap.enabled); + } } diff --git a/src/main.rs b/src/main.rs index 302c3b7..9398d71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -183,8 +183,8 @@ fn run(config_path: &Path) -> Result<()> { eprintln!(" → {}", out_path.display()); } - // 2. Generate Atom feed (blog posts only) - if !manifest.posts.is_empty() { + // 2. Generate Atom feed (blog posts only, if enabled) + if config.feed.enabled && !manifest.posts.is_empty() { generate_feed(&output_dir, &manifest, &config, &content_dir)?; } @@ -194,8 +194,10 @@ fn run(config_path: &Path) -> Result<()> { // 4. Generate homepage generate_homepage(&manifest, &output_dir, &config, &engine)?; - // 5. Generate sitemap - generate_sitemap_file(&output_dir, &manifest, &config, &content_dir)?; + // 5. Generate sitemap (if enabled) + if config.sitemap.enabled { + generate_sitemap_file(&output_dir, &manifest, &config, &content_dir)?; + } eprintln!("done!"); Ok(()) diff --git a/src/template_engine.rs b/src/template_engine.rs index dd75ebc..0970d8d 100644 --- a/src/template_engine.rs +++ b/src/template_engine.rs @@ -263,6 +263,32 @@ mod tests { assert_eq!(relative_prefix("/blog/posts/foo.html"), "../.."); } + #[test] + fn test_config_context_nav_structure() { + let config = SiteConfig { + title: "Test".to_string(), + author: "Author".to_string(), + base_url: "https://example.com/".to_string(), + paths: crate::config::PathsConfig::default(), + nav: crate::config::NavConfig { + nested: true, + toc: true, + }, + feed: crate::config::FeedConfig::default(), + sitemap: crate::config::SitemapConfig::default(), + }; + + let ctx = ConfigContext::from(&config); + assert!(ctx.nav.nested); + assert!(ctx.nav.toc); + assert_eq!( + ctx.base_url, "https://example.com", + "trailing slash trimmed" + ); + assert_eq!(ctx.title, "Test"); + assert_eq!(ctx.author, "Author"); + } + #[test] fn test_toc_config_fallback() { use crate::content::Frontmatter;