Skip to content

Commit a14d3f9

Browse files
committed
Ensure navbar tools also pipeline
1 parent 5b8c134 commit a14d3f9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/project/types/website/website-navigation-md.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const kNavNextId = "quarto-int-next";
3535
const kNavPrevId = "quarto-int-prev";
3636
const kSidebarIdPrefix = "quarto-int-sidebar:";
3737
const kNavbarIdPrefix = "quarto-int-navbar:";
38+
const kToolsPrefix = "quarto-navbar-tools:";
3839

3940
export interface NavigationPipelineContext {
4041
source: string;
@@ -284,6 +285,16 @@ const navbarContentsHandler = (context: NavigationPipelineContext) => {
284285
entries.forEach((entry) => {
285286
addEntry(entry);
286287
});
288+
289+
const tools = context.navigation.navbar.tools;
290+
if (tools) {
291+
tools.forEach((tool) => {
292+
if (tool.href) {
293+
markdown[`${kToolsPrefix}${tool.href.trim()}`] = tool.href;
294+
}
295+
});
296+
}
297+
287298
return { inlines: markdown };
288299
}
289300
},
@@ -306,6 +317,7 @@ const navbarContentsHandler = (context: NavigationPipelineContext) => {
306317
}
307318
}
308319

320+
// Any rendered hrefs for nav items
309321
const textParent = link.parentElement;
310322
if (textParent) {
311323
const href = textParent.getAttribute("href");
@@ -318,6 +330,23 @@ const navbarContentsHandler = (context: NavigationPipelineContext) => {
318330
}
319331
}
320332
});
333+
334+
// Any tools
335+
[".navbar .quarto-navbar-tools .quarto-navigation-tool"].forEach(
336+
(sel) => {
337+
const toolNodes = doc.querySelectorAll(sel);
338+
for (let i = 0; i < toolNodes.length; i++) {
339+
const toolEl = toolNodes[i] as Element;
340+
const href = toolEl.getAttribute("href");
341+
if (href) {
342+
const renderedHref = rendered[`${kToolsPrefix}${href}`];
343+
if (renderedHref) {
344+
toolEl.setAttribute("href", renderedHref?.innerText);
345+
}
346+
}
347+
}
348+
},
349+
);
321350
},
322351
};
323352
};

0 commit comments

Comments
 (0)