Files
mintel.me/apps/web/scripts/optimize-blog-post.ts
Marc Mintel 3eccff42e4
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 5s
Build & Deploy / 🧪 QA (push) Failing after 1m31s
Build & Deploy / 🏗️ Build (push) Failing after 3m51s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
chore: fix linting and build errors
2026-02-17 23:48:52 +01:00

108 lines
3.7 KiB
TypeScript

import { ContentGenerator, OptimizationOptions } from "@mintel/content-engine";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function main() {
const OPENROUTER_KEY = process.env.OPENROUTER_KEY;
if (!OPENROUTER_KEY) {
console.error("❌ Error: OPENROUTER_KEY not found in environment.");
process.exit(1);
}
const args = process.argv.slice(2);
let targetFile = args[0];
if (!targetFile) {
console.error("❌ Usage: npx tsx scripts/optimize-blog-post.ts <path/to/post.mdx>");
process.exit(1);
}
// Resolve absolute path
if (!path.isAbsolute(targetFile)) {
targetFile = path.resolve(process.cwd(), targetFile);
}
console.log(`📄 Reading file: ${targetFile}`);
let content = "";
try {
content = await fs.readFile(targetFile, "utf8");
} catch (err: any) {
console.error(`❌ Could not read file: ${err.message}`);
process.exit(1);
}
// Backup original
const backupPath = `${targetFile}.bak`;
await fs.writeFile(backupPath, content);
console.log(`💾 Backup created at: ${backupPath}`);
// Instantiate Generator
const generator = new ContentGenerator(OPENROUTER_KEY);
const context = `
Project: Mintel.me
Style: Industrial, Technical, High-Performance, "No-BS".
Author: Marc Mintel (Digital Architect).
Focus: Web Architecture, PageSpeed, Core Web Vitals, Data-Driven Design.
`;
// Define Optimization Options based on user request ("astrein verbessert mit daten gestützt, links zu quellen usw... mermaid, memes")
const options: OptimizationOptions = {
enhanceFacts: true,
addMemes: true,
addDiagrams: true,
projectContext: context,
availableComponents: [
{
name: "StatsDisplay",
description: "A row of 3 clear statistic cards with values and labels.",
usageExample: `<StatsDisplay
items={[
{ value: "-20%", label: "Conversion", description: "Source: Google" },
{ value: "53%", label: "Bounce Rate", description: "Mobile users > 3s" },
{ value: "0.1s", label: "Latency", description: "Edge Network" }
]}
/>`
},
{
name: "ComparisonRow",
description: "A comparison component showing a negative 'Standard' vs a positive 'Mintel' approach.",
usageExample: `<ComparisonRow
description="Architecture Comparison"
negativeLabel="Legacy CMS"
negativeText="Slow database queries, vulnerable plugins."
positiveLabel="Mintel Stack"
positiveText="Static generation, perfect security."
/>`
}
]
};
// 1. Separate Frontmatter from Body
const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
const frontmatter = fmMatch ? fmMatch[0] : "";
const body = fmMatch ? content.replace(frontmatter, "").trim() : content;
console.log("🚀 Starting Optimization via ContentEngine...");
const result = await generator.optimizePost(body, options);
console.log("✅ Optimization Complete!");
console.log(` - Added ${result.research.length} facts`);
console.log(` - Added ${result.memes.length} meme concepts`);
console.log(` - Generated ${result.diagrams.length} diagrams`);
// We write the content back (re-attaching frontmatter if it was there)
const finalContent = frontmatter ? `${frontmatter}\n\n${result.content}` : result.content;
await fs.writeFile(targetFile, finalContent);
console.log(`💾 Saved optimized content to: ${targetFile}`);
}
main().catch(console.error);