tractatus/scripts/add-sections-to-17-docs.js
TheFlow ac2db33732 fix(submissions): restructure Economist package and fix article display
- Create Economist SubmissionTracking package correctly:
  * mainArticle = full blog post content
  * coverLetter = 216-word SIR— letter
  * Links to blog post via blogPostId
- Archive 'Letter to The Economist' from blog posts (it's the cover letter)
- Fix date display on article cards (use published_at)
- Target publication already displaying via blue badge

Database changes:
- Make blogPostId optional in SubmissionTracking model
- Economist package ID: 68fa85ae49d4900e7f2ecd83
- Le Monde package ID: 68fa2abd2e6acd5691932150

Next: Enhanced modal with tabs, validation, export

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-24 08:47:42 +13:00

139 lines
5.6 KiB
JavaScript

#!/usr/bin/env node
/**
* Add Card View Sections to 17 Documents
*
* Adds card view sections to:
* - 5 newly imported archives
* - 12 existing documents without sections
*/
require('dotenv').config();
const fs = require('fs');
const path = require('path');
const { connect, close } = require('../src/utils/db.util');
const Document = require('../src/models/Document.model');
const { processMarkdownFile } = require('./generate-card-sections.js');
const DOCS_TO_PROCESS = [
// 5 newly imported archives
{ slug: 'case-studies-real-world-llm-failure-modes-appendix', mdPath: 'docs/markdown/case-studies.md' },
{ slug: 'implementation-guide-python-examples', mdPath: 'docs/api/examples-python.md' },
{ slug: 'tractatus-framework-enforcement-claude-code', mdPath: 'docs/claude-code-framework-enforcement.md' },
{ slug: 'research-topic-concurrent-session-architecture', mdPath: 'docs/research/concurrent-session-architecture-limitations.md' },
{ slug: 'research-topic-rule-proliferation-transactional-overhead', mdPath: 'docs/research/rule-proliferation-and-transactional-overhead.md' },
// 5 technical reference docs without sections
{ slug: 'implementation-roadmap-24-month-deployment-plan', mdPath: 'docs/markdown/implementation-roadmap-24-month-deployment-plan.md' },
{ slug: 'api-reference-complete', mdPath: 'docs/markdown/api-reference-complete.md' },
{ slug: 'api-javascript-examples', mdPath: 'docs/api/examples-javascript.md' },
{ slug: 'api-python-examples', mdPath: 'docs/api/examples-python.md' },
{ slug: 'openapi-specification', mdPath: 'docs/markdown/openapi-specification.md' },
// 5 case studies without sections
{ slug: 'the-27027-incident-a-case-study-in-pattern-recognition-bias', mdPath: 'docs/case-studies/27027-incident-detailed-analysis.md' },
{ slug: 'when-frameworks-fail-and-why-thats-ok', mdPath: 'docs/case-studies/when-frameworks-fail-oct-2025.md' },
{ slug: 'our-framework-in-action-detecting-and-correcting-ai-fabrications', mdPath: 'docs/case-studies/framework-in-action-oct-2025.md' },
{ slug: 'real-world-ai-governance-a-case-study-in-framework-failure-and-recovery', mdPath: 'docs/case-studies/real-world-governance-case-study-oct-2025.md' },
{ slug: 'case-studies-real-world-llm-failure-modes', mdPath: 'docs/markdown/case-studies.md' },
// 2 Phase 5 PoC summaries
{ slug: 'phase-5-poc-session-1-summary', mdPath: 'docs/markdown/phase-5-session1-summary.md' },
{ slug: 'phase-5-poc-session-2-summary', mdPath: 'docs/markdown/phase-5-session2-summary.md' }
];
async function addSectionsToDocument(docInfo) {
console.log(`\n📄 Processing: ${docInfo.slug}`);
try {
// Check if document exists
const doc = await Document.findBySlug(docInfo.slug);
if (!doc) {
console.log(` ❌ Document not found in database`);
return { success: false, reason: 'not_found' };
}
// Check if already has sections
if (doc.sections && doc.sections.length > 0) {
console.log(` ⏭️ Already has ${doc.sections.length} sections, skipping`);
return { success: false, reason: 'has_sections' };
}
// Build full path to markdown file
const fullPath = path.join('/home/theflow/projects/tractatus', docInfo.mdPath);
// Check if markdown file exists
if (!fs.existsSync(fullPath)) {
console.log(` ❌ Markdown file not found: ${fullPath}`);
return { success: false, reason: 'md_not_found' };
}
// Generate sections
console.log(` 📝 Generating sections from: ${docInfo.mdPath}`);
const sections = await processMarkdownFile(fullPath);
if (!sections || sections.length === 0) {
console.log(` ⚠️ No sections generated (possibly no H2 headers)`);
return { success: false, reason: 'no_sections' };
}
// Update document with sections
const updated = await Document.update(doc._id.toString(), { sections });
if (!updated) {
console.log(` ❌ Failed to update document`);
return { success: false, reason: 'update_failed' };
}
console.log(` ✅ Added ${sections.length} sections`);
return { success: true, sections: sections.length };
} catch (error) {
console.error(` ❌ Error: ${error.message}`);
return { success: false, error: error.message };
}
}
async function main() {
try {
console.log('🚀 Adding Card View Sections to 17 Documents\n');
console.log('═══════════════════════════════════════════════════\n');
await connect();
let added = 0;
let skipped = 0;
let notFound = 0;
let failed = 0;
for (const docInfo of DOCS_TO_PROCESS) {
const result = await addSectionsToDocument(docInfo);
if (result.success) {
added++;
} else if (result.reason === 'has_sections') {
skipped++;
} else if (result.reason === 'not_found' || result.reason === 'md_not_found') {
notFound++;
} else {
failed++;
}
}
console.log('\n═══════════════════════════════════════════════════');
console.log('\n📊 Summary:');
console.log(` ✅ Added sections: ${added}`);
console.log(` ⏭️ Skipped (already have sections): ${skipped}`);
console.log(` ❌ Not found: ${notFound}`);
console.log(` ❌ Failed: ${failed}`);
console.log(` 📦 Total processed: ${DOCS_TO_PROCESS.length}`);
await close();
} catch (error) {
console.error('\n❌ Fatal error:', error);
process.exit(1);
}
}
main();