feat: finalisation of M1
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user