feat: finalisation of M1

This commit is contained in:
2026-04-04 15:46:57 +02:00
parent 2d07ac7866
commit b532104032
10 changed files with 725 additions and 71 deletions

View File

@@ -34,6 +34,19 @@ pub struct ProjectMetadata {
pub blog_languages: Vec<String>,
}
impl ProjectMetadata {
/// Validate metadata fields per spec constraints.
pub fn validate(&self) -> Result<(), String> {
if self.max_posts_per_page < 1 || self.max_posts_per_page > 500 {
return Err(format!(
"maxPostsPerPage must be 1..500, got {}",
self.max_posts_per_page
));
}
Ok(())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CategorySettings {
@@ -143,4 +156,28 @@ mod tests {
assert!(tag.color.is_none());
assert!(tag.post_template_slug.is_none());
}
#[test]
fn max_posts_per_page_validation() {
let mut meta = ProjectMetadata {
name: "Test".into(),
description: None, public_url: None, main_language: None,
default_author: None, max_posts_per_page: 50, blogmark_category: None,
pico_theme: None, python_runtime_mode: None,
semantic_similarity_enabled: false, blog_languages: vec![],
};
assert!(meta.validate().is_ok());
meta.max_posts_per_page = 0;
assert!(meta.validate().is_err());
meta.max_posts_per_page = 501;
assert!(meta.validate().is_err());
meta.max_posts_per_page = 1;
assert!(meta.validate().is_ok());
meta.max_posts_per_page = 500;
assert!(meta.validate().is_ok());
}
}

View File

@@ -8,6 +8,13 @@ pub enum PostStatus {
Archived,
}
impl PostStatus {
/// Returns true if this status is valid for a translation (draft or published only).
pub fn is_valid_for_translation(&self) -> bool {
matches!(self, PostStatus::Draft | PostStatus::Published)
}
}
/// A blog post. Matches the `posts` table schema.
///
/// NOTE: `content` is null for published posts — body lives in the filesystem