chore: cleanups and refactorings for cleaner code

This commit is contained in:
2026-07-18 21:39:16 +02:00
parent b438a99999
commit e5080b7282
63 changed files with 3454 additions and 4093 deletions

View File

@@ -164,75 +164,6 @@ pub fn remove_category(data_dir: &Path, category: &str) -> EngineResult<()> {
Ok(())
}
// ── update helpers ──────────────────────────────────────────────────
/// Update the blog_languages list in project.json.
/// Per metadata.allium UpdateProjectMetadata: writes ProjectJsonWritten.
pub fn update_blog_languages(data_dir: &Path, languages: Vec<String>) -> EngineResult<()> {
let mut meta = read_project_json(data_dir)?;
meta.blog_languages = languages;
write_project_json(data_dir, &meta)?;
Ok(())
}
/// Update arbitrary fields of project metadata.
/// Per metadata.allium UpdateProjectMetadata rule.
pub fn update_project_metadata(data_dir: &Path, changes: &serde_json::Value) -> EngineResult<()> {
let mut meta = read_project_json(data_dir)?;
if let Some(name) = changes.get("name").and_then(|v| v.as_str()) {
meta.name = name.to_string();
}
if let Some(desc) = changes.get("description") {
meta.description = desc.as_str().map(|s| s.to_string());
}
if let Some(url) = changes.get("publicUrl") {
meta.public_url = url.as_str().map(|s| s.to_string());
}
if let Some(lang) = changes.get("mainLanguage") {
meta.main_language = lang.as_str().map(|s| s.to_string());
}
if let Some(author) = changes.get("defaultAuthor") {
meta.default_author = author.as_str().map(|s| s.to_string());
}
if let Some(max) = changes.get("maxPostsPerPage").and_then(|v| v.as_i64()) {
meta.max_posts_per_page = max as i32;
}
if let Some(concurrency) = changes.get("imageImportConcurrency") {
meta.image_import_concurrency = concurrency
.as_i64()
.map(|value| value as i32)
.or_else(|| {
concurrency
.as_str()
.and_then(|value| value.parse::<i32>().ok())
})
.unwrap_or(4)
.clamp(1, 8);
}
if let Some(cat) = changes.get("blogmarkCategory") {
meta.blogmark_category = cat.as_str().map(|s| s.to_string());
}
if let Some(theme) = changes.get("picoTheme") {
meta.pico_theme = theme.as_str().map(|s| s.to_string());
}
if let Some(enabled) = changes
.get("semanticSimilarityEnabled")
.and_then(|v| v.as_bool())
{
meta.semantic_similarity_enabled = enabled;
}
if let Some(langs) = changes.get("blogLanguages").and_then(|v| v.as_array()) {
meta.blog_languages = langs
.iter()
.filter_map(|v| v.as_str().map(|s| s.to_string()))
.collect();
}
meta.validate()
.map_err(crate::engine::EngineError::Validation)?;
write_project_json(data_dir, &meta)?;
Ok(())
}
// ── startup sync ────────────────────────────────────────────────────
/// Per metadata.allium StartupSync: loads metadata from filesystem, creating