Skip to content

Commit

Permalink
Merge pull request #11 from rocky-linux/feature/resources
Browse files Browse the repository at this point in the history
Finish Resources Pages
  • Loading branch information
FoggyMtnDrifter authored Mar 8, 2024
2 parents 23c903d + 3c2db06 commit ab71e78
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 46 deletions.
5 changes: 2 additions & 3 deletions app/[locale]/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ export default function Header() {
about: {
about: tNav("about.about"),
charter: tNav("about.charter"),
wiki: tNav("about.wiki"),
partners: tNav("about.partners"),
sponsors: tNav("about.sponsors"),
},
resources: {
faq: tNav("resources.faq"),
guidesAndManuals: tNav("resources.guidesAndManuals"),
docs: tNav("resources.docs"),
gpgKeyInfo: tNav("resources.gpgKeyInfo"),
wiki: tNav("resources.wiki"),
},
community: {
forums: tNav("community.forums"),
Expand Down
32 changes: 14 additions & 18 deletions app/[locale]/components/header/DesktopNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const DesktopNavigation = ({ translations: t }: DesktopNavigationProps) => {
title={t.about.charter}
href="/about/charter"
/>
<NavListItem
title={t.about.wiki}
href="https://wiki.rockylinux.org"
/>
<NavListItem
title={t.about.sponsors}
href="/about/sponsors"
Expand All @@ -43,42 +47,34 @@ const DesktopNavigation = ({ translations: t }: DesktopNavigationProps) => {
</NavList>
<NavList name={t.resourcesName}>
<NavListItem
title={t.resources.faq}
href="/resources/faq"
/>
<NavListItem
title={t.resources.guidesAndManuals}
href="/resources/guides-and-manuals"
title={t.resources.docs}
href="https://docs.rockylinux.org"
/>
<NavListItem
title={t.resources.gpgKeyInfo}
href="/resources/gpg-key-info"
/>
<NavListItem
title={t.resources.wiki}
href="/resources/wiki"
/>
</NavList>
<NavList name={t.communityName}>
<NavListItem
title={t.community.forums}
href="/community/forums"
href="https://forums.rockylinux.org"
/>
<NavListItem
title={t.community.mailing}
href="/community/mailing"
href="https://lists.resf.org/"
/>
<NavListItem
title={t.community.mattermost}
href="/community/mattermost"
href="https://chat.rockylinux.org/"
/>
<NavListItem
title={t.community.irc}
href="/community/irc"
href="https://wiki.rockylinux.org/irc/"
/>
<NavListItem
title={t.community.calendar}
href="/community/calendar"
href="https://calendar.google.com/calendar/u/0/[email protected]"
/>
</NavList>
<NavList name={t.supportName}>
Expand All @@ -88,21 +84,21 @@ const DesktopNavigation = ({ translations: t }: DesktopNavigationProps) => {
/>
<NavListItem
title={t.support.submitBug}
href="/support/submit-bug"
href="https://bugs.rockylinux.org"
/>
</NavList>
<NavList name={t.contributeName}>
<NavListItem
title={t.contribute.contribute}
href="/contribute/contribute"
href="https://wiki.rockylinux.org/contributing/"
/>
<NavListItem
title={t.contribute.shop}
href="/contribute/shop"
/>
<NavListItem
title={t.contribute.donate}
href="/contribute/donate"
href="https://rockylinux.z2systems.com/np/clients/rockylinux/donation.jsp"
/>
</NavList>
</NavigationMenuList>
Expand Down
32 changes: 14 additions & 18 deletions app/[locale]/components/header/MobileNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ const MobileNavigation = ({
title={t.about.charter}
href="/about/charter"
/>
<NavListItem
title={t.about.wiki}
href="https://wiki.rockylinux.org"
/>
<NavListItem
title={t.about.sponsors}
href="/about/sponsors"
Expand All @@ -82,42 +86,34 @@ const MobileNavigation = ({
</NavList>
<NavList name={t.resourcesName}>
<NavListItem
title={t.resources.faq}
href="/resources/faq"
/>
<NavListItem
title={t.resources.guidesAndManuals}
href="/resources/guides-and-manuals"
title={t.resources.docs}
href="https://docs.rockylinux.org"
/>
<NavListItem
title={t.resources.gpgKeyInfo}
href="/resources/gpg-key-info"
/>
<NavListItem
title={t.resources.wiki}
href="/resources/wiki"
/>
</NavList>
<NavList name={t.communityName}>
<NavListItem
title={t.community.forums}
href="/community/forums"
href="https://forums.rockylinux.org"
/>
<NavListItem
title={t.community.mailing}
href="/community/mailing"
href="https://lists.resf.org/"
/>
<NavListItem
title={t.community.mattermost}
href="/community/mattermost"
href="https://chat.rockylinux.org/"
/>
<NavListItem
title={t.community.irc}
href="/community/irc"
href="https://wiki.rockylinux.org/irc/"
/>
<NavListItem
title={t.community.calendar}
href="/community/calendar"
href="https://calendar.google.com/calendar/u/0/[email protected]"
/>
</NavList>
<NavList name={t.supportName}>
Expand All @@ -127,21 +123,21 @@ const MobileNavigation = ({
/>
<NavListItem
title={t.support.submitBug}
href="/support/submit-bug"
href="https://bugs.rockylinux.org"
/>
</NavList>
<NavList name={t.contributeName}>
<NavListItem
title={t.contribute.contribute}
href="/contribute/contribute"
href="https://wiki.rockylinux.org/contributing/"
/>
<NavListItem
title={t.contribute.shop}
href="/contribute/shop"
/>
<NavListItem
title={t.contribute.donate}
href="/contribute/donate"
href="https://rockylinux.z2systems.com/np/clients/rockylinux/donation.jsp"
/>
</NavList>
</Accordion>
Expand Down
5 changes: 2 additions & 3 deletions app/[locale]/components/header/NavigationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ export interface NavigationMenuItems {
about: {
about: string;
charter: string;
wiki: string;
sponsors: string;
partners: string;
};
resources: {
faq: string;
wiki: string;
guidesAndManuals: string;
docs: string;
gpgKeyInfo: string;
};
community: {
Expand Down
18 changes: 18 additions & 0 deletions app/[locale]/resources/[slug]/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useTranslations } from "next-intl";

export default function SlugNotFound() {
const t = useTranslations("global.notFound");

return (
<div className="py-24 sm:py-32">
<div className="mx-auto max-w-3xl text-base leading-7">
<h1 className="mt-2 text-3xl font-bold tracking-tight sm:text-4xl mb-12 text-center font-display">
{t("title")}
</h1>
<div className="prose dark:prose-invert prose-headings:font-display prose-a:text-primary prose-pre:bg-muted prose-pre:py-3 prose-pre:px-4 prose-pre:rounded prose-img:rounded-md max-w-none text-center">
{t("description")}
</div>
</div>
</div>
);
}
56 changes: 56 additions & 0 deletions app/[locale]/resources/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { checkIfSlugIsValid, getContentData } from "@/lib/resourcesPages";
import { notFound } from "next/navigation";

export type Params = {
slug: string;
};

export type Props = {
params: Params;
};

export type pageData = {
title: string;
description: string;
contentHtml: string;
};

export async function generateMetadata({ params }: Props) {
const slug = params.slug;

if (!(await checkIfSlugIsValid(slug))) {
return {
title: "Not Found",
};
}

const pageData: pageData = await getContentData(slug);

return {
title: `${pageData.title} - Rocky Linux`,
};
}

export default async function Page({ params }: Props) {
const slug = params.slug;

if (!(await checkIfSlugIsValid(slug))) {
notFound();
}

const pageData: pageData = await getContentData(slug);

return (
<div className="py-24 sm:py-32">
<div className="mx-auto max-w-3xl text-base leading-7">
<h1 className="text-3xl font-bold tracking-tight sm:text-4xl mb-12 text-center font-display">
{pageData.title}
</h1>
<div
className="prose dark:prose-invert prose-headings:font-display prose-a:text-primary prose-pre:bg-muted prose-pre:py-3 prose-pre:px-4 prose-pre:rounded prose-img:rounded-md max-w-none mb-12"
dangerouslySetInnerHTML={{ __html: pageData.contentHtml }}
/>
</div>
</div>
);
}
47 changes: 47 additions & 0 deletions lib/resourcesPages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import fs from "fs";
import path from "path";

import matter from "gray-matter";
import { processMarkdownAsHTML } from "@/utils/remarkUtils";

const contentDirectory = path.join(process.cwd(), "resources");

export async function checkIfSlugIsValid(slug: string) {
if (!slug || typeof slug !== "string") {
return false;
}

// Check that the slug does not contain any slashes to prevent directory traversal
if (slug.includes("/") || slug.includes("\\")) {
return false;
}

const fullPath = path.join(contentDirectory, `${slug}.md`);

try {
await fs.promises.access(fullPath);
return true;
} catch {
return false;
}
}

export async function getContentData(slug: string) {
const fullPath = path.join(contentDirectory, `${slug}.md`);

const fileContents = await fs.promises.readFile(fullPath, "utf8");

if (!fileContents) {
throw new Error(`Page with slug "${slug}" does not exist.`);
}

const matterResult = matter(fileContents);

const contentHtml = await processMarkdownAsHTML(matterResult.content);

return {
slug,
contentHtml,
...(matterResult.data as { title: string; description: string }),
};
}
7 changes: 3 additions & 4 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
"about": {
"about": "About Rocky Linux",
"charter": "Community Charter",
"wiki": "Project Wiki",
"sponsors": "Sponsors",
"partners": "Partners"
},
"resources": {
"faq": "Frequently Asked Questions",
"wiki": "Wiki",
"guidesAndManuals": "Guides & Manuals",
"docs": "Documentation",
"gpgKeyInfo": "GPG Key Info"
},
"community": {
Expand All @@ -41,7 +40,7 @@
"submitBug": "Submit Bug"
},
"contribute": {
"contribute": "Contribute",
"contribute": "Contributing Guide",
"shop": "Shop",
"donate": "Donate"
}
Expand Down
Loading

0 comments on commit ab71e78

Please sign in to comment.