Skip to content
Open
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
14 changes: 8 additions & 6 deletions packages/gitbook/src/components/Header/HeaderLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import assertNever from 'assert-never';
import type React from 'react';

import { resolveContentRef } from '@/lib/references';
import { getLocalizedTitle } from '@/lib/sites';
import { tcls } from '@/lib/tailwind';

import {
SiteAuthLoginButton,
SiteAuthLoginDropdownMenuItem,
Expand All @@ -35,20 +35,21 @@ export async function HeaderLink(props: {
const target = link.to ? await resolveContentRef(link.to, context) : null;
const headerPreset = customization.header.preset;
const linkStyle = link.style ?? 'link';
const title = getLocalizedTitle(link, context.locale);

if (link.links && link.links.length > 0) {
return (
<DropdownMenu
className={`shrink ${customization.styling.search === 'prominent' ? 'right-0 left-auto' : null}`}
button={
!target || !link.to ? (
<HeaderItemDropdown headerPreset={headerPreset} title={link.title} />
<HeaderItemDropdown headerPreset={headerPreset} title={title} />
) : (
<HeaderLinkNavItem
linkTarget={link.to}
linkStyle={linkStyle}
headerPreset={headerPreset}
title={link.title}
title={title}
isDropdown
href={target?.href}
isSiteAuthLoginHref={isSiteAuthLoginHref(context.linker, target.href)}
Expand All @@ -73,7 +74,7 @@ export async function HeaderLink(props: {
linkTarget={link.to}
linkStyle={linkStyle}
headerPreset={headerPreset}
title={link.title}
title={title}
isDropdown={false}
href={target?.href}
isSiteAuthLoginHref={target ? isSiteAuthLoginHref(context.linker, target.href) : false}
Expand Down Expand Up @@ -235,6 +236,7 @@ async function SubHeaderLink(props: {
return null;
}

const title = getLocalizedTitle(link, context.locale);
const sharedProps = {
href: target.href,
insights: {
Expand All @@ -247,8 +249,8 @@ async function SubHeaderLink(props: {
};

return isSiteAuthLoginHref(context.linker, target.href) ? (
<SiteAuthLoginDropdownMenuItem {...sharedProps}>{link.title}</SiteAuthLoginDropdownMenuItem>
<SiteAuthLoginDropdownMenuItem {...sharedProps}>{title}</SiteAuthLoginDropdownMenuItem>
) : (
<DropdownMenuItem {...sharedProps}>{link.title}</DropdownMenuItem>
<DropdownMenuItem {...sharedProps}>{title}</DropdownMenuItem>
);
}
8 changes: 5 additions & 3 deletions packages/gitbook/src/components/Header/HeaderLinkMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Icon } from '@gitbook/icons';
import type React from 'react';

import { resolveContentRef } from '@/lib/references';
import { getLocalizedTitle } from '@/lib/sites';
import { tcls } from '@/lib/tailwind';

import { SocialAccountLink } from '../Footer/SocialAccounts';
Expand Down Expand Up @@ -85,6 +86,7 @@ async function MoreMenuLink(props: {
}) {
const { context, link } = props;

const title = getLocalizedTitle(link, context.locale);
const target = link.to ? await resolveContentRef(link.to, context) : null;
const sharedProps = {
href: target?.href,
Expand All @@ -100,16 +102,16 @@ async function MoreMenuLink(props: {
};

return 'links' in link && link.links.length > 0 ? (
<DropdownSubMenu label={link.title}>
<DropdownSubMenu label={title}>
{link.links.map((subLink, index) => {
return <MoreMenuLink key={index} {...props} link={subLink} />;
})}
</DropdownSubMenu>
) : isSiteAuthLoginHref(context.linker, target?.href) && sharedProps.href ? (
<SiteAuthLoginDropdownMenuItem {...sharedProps} href={sharedProps.href}>
{link.title}
{title}
</SiteAuthLoginDropdownMenuItem>
) : (
<DropdownMenuItem {...sharedProps}>{link.title}</DropdownMenuItem>
<DropdownMenuItem {...sharedProps}>{title}</DropdownMenuItem>
);
}
Loading