1f17fb40dc
Жалоба пользователя по Физике 8 (но проблема общая для Phys 8 и Phys 9): страницы глав используют классы .wg/.dnd-pool/.dnd-chip/.btn/.score-display/ .feedback/.actions/.sliders/.spoiler/.drop-box в HTML-разметке, но CSS-правила для них живут только в physics_10_ch1.html. Из-за этого карточки-задания, chip'ы drag-and-drop, кнопки и feedback-блоки в Phys 8 и Phys 9 рендерились без стилей (как обычный текст). - extract_widget_css.cjs: вытягивает CSS-блок (.btn..pre-.col-side) из physics_10_ch1.html в frontend/css/phys-textbook-widgets.css (6.4 КБ) - Подключает <link> в 11 файлов: physics_8_ch1/ch2/ch3/hub/lab, physics_9_ch1..ch5, physics_9_hub - migrate_phys9_content.js теперь инжектит ссылку на widget CSS при будущих миграциях (рядом с FA CDN)
55 lines
2.2 KiB
JavaScript
55 lines
2.2 KiB
JavaScript
// Извлекает CSS виджетов (.wg, .dnd-pool, .btn, .feedback, .sliders, .score-display, .spoiler)
|
|
// из physics_10_ch1.html в frontend/css/phys-textbook-widgets.css.
|
|
// Подключается из всех physics_8_*.html и physics_9_*.html файлов.
|
|
'use strict';
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const SRC = path.join(__dirname, '..', '..', 'frontend', 'textbooks', 'physics_10_ch1.html');
|
|
const DST_CSS = path.join(__dirname, '..', '..', 'frontend', 'css', 'phys-textbook-widgets.css');
|
|
|
|
const h = fs.readFileSync(SRC, 'utf8');
|
|
const css = h.match(/<style>([\s\S]*?)<\/style>/)[1];
|
|
|
|
const start = css.indexOf('.btn{');
|
|
const end = css.indexOf('.col-side{');
|
|
if (start < 0 || end < 0) { console.error('Markers not found'); process.exit(1); }
|
|
|
|
const block = css.slice(start, end).trim();
|
|
|
|
const header =
|
|
'/* Auto-extracted from frontend/textbooks/physics_10_ch1.html.\n' +
|
|
' * Provides .wg, .dnd-pool, .dnd-chip, .drop-box, .btn, .feedback,\n' +
|
|
' * .actions, .sliders, .score-display, .spoiler — shared interactive\n' +
|
|
' * widget styles for all physics-N chapter pages.\n' +
|
|
' * Generated by backend/scripts/extract_widget_css.cjs.\n' +
|
|
' */\n\n';
|
|
|
|
fs.writeFileSync(DST_CSS, header + block + '\n');
|
|
console.log('Wrote', DST_CSS, '(' + (header.length + block.length) + ' bytes)');
|
|
|
|
// === Inject <link> in all physics_8_*.html and physics_9_*.html that miss it ===
|
|
const TBOOKS = path.dirname(SRC);
|
|
const files = fs.readdirSync(TBOOKS).filter(f =>
|
|
/^physics_[89]_(ch\d|hub|lab)\.html$/.test(f)
|
|
);
|
|
|
|
const LINK_TAG = '<link rel="stylesheet" href="/css/phys-textbook-widgets.css">';
|
|
const ANCHOR = '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">';
|
|
|
|
let injectedCount = 0;
|
|
for (const f of files) {
|
|
const p = path.join(TBOOKS, f);
|
|
let body = fs.readFileSync(p, 'utf8');
|
|
if (body.includes('phys-textbook-widgets.css')) continue;
|
|
if (!body.includes(ANCHOR)) {
|
|
console.warn(' skip', f, '(no katex anchor)');
|
|
continue;
|
|
}
|
|
body = body.replace(ANCHOR, ANCHOR + '\n' + LINK_TAG);
|
|
fs.writeFileSync(p, body);
|
|
injectedCount++;
|
|
console.log(' injected →', f);
|
|
}
|
|
console.log('Total injected:', injectedCount, '/', files.length);
|