Three scripts to support blog system improvements:
1. fix-blog-dates.js
- Fixes empty {} published_at values in database
- Sets proper ISODate values for 3 blogs
- Also updates moderation.approved_at for consistency
2. add-blog-categories.js
- Adds category field to all blog posts
- Maps content to standardized categories (Framework Updates,
Implementation, Case Studies)
- Enables category filtering functionality
3. add-vetting-notice-to-architectural-boundaries.js
- Adds comprehensive human vetting notice
- Documents AI-curated content review process
- Shows governance working end-to-end with inst_017 compliance
Applied to both tractatus_dev and tractatus_prod databases.
Ref: SESSION_HANDOFF_2025-10-23_WEBSITE_AUDIT.md
124 lines
3.3 KiB
JavaScript
124 lines
3.3 KiB
JavaScript
/**
|
|
* Add Category Field to Blog Posts
|
|
* Maps tags/content to standardized categories for filtering
|
|
*/
|
|
|
|
const { MongoClient } = require('mongodb');
|
|
|
|
const DEV_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017';
|
|
const DEV_DB = process.env.MONGODB_DB || 'tractatus_dev';
|
|
|
|
// Category assignments based on blog content and tags
|
|
const CATEGORY_ASSIGNMENTS = [
|
|
{
|
|
slug: 'why-ai-safety-requires-architectural-boundaries-not-just-training',
|
|
category: 'Implementation',
|
|
reason: 'Technical implementation guide with actionable takeaways'
|
|
},
|
|
{
|
|
slug: 'scaling-tractatus-roadmap',
|
|
category: 'Framework Updates',
|
|
reason: 'Roadmap and strategic plan for framework scaling'
|
|
},
|
|
{
|
|
slug: 'introducing-tractatus-framework',
|
|
category: 'Framework Updates',
|
|
reason: 'Framework introduction and overview'
|
|
},
|
|
{
|
|
slug: 'when-frameworks-fail-case-study',
|
|
category: 'Case Studies',
|
|
reason: 'Case study on framework failures'
|
|
},
|
|
{
|
|
slug: 'five-component-tractatus-architecture',
|
|
category: 'Framework Updates',
|
|
reason: 'Framework architecture explanation'
|
|
},
|
|
{
|
|
slug: 'tractatus-blog-system-launch',
|
|
category: 'Framework Updates',
|
|
reason: 'Framework feature announcement'
|
|
}
|
|
];
|
|
|
|
async function addCategories() {
|
|
const client = new MongoClient(DEV_URI);
|
|
|
|
try {
|
|
console.log('\n📁 Adding Category Field to Blog Posts\n');
|
|
console.log('═'.repeat(70));
|
|
|
|
await client.connect();
|
|
const db = client.db(DEV_DB);
|
|
const collection = db.collection('blog_posts');
|
|
|
|
let updated = 0;
|
|
let notFound = 0;
|
|
|
|
for (const assignment of CATEGORY_ASSIGNMENTS) {
|
|
const blog = await collection.findOne({ slug: assignment.slug });
|
|
|
|
if (!blog) {
|
|
console.log(`\n❌ Blog not found: ${assignment.slug}`);
|
|
notFound++;
|
|
continue;
|
|
}
|
|
|
|
console.log(`\n📄 ${blog.title}`);
|
|
console.log(` Slug: ${assignment.slug}`);
|
|
console.log(` Category: ${assignment.category}`);
|
|
console.log(` Reason: ${assignment.reason}`);
|
|
|
|
const result = await collection.updateOne(
|
|
{ slug: assignment.slug },
|
|
{ $set: { category: assignment.category } }
|
|
);
|
|
|
|
if (result.modifiedCount === 1) {
|
|
console.log(` ✅ Category added`);
|
|
updated++;
|
|
} else {
|
|
console.log(` ⚠️ No change (may already have category)`);
|
|
}
|
|
}
|
|
|
|
console.log('\n' + '═'.repeat(70));
|
|
console.log(`\n✨ Complete: ${updated} categories added, ${notFound} not found\n`);
|
|
|
|
// Show category distribution
|
|
console.log('Category Distribution:');
|
|
const categories = await collection.aggregate([
|
|
{ $match: { status: 'published' } },
|
|
{ $group: { _id: '$category', count: { $sum: 1 } } },
|
|
{ $sort: { count: -1 } }
|
|
]).toArray();
|
|
|
|
for (const cat of categories) {
|
|
console.log(` ${cat._id || '(no category)'}: ${cat.count}`);
|
|
}
|
|
console.log('');
|
|
|
|
return updated > 0;
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error:', error.message);
|
|
throw error;
|
|
} finally {
|
|
await client.close();
|
|
}
|
|
}
|
|
|
|
// Run if called directly
|
|
if (require.main === module) {
|
|
addCategories()
|
|
.then((success) => {
|
|
process.exit(success ? 0 : 1);
|
|
})
|
|
.catch(error => {
|
|
console.error('\n💥 Failed:', error);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
module.exports = { addCategories, CATEGORY_ASSIGNMENTS };
|