docs: update refs html extract script

This commit is contained in:
2026-08-28 14:55:57 +05:00
parent ada96b3534
commit 7aa50eee6c
6 changed files with 101 additions and 5 deletions
+14
View File
@@ -2232,5 +2232,19 @@ h1 {
<template data-dgst="BAILOUT_TO_CLIENT_SIDE_RENDERING">
</template>
<!--/$-->
<script>
(function () {
var btn = document.querySelector('button[aria-label="Toggle theme"]');
var shell = document.querySelector('.app-shell');
if (!btn || window.__themeToggleInjected) return;
window.__themeToggleInjected = true;
btn.addEventListener('click', function () {
document.documentElement.classList.toggle('dark-mode');
if (shell) shell.classList.toggle('dark-mode');
});
})();
</script>
</body>
</html>
+14
View File
@@ -2590,5 +2590,19 @@ h1 {
<template data-dgst="BAILOUT_TO_CLIENT_SIDE_RENDERING">
</template>
<!--/$-->
<script>
(function () {
var btn = document.querySelector('button[aria-label="Toggle theme"]');
var shell = document.querySelector('.app-shell');
if (!btn || window.__themeToggleInjected) return;
window.__themeToggleInjected = true;
btn.addEventListener('click', function () {
document.documentElement.classList.toggle('dark-mode');
if (shell) shell.classList.toggle('dark-mode');
});
})();
</script>
</body>
</html>
+14
View File
@@ -2227,5 +2227,19 @@ opacity: 1;</pre>
<template data-dgst="BAILOUT_TO_CLIENT_SIDE_RENDERING">
</template>
<!--/$-->
<script>
(function () {
var btn = document.querySelector('button[aria-label="Toggle theme"]');
var shell = document.querySelector('.app-shell');
if (!btn || window.__themeToggleInjected) return;
window.__themeToggleInjected = true;
btn.addEventListener('click', function () {
document.documentElement.classList.toggle('dark-mode');
if (shell) shell.classList.toggle('dark-mode');
});
})();
</script>
</body>
</html>
+14
View File
@@ -2590,5 +2590,19 @@ h1 {
<template data-dgst="BAILOUT_TO_CLIENT_SIDE_RENDERING">
</template>
<!--/$-->
<script>
(function () {
var btn = document.querySelector('button[aria-label="Toggle theme"]');
var shell = document.querySelector('.app-shell');
if (!btn || window.__themeToggleInjected) return;
window.__themeToggleInjected = true;
btn.addEventListener('click', function () {
document.documentElement.classList.toggle('dark-mode');
if (shell) shell.classList.toggle('dark-mode');
});
})();
</script>
</body>
</html>
+14
View File
@@ -2954,5 +2954,19 @@ h1 {
<template data-dgst="BAILOUT_TO_CLIENT_SIDE_RENDERING">
</template>
<!--/$-->
<script>
(function () {
var btn = document.querySelector('button[aria-label="Toggle theme"]');
var shell = document.querySelector('.app-shell');
if (!btn || window.__themeToggleInjected) return;
window.__themeToggleInjected = true;
btn.addEventListener('click', function () {
document.documentElement.classList.toggle('dark-mode');
if (shell) shell.classList.toggle('dark-mode');
});
})();
</script>
</body>
</html>
+26
View File
@@ -7,6 +7,31 @@ import { join, dirname, basename } from 'node:path';
const root = process.argv[2];
const dest = process.argv[3];
// --- inject a minimal theme toggle (extraction strips all <script> tags, so the
// ref pages would otherwise have no working dark-mode switch) ---
const THEME_TOGGLE = `
<script>
(function () {
var btn = document.querySelector('button[aria-label="Toggle theme"]');
var shell = document.querySelector('.app-shell');
if (!btn || window.__themeToggleInjected) return;
window.__themeToggleInjected = true;
btn.addEventListener('click', function () {
document.documentElement.classList.toggle('dark-mode');
if (shell) shell.classList.toggle('dark-mode');
});
})();
</script>
`;
function injectThemeToggle(html) {
if (html.includes('__themeToggleInjected')) return html;
const tag = '</body>';
if (html.includes(tag)) return html.replace(tag, THEME_TOGGLE + '\n' + tag);
if (html.includes('</html>')) return html.replace('</html>', THEME_TOGGLE + '\n</html>');
return html + '\n' + THEME_TOGGLE;
}
// --- CSS: find the compiled chunk and pretty-print it ---
const cssChunks = join(root, '..', '..', 'static', 'chunks');
const cssFile = readdirSync(cssChunks)
@@ -110,6 +135,7 @@ for (const [src, out] of pages) {
);
html = fmtHtml(html);
html = injectThemeToggle(html);
const file = join(dest, out);
mkdirSync(dirname(file), { recursive: true });