Skip to content

Commit

Permalink
Breadcrumbs on all pages, category indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
e-im committed Apr 8, 2022
1 parent 9e18268 commit 72ac1bc
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
27 changes: 27 additions & 0 deletions config/sidebars.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "How-to Guides",
link: {
type: "generated-index"
},
items: [
"paper/how-to/per-world-configuration",
"paper/how-to/anti-xray",
Expand All @@ -42,6 +45,9 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Reference",
link: {
type: "generated-index",
},
items: [
"paper/reference/paper-global-configuration",
"paper/reference/paper-per-world-configuration",
Expand Down Expand Up @@ -74,6 +80,9 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "How-to Guides",
link: {
type: "generated-index"
},
items: [
"velocity/how-to/security",
"velocity/how-to/tuning",
Expand All @@ -83,6 +92,9 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Reference",
link: {
type: "generated-index",
},
items: [
"velocity/reference/configuration",
"velocity/reference/commands",
Expand All @@ -103,6 +115,9 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Getting Started",
link: {
type: "generated-index"
},
items: [
"velocity/developers/getting-started/creating-your-first-plugin",
"velocity/developers/getting-started/api-basics",
Expand All @@ -112,6 +127,9 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "How-to Guides",
link: {
type: "generated-index"
},
items: [
"velocity/developers/how-to/dependencies",
"velocity/developers/how-to/porting-from-velocity-1",
Expand All @@ -120,6 +138,9 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "API",
link: {
type: "generated-index"
},
items: [
"velocity/developers/api/event",
"velocity/developers/api/command",
Expand All @@ -142,11 +163,17 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Common",
link: {
type: "generated-index"
},
items: ["common/java-install"],
},
{
type: "category",
label: "PaperMC",
link: {
type: "generated-index"
},
items: ["papermc/downloads-api", "papermc/assets", "papermc/contact"],
},
],
Expand Down
103 changes: 103 additions & 0 deletions src/theme/DocBreadcrumbs/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import React, {type ReactNode} from 'react';
import {
ThemeClassNames,
useSidebarBreadcrumbs,
useHomePageRoute,
} from '@docusaurus/theme-common';
import styles from './styles.module.css';
import clsx from 'clsx';
import Link from '@docusaurus/Link';
import useBaseUrl from '@docusaurus/useBaseUrl';

// TODO move to design system folder
function BreadcrumbsItemLink({
children,
href,
}: {
children: ReactNode;
href?: string;
}): JSX.Element {
const className = 'breadcrumbs__link';
return href ? (
<Link className={className} href={href} itemProp="item">
<span itemProp="name">{children}</span>
</Link>
) : (
<span className={className} itemProp="item name">
{children}
</span>
);
}

// TODO move to design system folder
function BreadcrumbsItem({
children,
active,
index,
}: {
children: ReactNode;
active?: boolean;
index: number;
}): JSX.Element {
return (
<li
itemScope
itemProp="itemListElement"
itemType="https://schema.org/ListItem"
className={clsx('breadcrumbs__item', {
'breadcrumbs__item--active': active,
})}>
{children}
<meta itemProp="position" content={String(index + 1)} />
</li>
);
}

function HomeBreadcrumbItem() {
const homeHref = useBaseUrl('/');
return (
<li className="breadcrumbs__item">
<Link
className={clsx('breadcrumbs__link', styles.breadcrumbsItemLink)}
href={homeHref}>
🏠
</Link>
</li>
);
}

export default function DocBreadcrumbs(): JSX.Element | null {
const breadcrumbs = useSidebarBreadcrumbs();
const homePageRoute = useHomePageRoute();

if (!breadcrumbs) {
return null;
}

return (
<nav
className={clsx(
ThemeClassNames.docs.docBreadcrumbs,
styles.breadcrumbsContainer,
)}
aria-label="breadcrumbs">
<ul
className="breadcrumbs"
itemScope
itemType="https://schema.org/BreadcrumbList">
{homePageRoute && <HomeBreadcrumbItem />}
{breadcrumbs.map((item, idx) => (
<BreadcrumbsItem
key={idx}
active={idx === breadcrumbs.length - 1}
index={idx}>
<BreadcrumbsItemLink
href={item.href}> {/* papermc - breadcrumb links on all pages, even current */}
{item.label}
</BreadcrumbsItemLink>
</BreadcrumbsItem>
))}
</ul>
</nav>
);
}
11 changes: 11 additions & 0 deletions src/theme/DocBreadcrumbs/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

.breadcrumbsContainer {
--ifm-breadcrumb-size-multiplier: 0.8;
margin-bottom: 0.8rem;
}

0 comments on commit 72ac1bc

Please sign in to comment.