Skip to content

Commit

Permalink
Breadcrumb links to all pages, category indexes (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
e-im authored Apr 8, 2022
1 parent 66df253 commit b070580
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 6 deletions.
6 changes: 3 additions & 3 deletions config/navbar.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Navbar} from "@docusaurus/theme-common";
import { Navbar } from "@docusaurus/theme-common";

const navbar: Omit<Navbar, "style"> = { // don't specify style here, we want it to be dynamic
// don't specify style or hideOnScroll here, we want it to be dynamic
const navbar: Omit<Navbar, "style" | "hideOnScroll"> = {
title: "PaperMC Docs",
hideOnScroll: true,
logo: {
src: "img/logo.svg",
alt: "PaperMC Logo",
Expand Down
55 changes: 52 additions & 3 deletions config/sidebars.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@ import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";
const sidebars: SidebarsConfig = {
docs: [
{
type: "link",
label: "Support Discord",
href: "https://discord.gg/papermc",
type: "category",
label: "Getting Help",
items: [
{
type: "link",
label: "Discord",
href: "https://discord.gg/papermc",
},
{
type: "link",
label: "Forums",
href: "https://forums.papermc.io",
},
],
},
"README",
{
Expand All @@ -32,6 +43,10 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "How-to Guides",
link: {
type: "generated-index",
slug: "/category/paper/how-to-guides",
},
items: [
"paper/how-to/per-world-configuration",
"paper/how-to/anti-xray",
Expand All @@ -42,6 +57,10 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Reference",
link: {
type: "generated-index",
slug: "/category/paper/reference",
},
items: [
"paper/reference/paper-global-configuration",
"paper/reference/paper-per-world-configuration",
Expand Down Expand Up @@ -74,6 +93,10 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "How-to Guides",
link: {
type: "generated-index",
slug: "/category/velocity/how-to-guides",
},
items: [
"velocity/how-to/security",
"velocity/how-to/tuning",
Expand All @@ -83,6 +106,10 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Reference",
link: {
type: "generated-index",
slug: "/category/velocity/reference",
},
items: [
"velocity/reference/configuration",
"velocity/reference/commands",
Expand All @@ -103,6 +130,10 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Getting Started",
link: {
type: "generated-index",
slug: "/category/velocity/developers/getting-started",
},
items: [
"velocity/developers/getting-started/creating-your-first-plugin",
"velocity/developers/getting-started/api-basics",
Expand All @@ -112,6 +143,10 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "How-to Guides",
link: {
type: "generated-index",
slug: "/category/velocity/developers/how-to-guides",
},
items: [
"velocity/developers/how-to/dependencies",
"velocity/developers/how-to/porting-from-velocity-1",
Expand All @@ -120,6 +155,10 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "API",
link: {
type: "generated-index",
slug: "/category/velocity/developers/api",
},
items: [
"velocity/developers/api/event",
"velocity/developers/api/command",
Expand All @@ -142,11 +181,21 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Common",
link: {
type: "generated-index",
slug: "/category/common",
description: "Documentation relevant to all PaperMC projects.",
},
items: ["common/java-install"],
},
{
type: "category",
label: "PaperMC",
link: {
type: "generated-index",
slug: "/category/papermc",
description: "Information about the PaperMC Organization.",
},
items: ["papermc/downloads-api", "papermc/assets", "papermc/contact"],
},
],
Expand Down
1 change: 1 addition & 0 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const config: Config = {
projectName: "docs",
trailingSlash: false,
noIndex: isPreview,
baseUrlIssueBanner: false,

webpack: {
jsLoader: (isServer) => ({
Expand Down
87 changes: 87 additions & 0 deletions src/theme/DocBreadcrumbs/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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}> {item.label}</BreadcrumbsItemLink>
</BreadcrumbsItem>
))}
</ul>
</nav>
);
}
4 changes: 4 additions & 0 deletions src/theme/DocBreadcrumbs/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.breadcrumbsContainer {
--ifm-breadcrumb-size-multiplier: 0.8;
margin-bottom: 0.8rem;
}

0 comments on commit b070580

Please sign in to comment.