clean up client install/configure and add sidebar cta

This commit is contained in:
miloschwartz
2026-02-12 16:43:19 -08:00
parent 39429997d5
commit 202e25b9f6
103 changed files with 736 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
#!/usr/bin/env node
/**
* One-off script: add PangolinCloudTocCta import and usage to every MDX file.
* Run from repo root: node scripts/add-toc-cta-snippet.js
*/
const fs = require("fs");
const path = require("path");
const BLOCK = `import PangolinCloudTocCta from "/snippets/pangolin-cloud-toc-cta.mdx";
<PangolinCloudTocCta />
`;
function findMdxFiles(dir, list = []) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const e of entries) {
const full = path.join(dir, e.name);
if (e.isDirectory()) findMdxFiles(full, list);
else if (e.name.endsWith(".mdx")) list.push(full);
}
return list;
}
function addSnippet(filePath) {
let content = fs.readFileSync(filePath, "utf8");
if (content.includes("pangolin-cloud-toc-cta.mdx")) return false; // already added
const close = content.indexOf("\n---", 3);
if (close === -1) return false;
const insertAt = close + 4; // after "\n---"
content = content.slice(0, insertAt) + BLOCK + content.slice(insertAt);
fs.writeFileSync(filePath, content);
return true;
}
const root = path.resolve(__dirname, "..");
const files = findMdxFiles(root).filter(
(f) => !f.includes("snippets" + path.sep)
);
let added = 0;
for (const f of files) {
if (addSnippet(f)) added++;
}
console.log(`Added snippet to ${added} of ${files.length} MDX files.`);

View File

@@ -0,0 +1,75 @@
/**
* Shows the Pangolin Cloud CTA in the table of contents on every page.
* Moves the PangolinCloudTocCta snippet (MDX Card) into the TOC when present.
* Re-runs on SPA navigation; avoids duplicating when DOM re-renders (e.g. theme toggle).
*/
(function () {
const MAX_ATTEMPTS = 30;
const RETRY_MS = 150;
const DEBOUNCE_MS = 100;
const CTA_MARKER = "data-pangolin-toc-cta";
function moveSnippetToToc() {
const toc = document.getElementById("table-of-contents");
const source = document.getElementById("pangolin-toc-cta");
if (!toc || !source) return false;
if (toc.querySelector("[" + CTA_MARKER + "]")) {
const duplicate = source.firstElementChild;
if (duplicate) source.removeChild(duplicate);
return true;
}
const card = source.firstElementChild;
if (!card) return false;
source.removeChild(card);
card.setAttribute(CTA_MARKER, "true");
toc.appendChild(card);
return true;
}
function tryRun() {
moveSnippetToToc();
}
let debounceTimer = null;
function scheduleRun() {
if (debounceTimer) clearTimeout(debounceTimer);
debounceTimer = setTimeout(function () {
debounceTimer = null;
tryRun();
}, DEBOUNCE_MS);
}
function run() {
let attempts = 0;
const id = setInterval(function () {
attempts++;
if (moveSnippetToToc()) {
clearInterval(id);
observeForNavigation();
return;
}
if (attempts >= MAX_ATTEMPTS) {
clearInterval(id);
observeForNavigation();
}
}, RETRY_MS);
}
function observeForNavigation() {
const observer = new MutationObserver(function () {
if (document.getElementById("pangolin-toc-cta")) {
scheduleRun();
}
});
observer.observe(document.body, { childList: true, subtree: true });
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", run);
} else {
run();
}
})();