Files
micromelon-website/scripts/cleanup-mdx.mjs
Tim Hadwen 707c49dd3f Build Your Kit page and full Micromelon website
Complete website build including:
- Build Your Kit store page with cart system, sectioned layout
  (Hardware, Software, Attachments, Spare Parts), inline quote
  request form, and sticky sidebar summary
- 16+ pages: Education, Platform, Resources, News, About Us,
  Download, Contact, Rover, Code Editor, Robot Simulator, etc.
- 89+ MDX resource articles and 18 news posts
- Store product images scraped from micromelon.com.au
- Quote request API route with Airtable integration
- Dynamic back links and cover photos on resource pages
- Redesigned downloads page
- Fixed corrupted MDX code blocks
2026-02-28 19:00:42 +10:00

46 lines
1.6 KiB
JavaScript

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const dir = path.join(__dirname, '..', 'content', 'resources');
let fixed = 0;
for (const f of fs.readdirSync(dir).filter(f => f.endsWith('.mdx'))) {
const filepath = path.join(dir, f);
const original = fs.readFileSync(filepath, 'utf8');
let content = original;
// Clean excerpts that contain HTML/CSS artifacts
const excerptMatch = content.match(/^excerpt: "(.*)"$/m);
if (excerptMatch) {
let excerpt = excerptMatch[1];
excerpt = excerpt.replace(/#block-[^\s]+ \{[^}]*\}/g, '');
excerpt = excerpt.replace(/!\[[^\]]*\]\([^)]*\)/g, '');
excerpt = excerpt.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1');
excerpt = excerpt.replace(/\*\*/g, '');
excerpt = excerpt.replace(/\s+/g, ' ').trim().substring(0, 250);
if (excerpt !== excerptMatch[1]) {
content = content.replace(excerptMatch[0], `excerpt: "${excerpt}"`);
}
}
// Remove BACK TO POSTS lines
content = content.replace(/\[?\s*\*?\*?BACK TO POSTS\s*\*?\*?\s*\]?\s*\([^)]*\)\s*(\*?\*?\s*\|?\s*\*?\*?\s*\[?\*?\*?OPEN PAGE AS PDF\*?\*?\]?\([^)]*\))?/gi, '');
// Remove --> artifacts
content = content.replace(/^-->\s*$/gm, '');
// Remove CSS block definitions
content = content.replace(/#block-[a-zA-Z0-9_-]+ \{[^}]*\}/g, '');
// Clean excessive blank lines
content = content.replace(/\n{3,}/g, '\n\n');
if (content !== original) {
fs.writeFileSync(filepath, content);
fixed++;
}
}
console.log(`Cleaned ${fixed} files`);