Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions examples/pokeapi-docs/content/docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"logo": "/logo.svg",
"favicon": "/favicon.svg",
"colors": { "primary": "#dc2626" },
"navbarLinks": [
{ "name": "pokeapi.co", "href": "https://pokeapi.co" },
{ "name": "GitHub", "href": "https://github.com/PokeAPI/pokeapi" }
],
"navbarLinks": [],
"anchors": [
{ "name": "PokéAPI", "href": "https://pokeapi.co", "icon": "globe" },
{ "name": "GitHub", "href": "https://github.com/PokeAPI/pokeapi", "icon": "github" }
Expand Down
39 changes: 19 additions & 20 deletions packages/framework/src/secondary-top-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,30 @@ function tabClass(active: boolean) {
return `fw-topnav-tab${active ? ' fw-topnav-tab--active' : ''}`;
}

/** Anchors and navbarLinks can point at the same URL; render once (anchors win). */
function mergeTopBarLinks(
anchors: NonNullable<DocsConfig['anchors']>,
navlinks: NonNullable<DocsConfig['navbarLinks']>,
) {
const seen = new Set<string>();
const merged: Array<{ name: string; href: string }> = [];

for (const link of [...anchors, ...navlinks]) {
if (seen.has(link.href)) continue;
seen.add(link.href);
merged.push(link);
}

return merged;
}

/**
* Unified secondary header row: doc tabs, anchors, and navbar links share the
* same underline-tab styling and active state logic.
*/
export function SecondaryTopNav({ config, activeTab, pathname, apiBase }: SecondaryTopNavProps) {
const tabs = docTabs(config);
const anchors = config.anchors ?? [];
const navlinks = config.navbarLinks ?? [];
const extraLinks = mergeTopBarLinks(config.anchors ?? [], config.navbarLinks ?? []);

const onBlog = pathname.startsWith('/blog');
const onChangelog = pathname.startsWith('/changelog');
Expand All @@ -56,24 +72,7 @@ export function SecondaryTopNav({ config, activeTab, pathname, apiBase }: Second
);
})}

{anchors.map((a) => {
const external = a.href.startsWith('http');
const isActive = isInternalNavActive(pathname, a.href);

return (
<a
key={a.href}
href={a.href}
className={tabClass(isActive)}
aria-current={isActive ? 'page' : undefined}
{...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {})}
>
{a.name}
</a>
);
})}

{navlinks.map((l) => {
{extraLinks.map((l) => {
const external = l.href.startsWith('http');
const isActive = isInternalNavActive(pathname, l.href);

Expand Down
Loading