Skip to content

Commit

Permalink
feat(plugin-docs): docs sidebar item link: support "autoAddBaseUrl" a…
Browse files Browse the repository at this point in the history
…ttribute (#7949)
  • Loading branch information
slorber committed Sep 1, 2022
1 parent 7d25a02 commit 8447a29
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Expand Up @@ -44,6 +44,7 @@ export type SidebarItemLink = SidebarItemBase & {
type: 'link';
href: string;
label: string;
autoAddBaseUrl?: boolean;
};

export type SidebarItemAutogenerated = SidebarItemBase & {
Expand Down
Expand Up @@ -59,6 +59,7 @@ const sidebarItemHtmlSchema = sidebarItemBaseSchema.append<SidebarItemHtml>({
const sidebarItemLinkSchema = sidebarItemBaseSchema.append<SidebarItemLink>({
type: 'link',
href: URISchema.required(),
autoAddBaseUrl: Joi.boolean(),
label: Joi.string()
.required()
.messages({'any.unknown': '"label" must be a string'}),
Expand Down
Expand Up @@ -24,7 +24,7 @@ export default function DocSidebarItemLink({
index,
...props
}: Props): JSX.Element {
const {href, label, className} = item;
const {href, label, className, autoAddBaseUrl} = item;
const isActive = isActiveSidebarItem(item, activePath);
const isInternalLink = isInternalUrl(href);
return (
Expand All @@ -44,6 +44,7 @@ export default function DocSidebarItemLink({
'menu__link--active': isActive,
},
)}
autoAddBaseUrl={autoAddBaseUrl}
aria-current={isActive ? 'page' : undefined}
to={href}
{...(isInternalLink && {
Expand Down
23 changes: 20 additions & 3 deletions website/_dogfooding/docs-tests-sidebars.js
Expand Up @@ -71,10 +71,27 @@ const sidebars = {
],
},
{
type: 'link',
label: 'External link',
href: 'https://github.com/facebook/docusaurus',
type: 'category',
label: 'Link tests',
className: 'red',
items: [
{
type: 'link',
label: 'External link absolute',
href: 'https://github.com/facebook/docusaurus',
},
{
type: 'link',
label: 'pathname:/// link',
href: 'pathname:///some/local/path',
},
{
type: 'link',
label: 'pathname:/// link (no baseUrl)',
href: 'pathname:///some/local/path',
autoAddBaseUrl: false,
},
],
},
{
type: 'category',
Expand Down

0 comments on commit 8447a29

Please sign in to comment.