How nsfoxer/cnblog works
Project Type and Purpose
• Type: Open-source CLI synchronization tool
• Purpose: Scan a local directory of Markdown files, store metadata in SQLite, Base64-encode the DB, and push/pull blog posts through the MetaWeblog API on Cnblog
File Structure
• Top level:
• Cargo.toml / Cargo.lock – Rust manifest & dependency lock
• README.md – project description & usage
• src/main.rs – CLI entry point
• src/lib.rs – library exports & orchestrator
• src/meta_weblog/ – module handling config, RPC, and weblog logic
· cfg.rs – config file parsing & storage path
· rpc.rs – HTTP client for MetaWeblog endpoints
· weblog.rs – blog-specific data structures & sync logic
• Implication: Clear separation between CLI, configuration, RPC, business logic, and persistence
Extract Key Components from README
• Config folder (defaults to ~/.config/cnblog/)
• CLI flags: -c, -r, -h, -V
• Workflow: scan directory → detect new/changed/deleted → update SQLite → base64-encode → upload via MetaWeblog → handle responses → move deleted posts locally
Main Components & Their Relationships
a. CLI Frontend (main.rs)
– Parses flags, invokes library functions
b. Config Manager (cfg.rs)
– Loads/saves JSON or TOML config (API keys, endpoints, local root path)
c. File Scanner (lib.rs / weblog.rs)
– Walks target directory, computes diffs (new/modified/deleted)
d. SQLite Storage
– Persists metadata: post IDs, timestamps, checksums
e. Base64 Encoder
– Encodes SQLite DB file before uploading as fallback storage
f. RPC Client (rpc.rs)
– Wraps XML-RPC calls to MetaWeblog API (newPost, editPost, getRecentPosts)
g. Cnblog Service (External)
– Remote blog host providing the MetaWeblog endpoint
h. Local Filesystem
– Source of truth for posts; .cnblog_deleted folder for removed items
Architectural Patterns & Design Principles
• Modular layering:
1. Presentation Layer: CLI
2. Application Layer: lib.rs orchestrator & weblog logic
3. Infrastructure Layer: config & RPC modules, SQLite persistence
4. External Systems: Local FS & Cnblog API
• Separation of concerns: each module has a single responsibility
• Data flow orchestration: pipeline from scanning → persistence → encoding → network