From 07040140306f107599f3c5d9c6f459a0d9afa4f1 Mon Sep 17 00:00:00 2001 From: nickfrosty Date: Thu, 30 Nov 2023 15:53:13 -0500 Subject: [PATCH] feat: catchup --- src/pages/api/content/[[...slug]].ts | 12 +++-- src/pages/api/nav/[group].ts | 44 ---------------- src/pages/api/paths/[group].ts | 75 ---------------------------- src/utils/navItem.ts | 11 +++- 4 files changed, 18 insertions(+), 124 deletions(-) delete mode 100644 src/pages/api/nav/[group].ts delete mode 100644 src/pages/api/paths/[group].ts diff --git a/src/pages/api/content/[[...slug]].ts b/src/pages/api/content/[[...slug]].ts index 3b75ce7ff..fa026a2fe 100644 --- a/src/pages/api/content/[[...slug]].ts +++ b/src/pages/api/content/[[...slug]].ts @@ -13,6 +13,7 @@ import { allDeveloperResources, allSolanaDocs, allDeveloperWorkshops, + allSolanaRPCDocs, DocumentTypes, } from "contentlayer/generated"; import type { NextApiRequest, NextApiResponse } from "next"; @@ -32,8 +33,10 @@ export default function handler( // retrieve the correct group's records by its simple group name const records = ((group: SimpleRecordGroupName) => { switch (group) { - case "docs": + case "docs": { + if (slug[1] == "rpc") return allSolanaRPCDocs; return allSolanaDocs; + } case "guides": return allDeveloperGuides; case "resources": @@ -48,8 +51,11 @@ export default function handler( // define the formatted href value to search for // note: this effectively enforces that only href's that start with "/developers" are supported const href = `${ - slug[0].toLocaleLowerCase() == "docs" ? "" : "/developers" - }/${slug.join("/")}`; + slug[0].toLocaleLowerCase() == "docs" || + slug[0].toLocaleLowerCase() == "rpc" + ? "" + : "/developers" + }/${slug.join("/")}`.toLowerCase(); // create a flat listing of all the nav items in order to locate the next, current, and prev records const flatNavItems = generateFlatNavItemListing( diff --git a/src/pages/api/nav/[group].ts b/src/pages/api/nav/[group].ts deleted file mode 100644 index 7a115a26c..000000000 --- a/src/pages/api/nav/[group].ts +++ /dev/null @@ -1,44 +0,0 @@ -/** - * api route to generate the nav item listing for - * each supported content record `group` - */ - -import type { NextApiRequest, NextApiResponse } from "next"; -import { NavItem, SimpleRecordGroupName } from "@/types"; -import { generateNavItemListing } from "@/utils/navItem"; -import { - allDeveloperGuides, - allDeveloperResources, - allSolanaDocs, - allDeveloperWorkshops, -} from "contentlayer/generated"; - -export default function handler( - req: NextApiRequest, - res: NextApiResponse, -) { - // get the content record group - const group = req.query?.group?.toString() as SimpleRecordGroupName; - if (!group) return res.status(404).json({ notFound: true }); - - // retrieve the correct group's records by its simple group name - const records = ((group: SimpleRecordGroupName) => { - switch (group) { - case "docs": - return allSolanaDocs; - case "guides": - return allDeveloperGuides; - // case "resources": - // return allDeveloperResources; - case "workshops": - return allDeveloperWorkshops; - } - })(group); - - if (!records) return res.status(404).json({ notFound: true }); - - const navItems = generateNavItemListing(records); - - // finally, return the json formatted listing of NavItems - return res.status(200).json(navItems); -} diff --git a/src/pages/api/paths/[group].ts b/src/pages/api/paths/[group].ts deleted file mode 100644 index 769b4bc23..000000000 --- a/src/pages/api/paths/[group].ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * api route to generate a path listing for - * each supported content record `group` - */ - -import type { NextApiRequest, NextApiResponse } from "next"; -import { NavItem, SimpleRecordGroupName } from "@/types"; -import { computeNavItem, shouldIgnoreRecord } from "@/utils/navItem"; -import { - allDeveloperGuides, - allDeveloperResources, - allSolanaDocs, - allDeveloperWorkshops, -} from "contentlayer/generated"; - -export default function handler( - req: NextApiRequest, - res: NextApiResponse, -) { - // get the content record group - const group = req.query?.group?.toString() as SimpleRecordGroupName; - if (!group) return res.status(404).json({ notFound: true }); - - // retrieve the correct group's records by its simple group name - const records = ((group: SimpleRecordGroupName) => { - switch (group) { - case "docs": - return allSolanaDocs; - case "guides": - return allDeveloperGuides; - case "resources": - return allDeveloperResources; - case "workshops": - return allDeveloperWorkshops; - } - })(group); - - if (!records) return res.status(404).json({ notFound: true }); - - // init the listing response - const listing: Array = []; - - /** - * todo: assorted things - * - better support for external links - */ - - // compute the path data to return - records.map(record => { - if (shouldIgnoreRecord({ fileName: record._raw.sourceFileName })) return; - - // @ts-ignore - const navItem = computeNavItem(record); - - if (!navItem.href || !!record.isExternal) return; - - listing.push(navItem); - - // handle adding each of the alternative routes into the path listing - if (!!record?.altRoutes?.length) { - record.altRoutes.forEach(route => { - if (!!route?.trim()) { - listing.push( - Object.assign(navItem, { - href: route.trim(), - }), - ); - } - }); - } - }); - - // finally, return the json formatted listing - return res.status(200).json(listing); -} diff --git a/src/utils/navItem.ts b/src/utils/navItem.ts index 66d179540..4188a7050 100644 --- a/src/utils/navItem.ts +++ b/src/utils/navItem.ts @@ -24,7 +24,10 @@ export function generateNavItemListing( grouping[record._raw.sourceFileDir] = { items: [] } as unknown as NavItem; // process the index file as the root of the NavItem - if (record._raw.sourceFileName == "index.md") { + if ( + record._raw.sourceFileName == "index.md" || + record._raw.sourceFileName == "index.mdx" + ) { grouping[record._raw.sourceFileDir] = Object.assign( grouping[record._raw.sourceFileDir], // @ts-ignore @@ -157,7 +160,7 @@ export function sortNavItems(navItems: NavItem[]) { */ export function shouldIgnoreRecord({ fileName, - allowedExtensions = ["md"], + allowedExtensions = ["md", "mdx"], }: { fileName: string; allowedExtensions?: Array; @@ -212,6 +215,10 @@ export function computeNavItem( ); } + // always lowercase certain specific values + record.href = record.href.toLowerCase(); + record.id = record.id.toLowerCase(); + /** * when the record is only storing metadata, remove it as a linked item * ---