diff --git a/.claude/private/CLAUDE.md b/.claude/private/CLAUDE.md index 2ddb784..6c6e867 100644 Binary files a/.claude/private/CLAUDE.md and b/.claude/private/CLAUDE.md differ diff --git a/server/crates/publish/src/site.rs b/server/crates/publish/src/site.rs index 3b65575..68dc385 100644 --- a/server/crates/publish/src/site.rs +++ b/server/crates/publish/src/site.rs @@ -38,8 +38,9 @@ pub struct SiteLimits { pub media: usize, pub media_bytes: u64, pub media_file: u64, - /// Files and bytes for a site with a cookbook: recipes are mostly - /// photographs. + /// Pages, files and bytes for a site with a cookbook: a cookbook is + /// many recipes, mostly photographs. + pub cookbook_pages: usize, pub cookbook_media: usize, pub cookbook_bytes: u64, } @@ -51,8 +52,9 @@ impl Default for SiteLimits { media: 377, media_bytes: 144 << 20, media_file: 21 << 20, - cookbook_media: 987, - cookbook_bytes: 610 << 20, + cookbook_pages: 1597, + cookbook_media: 2584, + cookbook_bytes: 1597 << 20, } } } @@ -240,7 +242,14 @@ impl Site { } let key = format!("{PAGES}{slug}"); let new = self.store.get(&key)?.is_none(); - if new && self.store.list(PAGES, None, usize::MAX)?.len() >= self.limits.pages { + // A recipe for the cookbook, or any page of a site that has one, + // counts against the cookbook's room. + let pages = if (page.listed && page.recipe.is_some()) || self.has_cookbook()? { + self.limits.pages.max(self.limits.cookbook_pages) + } else { + self.limits.pages + }; + if new && self.store.list(PAGES, None, usize::MAX)?.len() >= pages { return Err(SiteError::Full); } let listed = match &page.recipe { diff --git a/server/crates/publish/tests/site.rs b/server/crates/publish/tests/site.rs index 76244a5..5c821bc 100644 --- a/server/crates/publish/tests/site.rs +++ b/server/crates/publish/tests/site.rs @@ -254,6 +254,21 @@ fn the_cookbook_address_is_not_a_page() { assert_eq!(put(&mut site, &owner(), "ricette", &page("Ricette", "x")), Err(SiteError::NotFound)); } +#[test] +fn a_site_with_a_cookbook_holds_more_pages() { + let mut site = claimed().with_limits(SiteLimits { pages: 1, cookbook_pages: 3, ..SiteLimits::default() }); + put(&mut site, &owner(), "diario", &page("Diario", "x")).unwrap(); + assert_eq!(put(&mut site, &owner(), "altro", &page("Altro", "x")), Err(SiteError::Full)); + // Recipes for the cookbook have its room, and so has the site then. + put(&mut site, &owner(), "pane", &recipe("Pane", "Lievitati", true)).unwrap(); + put(&mut site, &owner(), "altro", &page("Altro", "x")).unwrap(); + assert_eq!(put(&mut site, &owner(), "seadas", &recipe("Seadas", "Dolci", true)), Err(SiteError::Full)); + // A draft recipe is not the cookbook's. + let mut plain = claimed().with_limits(SiteLimits { pages: 1, cookbook_pages: 3, ..SiteLimits::default() }); + put(&mut plain, &owner(), "diario", &page("Diario", "x")).unwrap(); + assert_eq!(put(&mut plain, &owner(), "bozza", &recipe("Bozza", "Dolci", false)), Err(SiteError::Full)); +} + #[test] fn a_site_with_a_cookbook_holds_more_files() { let mut site = claimed().with_limits(SiteLimits {