Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Initial Separation of projects within docs #346

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 6 additions & 9 deletions config/navbar.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ const navbar: Omit<Navbar, "style" | "hideOnScroll"> = {
},
items: [
{
type: "dropdown",
label: "Paper",
to: "/paper",
label: "Paper",
position: "left",
activeBaseRegex: "\\/paper.*",
items: [
modules: [
{
label: "Administration",
to: "/paper/admin",
Expand All @@ -35,12 +34,11 @@ const navbar: Omit<Navbar, "style" | "hideOnScroll"> = {
],
},
{
type: "dropdown",
label: "Folia",
to: "/folia",
label: "Folia",
position: "left",
activeBaseRegex: "(\\/folia)(.+)?",
items: [
modules: [
{
label: "Administration",
to: "/folia/admin",
Expand All @@ -54,12 +52,11 @@ const navbar: Omit<Navbar, "style" | "hideOnScroll"> = {
],
},
{
type: "dropdown",
label: "Velocity",
to: "/velocity",
label: "Velocity",
position: "left",
activeBaseRegex: "\\/velocity.*",
items: [
modules: [
{
label: "Administration",
to: "/velocity/admin",
Expand Down
10 changes: 6 additions & 4 deletions config/sidebar.folia.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";

const folia: SidebarsConfig = {
primary: [
"README",
primary: ["README", "admin/README", "dev/README"],
administration: [
{
type: "category",
label: "Administration",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "admin/README",
Expand Down Expand Up @@ -35,10 +35,12 @@ const folia: SidebarsConfig = {
},
],
},
],
development: [
{
type: "category",
label: "Development",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "dev/README",
Expand Down
14 changes: 9 additions & 5 deletions config/sidebar.paper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";

const paper: SidebarsConfig = {
primary: [
"README",
primary: ["README", "admin/README", "dev/README", "contributing/README"],
administration: [
{
type: "category",
label: "Administration",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "admin/README",
Expand Down Expand Up @@ -80,10 +80,12 @@ const paper: SidebarsConfig = {
},
],
},
],
development: [
{
type: "category",
label: "Development",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "dev/README",
Expand Down Expand Up @@ -169,10 +171,12 @@ const paper: SidebarsConfig = {
},
],
},
],
contributing: [
{
type: "category",
label: "Contributing",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "contributing/README",
Expand Down
10 changes: 6 additions & 4 deletions config/sidebar.velocity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";

const velocity: SidebarsConfig = {
primary: [
"README",
primary: ["README", "admin/README", "dev/README"],
administration: [
{
type: "category",
label: "Administration",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "admin/README",
Expand Down Expand Up @@ -55,10 +55,12 @@ const velocity: SidebarsConfig = {
},
],
},
],
development: [
{
type: "category",
label: "Development",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "dev/README",
Expand Down
42 changes: 31 additions & 11 deletions src/components/Projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,29 @@ const projects: Project[] = [
description:
"High performance Minecraft server that aims to fix gameplay and mechanics inconsistencies.",
repo: "PaperMC/Paper",
link: "/paper",
modules: [
{ name: "Administration", link: "/paper/admin" },
{ name: "Development", link: "/paper/dev" },
{ name: "Contributing", link: "/paper/contributing" },
],
},
{
title: "Folia",
description: "A fork of Paper which adds regionized multithreading to the dedicated server.",
repo: "PaperMC/Folia",
link: "/folia",
modules: [
{ name: "Administration", link: "/folia/admin" },
{ name: "Development", link: "/folia/dev" },
],
},
{
title: "Velocity",
description: "The modern, next-generation Minecraft server proxy.",
repo: "PaperMC/Velocity",
link: "/velocity",
modules: [
{ name: "Administration", link: "/velocity/admin" },
{ name: "Development", link: "/velocity/dev" },
],
},
{
title: "Miscellaneous",
Expand All @@ -43,7 +53,7 @@ const projects: Project[] = [
function Project(project: Project) {
return (
<div className={"project"}>
<div className={"flex"}>
<div>
<Link
className={clsx("projectGitHub", project.eol && "archivedProjectTitle")}
to={`https://github.com/${project.repo}`}
Expand All @@ -54,12 +64,16 @@ function Project(project: Project) {
<p>{project.description}</p>
</div>
<div>
<Link
className={clsx("button button--primary", project.eol && "archivedProjectButton")}
to={project.link}
>
Go
</Link>
{project.modules?.map((module, index) => (
<Link key={index} className={"button button--primary"} to={module.link}>
{module.name}
</Link>
))}
{project.link && (
<Link className={"button button--primary"} to={project.link}>
Go
</Link>
)}
</div>
</div>
);
Expand All @@ -81,6 +95,12 @@ interface Project {
title: string;
description: string;
repo: string;
link: string;
link?: string;
modules?: Module[];
eol?: boolean;
}

interface Module {
name: string;
link: string;
}
12 changes: 11 additions & 1 deletion src/css/projects.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
border: 1px solid var(--ifm-color-emphasis-300);
padding: var(--ifm-global-spacing);
margin: 24px 0;
align-items: center;
justify-content: space-between;
}

.project p {
Expand All @@ -17,6 +17,16 @@
margin: 0;
}

.project div {
display: flex;
flex-direction: column;
justify-content: space-evenly;
}

.project a + a {
margin-top: 0.5em;
}

.projectGitHub {
color: var(--ifm-link-color);
font-size: 1rem;
Expand Down
104 changes: 104 additions & 0 deletions src/theme/Navbar/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, { type ReactNode } from "react";
import { useThemeConfig, ErrorCauseBoundary } from "@docusaurus/theme-common";
import { splitNavbarItems, useNavbarMobileSidebar } from "@docusaurus/theme-common/internal";
import NavbarItem, { type Props as NavbarItemConfig } from "@theme/NavbarItem";
import NavbarColorModeToggle from "@theme/Navbar/ColorModeToggle";
import SearchBar from "@theme/SearchBar";
import NavbarMobileSidebarToggle from "@theme/Navbar/MobileSidebar/Toggle";
import NavbarLogo from "@theme/Navbar/Logo";
import NavbarSearch from "@theme/Navbar/Search";

import styles from "./styles.module.css";

export type ExtendedNavbarItemConfig = NavbarItemConfig & {
activeBaseRegex?: string;
modules?: ExtendedNavbarItemConfig[];
label?: string;
to?: string;
};

function useNavbarItems() {
return useThemeConfig().navbar.items as ExtendedNavbarItemConfig[];
}

function NavbarItems({ items }: { items: ExtendedNavbarItemConfig[] }): JSX.Element {
return (
<>
{items.map((item, i) => (
<ErrorCauseBoundary
key={i}
onError={(error) =>
new Error(
`A theme navbar item failed to render.
Please double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config:
${JSON.stringify(item, null, 2)}`,
{ cause: error }
)
}
>
<NavbarItem {...item} />
</ErrorCauseBoundary>
))}
</>
);
}

function NavbarContentLayout({ left, right }: { left: ReactNode; right: ReactNode }) {
return (
<div className="navbar__inner">
<div className="navbar__items">{left}</div>
<div className="navbar__items navbar__items--right">{right}</div>
</div>
);
}

export default function NavbarContent(): JSX.Element {
const mobileSidebar = useNavbarMobileSidebar();

const items = useNavbarItems();
let [leftItems, rightItems] = splitNavbarItems(items);

// What we are doing here is going through each of the root level NavbarItems,
// and checking if the activeBaseRegex matches the current location. If it does
// we set the leftItems to the modules of that NavbarItem. This does not happen
// if that project does not have submodules.
if (typeof document !== "undefined") {
for (let item of items) {
if (
item.activeBaseRegex &&
item.modules &&
new RegExp(item.activeBaseRegex).test(document.location.pathname)
) {
leftItems = item.modules;
}
}
}

const searchBarItem = items.find((item) => item.type === "search");

return (
<NavbarContentLayout
left={
// TODO stop hardcoding items?
<>
{!mobileSidebar.disabled && <NavbarMobileSidebarToggle />}
<NavbarLogo />
<NavbarItems items={leftItems} />
</>
}
right={
// TODO stop hardcoding items?
// Ask the user to add the respective navbar items => more flexible
<>
<NavbarItems items={rightItems} />
<NavbarColorModeToggle className={styles.colorModeToggle} />
{!searchBarItem && (
<NavbarSearch>
<SearchBar />
</NavbarSearch>
)}
</>
}
/>
);
}
8 changes: 8 additions & 0 deletions src/theme/Navbar/Content/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Hide color mode toggle in small viewports
*/
@media (max-width: 996px) {
.colorModeToggle {
display: none;
}
}
Loading