mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
feat(plugin-docs): docs sidebar item link: support "autoAddBaseUrl" attribute (#7949)
This commit is contained in:
parent
53bb0307dd
commit
de526e1ab2
4 changed files with 24 additions and 4 deletions
|
@ -44,6 +44,7 @@ export type SidebarItemLink = SidebarItemBase & {
|
||||||
type: 'link';
|
type: 'link';
|
||||||
href: string;
|
href: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
autoAddBaseUrl?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SidebarItemAutogenerated = SidebarItemBase & {
|
export type SidebarItemAutogenerated = SidebarItemBase & {
|
||||||
|
|
|
@ -59,6 +59,7 @@ const sidebarItemHtmlSchema = sidebarItemBaseSchema.append<SidebarItemHtml>({
|
||||||
const sidebarItemLinkSchema = sidebarItemBaseSchema.append<SidebarItemLink>({
|
const sidebarItemLinkSchema = sidebarItemBaseSchema.append<SidebarItemLink>({
|
||||||
type: 'link',
|
type: 'link',
|
||||||
href: URISchema.required(),
|
href: URISchema.required(),
|
||||||
|
autoAddBaseUrl: Joi.boolean(),
|
||||||
label: Joi.string()
|
label: Joi.string()
|
||||||
.required()
|
.required()
|
||||||
.messages({'any.unknown': '"label" must be a string'}),
|
.messages({'any.unknown': '"label" must be a string'}),
|
||||||
|
|
|
@ -24,7 +24,7 @@ export default function DocSidebarItemLink({
|
||||||
index,
|
index,
|
||||||
...props
|
...props
|
||||||
}: Props): JSX.Element {
|
}: Props): JSX.Element {
|
||||||
const {href, label, className} = item;
|
const {href, label, className, autoAddBaseUrl} = item;
|
||||||
const isActive = isActiveSidebarItem(item, activePath);
|
const isActive = isActiveSidebarItem(item, activePath);
|
||||||
const isInternalLink = isInternalUrl(href);
|
const isInternalLink = isInternalUrl(href);
|
||||||
return (
|
return (
|
||||||
|
@ -44,6 +44,7 @@ export default function DocSidebarItemLink({
|
||||||
'menu__link--active': isActive,
|
'menu__link--active': isActive,
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
|
autoAddBaseUrl={autoAddBaseUrl}
|
||||||
aria-current={isActive ? 'page' : undefined}
|
aria-current={isActive ? 'page' : undefined}
|
||||||
to={href}
|
to={href}
|
||||||
{...(isInternalLink && {
|
{...(isInternalLink && {
|
||||||
|
|
|
@ -71,10 +71,27 @@ const sidebars = {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'link',
|
type: 'category',
|
||||||
label: 'External link',
|
label: 'Link tests',
|
||||||
href: 'https://github.com/facebook/docusaurus',
|
|
||||||
className: 'red',
|
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',
|
type: 'category',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue