From 1de99cbe38cbe5e00fe4459be2580b6488e8dc20 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Tue, 31 Mar 2026 09:12:19 +0530 Subject: [PATCH] migrate strip-spec-container to TS --- setup/strip-spec-container.ts | 44 +++++++++++++++++++++++++++++++++++ strip-spec-container.cjs | 17 -------------- 2 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 setup/strip-spec-container.ts delete mode 100644 strip-spec-container.cjs diff --git a/setup/strip-spec-container.ts b/setup/strip-spec-container.ts new file mode 100644 index 0000000..73738ed --- /dev/null +++ b/setup/strip-spec-container.ts @@ -0,0 +1,44 @@ +#!/usr/bin/env bun +import fs from "node:fs"; +import path from "node:path"; +import * as cheerio from "cheerio"; + +/** + * Strips HTML files to only contain the #spec-container element. + * + * This script processes HTML files in the spec-built/multipage directory, + * extracts the #spec-container element, and replaces the entire body + * content with just that container. This reduces file size and focuses + * only on the specification content. + */ + +const SPEC_DIR = path.join(__dirname, "../spec-built/multipage"); + +function stripSpecContainer(): void { + const files = fs.readdirSync(SPEC_DIR); + let processedCount = 0; + + for (const file of files) { + if (!file.endsWith(".html")) { + continue; + } + + const filePath = path.join(SPEC_DIR, file); + const content = fs.readFileSync(filePath, "utf-8"); + const $ = cheerio.load(content); + const container = $("#spec-container"); + + if (container.length) { + $("body").empty().append(container); + fs.writeFileSync(filePath, $.html()); + console.log(`Processed ${file}`); + processedCount++; + } else { + console.warn(`Warning: #spec-container not found in ${file}`); + } + } + + console.log(`\nProcessed ${processedCount} HTML file(s)`); +} + +stripSpecContainer(); diff --git a/strip-spec-container.cjs b/strip-spec-container.cjs deleted file mode 100644 index 78f951c..0000000 --- a/strip-spec-container.cjs +++ /dev/null @@ -1,17 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const cheerio = require("cheerio"); - -const dir = path.join(__dirname, "spec-built/multipage"); -fs.readdirSync(dir).forEach((file) => { - if (!file.endsWith(".html")) return; - const filePath = path.join(dir, file); - const content = fs.readFileSync(filePath, "utf-8"); - const $ = cheerio.load(content); - const container = $("#spec-container"); - if (container.length) { - $("body").empty().append(container); - fs.writeFileSync(filePath, $.html()); - console.log(`Processed ${file}`); - } -});