-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from rocky-linux/feature/resources
Finish Resources Pages
- Loading branch information
Showing
9 changed files
with
240 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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}> | ||
|
@@ -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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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}> | ||
|
@@ -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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.