Skip to content

Commit

Permalink
fix(docs): not found page (#75)
Browse files Browse the repository at this point in the history
Fixes styling and page components on the docs "Not Found" page
  • Loading branch information
lazarv authored Nov 9, 2024
1 parent 63ba3e1 commit 9f3b6b9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/src/pages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ export function getPages(pathname, lang) {
}),
}));
}

export function hasCategory(category) {
return categories?.find((c) => c.toLowerCase() === category?.toLowerCase());
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { defaultLanguage } from "../../../../const.mjs";
import { hasCategory } from "../../../../pages.mjs";

export default function Breadcrumb({ lang, category }) {
if (!hasCategory(category)) {
return null;
}

return (
<a
data-no-content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { getPages } from "../../../../pages.mjs";

export default function Contents({ lang, category }) {
const pathname = usePathname();
const { frontmatter } = getPages(pathname, lang)
.find(({ category: c }) => c.toLowerCase() === category.toLowerCase())
?.pages.find(({ langHref }) => langHref === pathname);
const { frontmatter } =
getPages(pathname, lang)
.find(({ category: c }) => c.toLowerCase() === category.toLowerCase())
?.pages.find(({ langHref }) => langHref === pathname) ?? {};

if (frontmatter?.contents === false) return null;
if (!frontmatter || frontmatter?.contents === false) return null;

return (
<Sidebar id="contents" menu="On this page" right>
Expand Down
8 changes: 6 additions & 2 deletions docs/src/pages/@sidebar/[[lang]]/(sidebar).[...slug].page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import { usePathname } from "@lazarv/react-server";

import Sidebar from "../../../components/Sidebar.jsx";
import { defaultLanguage } from "../../../const.mjs";
import { categories } from "../../../pages.mjs";
import { hasCategory, categories } from "../../../pages.mjs";

const pages = Array.from(
Object.entries(
import.meta.glob("../../../**/\\(pages\\)/**/*.{md,mdx}", { eager: true })
)
);

export default function PageSidebar({ lang }) {
export default function PageSidebar({ lang, slug: [category] }) {
const pathname = usePathname();

if (!hasCategory(category)) {
return null;
}

return (
<Sidebar id="sidebar" menu="Menu">
{Array.from(
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/en/(404).[[...slug]].page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function NotFound() {

<NotFound />

<div className="flex flex-col gap-4 h-full justify-center items-center text-center">
<div className="flex flex-col gap-4 w-full h-full justify-center items-center text-center">
# Not Found

Sorry, this page was not found.
Expand Down

0 comments on commit 9f3b6b9

Please sign in to comment.