Skip to content

feat: Initial Separation of projects within docs #346

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

Closed
wants to merge 7 commits into from
Closed
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
@@ -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",
@@ -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",
@@ -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",
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",
@@ -35,10 +35,12 @@ const folia: SidebarsConfig = {
},
],
},
],
development: [
{
type: "category",
label: "Development",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "dev/README",
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",
@@ -80,10 +80,12 @@ const paper: SidebarsConfig = {
},
],
},
],
development: [
{
type: "category",
label: "Development",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "dev/README",
@@ -169,10 +171,12 @@ const paper: SidebarsConfig = {
},
],
},
],
contributing: [
{
type: "category",
label: "Contributing",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "contributing/README",
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",
@@ -55,10 +55,12 @@ const velocity: SidebarsConfig = {
},
],
},
],
development: [
{
type: "category",
label: "Development",
collapsed: true,
collapsible: false,
link: {
type: "doc",
id: "dev/README",
42 changes: 31 additions & 11 deletions src/components/Projects.tsx
Original file line number Diff line number Diff line change
@@ -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",
@@ -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}`}
@@ -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>
);
@@ -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
@@ -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 {
@@ -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;
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;
}
}
61 changes: 61 additions & 0 deletions src/theme/Navbar/Logo/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from "react";
import Logo from "@theme/Logo";
import { useThemeConfig } from "@docusaurus/theme-common";
import ThemedImage from "@theme/ThemedImage";
import Link from "@docusaurus/Link";
import clsx from "clsx";
import "./styles.css";

interface IconInfo {
light: string;
dark: string;
}

interface Icons {
[key: string]: IconInfo;
}

const ICONS: Icons = {
paper: {
light: "/img/platform-icons/paper_light.svg",
dark: "/img/platform-icons/paper_dark.svg",
},
folia: {
light: "/img/platform-icons/folia_light.svg",
dark: "/img/platform-icons/folia_dark.svg",
},
velocity: {
light: "/img/platform-icons/velocity_light.svg",
dark: "/img/platform-icons/velocity_dark.svg",
},
};

const renderIcon = (label: string, icon: IconInfo) => (
<Link to={"/"} className={"project-icon"}>
<ThemedImage sources={icon} className={clsx("navbar__logo navbar__brand", "project-icon")} />
</Link>
);

export default function NavbarLogo(): JSX.Element {
if (typeof document !== "undefined") {
for (let item of useThemeConfig().navbar.items) {
if (item.activeBaseRegex && new RegExp(item.activeBaseRegex).test(location.pathname)) {
switch (item.label) {
case "Paper":
return renderIcon(item.label, ICONS.paper);
case "Folia":
return renderIcon(item.label, ICONS.folia);
case "Velocity":
return renderIcon(item.label, ICONS.velocity);
}
}
}
}
return (
<Logo
className="navbar__brand"
imageClassName="navbar__logo"
titleClassName="navbar__title text--truncate"
/>
);
}
4 changes: 4 additions & 0 deletions src/theme/Navbar/Logo/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.project-icon {
height: 40px;
width: 40px;
}
1 change: 1 addition & 0 deletions static/img/platform-icons/folia_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/img/platform-icons/folia_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/img/platform-icons/paper_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/img/platform-icons/paper_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/img/platform-icons/velocity_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/img/platform-icons/velocity_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.