Skip to content

Commit 19e50f7

Browse files
committed
Highlight current page in sidebar nav, normalize code font size
Inject a small script via the SEO plugin that marks the active sidebar link with a "current" class (TypeDoc doesn't do this natively for document pages). Uses a MutationObserver since the sidebar is populated asynchronously. Pathname comparison strips .html extensions to support clean-URL servers. Also bumps code/pre font-size from 0.85em to 1em so code snippets match the surrounding body text size.
1 parent 693e1bc commit 19e50f7

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

docs/mcp-theme.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ body {
174174
code,
175175
pre {
176176
font-family: var(--font-family-code);
177-
font-size: 0.85em;
177+
font-size: 1em;
178178
}
179179

180180
.tsd-typography pre {
@@ -185,5 +185,5 @@ pre {
185185
/* Inline code */
186186
.tsd-typography code:not(pre code) {
187187
padding: 0.15em 0.35em;
188-
font-size: 0.875em;
188+
font-size: 1em;
189189
}

scripts/typedoc-plugin-seo.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ export function load(app) {
189189
"</head>",
190190
headInjections + "\n</head>",
191191
);
192+
193+
// Inject script to mark the current sidebar nav link with a "current" class.
194+
// TypeDoc does not natively add this class for document pages.
195+
// The sidebar is populated asynchronously from compressed navigation data,
196+
// so we use a MutationObserver to detect when links appear.
197+
// Pathname comparison strips trailing slashes and .html extensions to handle
198+
// servers with clean-URL mode (e.g. `serve` drops .html).
199+
const currentNavScript = `<script>(function(){function norm(s){return s.replace(/\\/$/,"").replace(/\\.html$/,"");}function mark(){var p=norm(location.pathname);var links=document.querySelectorAll(".site-menu .tsd-navigation a[href]");for(var i=0;i<links.length;i++){var h=norm(new URL(links[i].href,location.href).pathname);if(h===p){links[i].classList.add("current");return true;}}return false;}function init(){if(!mark()){var c=document.getElementById("tsd-nav-container");if(c){new MutationObserver(function(m,o){if(mark())o.disconnect();}).observe(c,{childList:true,subtree:true});}}}if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",init);}else{init();}})();</script>`;
200+
page.contents = page.contents.replace(
201+
"</body>",
202+
currentNavScript + "\n</body>",
203+
);
192204
});
193205

194206
// --- Post-render: copy favicons + rename document slugs ---

0 commit comments

Comments
 (0)