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
This commit is contained in:
59
scripts/fix-code-blocks.mjs
Normal file
59
scripts/fix-code-blocks.mjs
Normal file
@@ -0,0 +1,59 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const contentDir = path.join(__dirname, "..", "content", "resources");
|
||||
|
||||
const files = fs.readdirSync(contentDir).filter((f) => f.endsWith(".mdx"));
|
||||
|
||||
let totalFixed = 0;
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = path.join(contentDir, file);
|
||||
const raw = fs.readFileSync(filePath, "utf-8");
|
||||
|
||||
// Split frontmatter from content
|
||||
const fmMatch = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
||||
if (!fmMatch) continue;
|
||||
|
||||
const frontmatter = fmMatch[1];
|
||||
const content = fmMatch[2];
|
||||
|
||||
const lines = content.split("\n");
|
||||
let insideFencedBlock = false;
|
||||
let changed = false;
|
||||
const result = [];
|
||||
|
||||
for (let line of lines) {
|
||||
// Toggle fenced code block state
|
||||
if (/^```/.test(line.trimStart())) {
|
||||
insideFencedBlock = !insideFencedBlock;
|
||||
result.push(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (insideFencedBlock) {
|
||||
// Inside fenced code block: unescape HTML entities
|
||||
const newLine = line.replace(/</g, "<").replace(/>/g, ">");
|
||||
if (newLine !== line) changed = true;
|
||||
result.push(newLine);
|
||||
} else {
|
||||
// Outside fenced block: fix inline code spans
|
||||
const newLine = line.replace(/`[^`]+`/g, (match) => {
|
||||
return match.replace(/</g, "<").replace(/>/g, ">");
|
||||
});
|
||||
if (newLine !== line) changed = true;
|
||||
result.push(newLine);
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
const output = `---\n${frontmatter}\n---\n${result.join("\n")}`;
|
||||
fs.writeFileSync(filePath, output, "utf-8");
|
||||
totalFixed++;
|
||||
console.log(`Fixed: ${file}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\nDone. Fixed ${totalFixed} files.`);
|
||||
Reference in New Issue
Block a user