feat(migration): complete WordPress migration and UX refinements
- Migrate historical posts, localized assets, and 103 comments - Colocate media into posts/<slug>/images/ and remove wp-content - Add native bilingual support for ai-can-change post (English default, /zh variant) - Support clean taxonomy routing (/category/:category and /tag/:tag) - Dynamically populate categories and tags in sitemap.xml - Fix header scroll padding/margin offsets for anchor and reference links - Constrain image and media widths to prevent content overflow - Redesign homepage recent posts to 4 compact editorial cards - Restore valid binary favicon.ico and high-res icon assets - Remove placeholder content and sample test comments
This commit is contained in:
@@ -80,6 +80,37 @@ class DatabaseService {
|
||||
CREATE INDEX IF NOT EXISTS idx_comments_email ON comments(author_email);
|
||||
`);
|
||||
|
||||
// Auto-seed comments if comments table is newly created and comments.json exists
|
||||
try {
|
||||
const count = this.db.prepare('SELECT COUNT(*) as c FROM comments').get().c;
|
||||
const seedFile = path.join(dataDir, 'comments.json');
|
||||
if (count === 0 && fs.existsSync(seedFile)) {
|
||||
const seedData = JSON.parse(fs.readFileSync(seedFile, 'utf8'));
|
||||
const insertStmt = this.db.prepare(`
|
||||
INSERT INTO comments (id, post_slug, author_name, author_email, author_website, body, created_at, approved, ip)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
this.db.exec('BEGIN');
|
||||
for (const c of seedData) {
|
||||
insertStmt.run(
|
||||
c.id,
|
||||
c.post_slug,
|
||||
c.author_name,
|
||||
c.author_email,
|
||||
c.author_website,
|
||||
c.body,
|
||||
c.created_at,
|
||||
c.approved,
|
||||
c.ip || ''
|
||||
);
|
||||
}
|
||||
this.db.exec('COMMIT');
|
||||
console.log(`[DB] Seeded ${seedData.length} comments from ${seedFile}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[DB] Warning: Failed to auto-seed comments:', err.message);
|
||||
}
|
||||
|
||||
console.log(`[DB] Unified SQLite database initialized at ${this.dbPath}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user