#!/usr/bin/env node // Replace sidebar HTML with // and add after api.js on each page. const fs = require('fs'); const path = require('path'); const FRONTEND = path.join(__dirname, '..', 'frontend'); // Pages that get the universal sidebar (excludes test-run.html, login.html, 403/404/500, parent.html, guest-board.html) const PAGES = [ 'admin', 'analytics', 'biochem', 'biochem-library', 'biochem-pathways', 'biochem-properties', 'biochem-reactions', 'board', 'classes', 'classroom', 'collection', 'collection-rb', 'course', 'crossword', 'dashboard', 'flashcards', 'gradebook', 'hangman', 'homework', 'knowledge-map', 'lab', 'lesson', 'lesson-editor', 'lesson-history', 'library', 'live-quiz', 'my-lessons', 'pet', 'profile', 'question-bank', 'red-book', 'red-book-biomes', 'red-book-ecosystem', 'red-book-games', 'theory', ]; // Regex: match // Handles optional extra attributes and multi-line content const ASIDE_RE = /]*\bclass="sidebar"[^>]*>[\s\S]*?<\/aside>/; // Match existing sidebar.js script tag const SIDEBAR_SCRIPT_RE = /<\/script>/; // Match api.js script tag const API_SCRIPT_RE = /(<\/script>)/; let changed = 0; let skipped = 0; let errors = 0; for (const name of PAGES) { const file = path.join(FRONTEND, `${name}.html`); if (!fs.existsSync(file)) { console.log(` SKIP ${name}.html (not found)`); skipped++; continue; } let src = fs.readFileSync(file, 'utf8'); let modified = false; // 1. Replace sidebar