update website with new remix typings
This commit is contained in:
@@ -2,35 +2,34 @@ import glob from "fast-glob"
|
||||
import grayMatter from "gray-matter"
|
||||
import { readFile } from "node:fs/promises"
|
||||
import { join, parse } from "node:path"
|
||||
import type { AppLinkProps } from "~/modules/navigation/app-link"
|
||||
import { z } from "zod"
|
||||
|
||||
const guidesFolder = "app/routes/guides"
|
||||
|
||||
export type GuideLink = {
|
||||
title: string
|
||||
order: number
|
||||
link: AppLinkProps
|
||||
}
|
||||
const frontmatterSchema = z.object({
|
||||
meta: z.object({
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
}),
|
||||
order: z.number().optional(),
|
||||
})
|
||||
|
||||
export async function loadGuideLinks(): Promise<GuideLink[]> {
|
||||
export type GuideLink = Awaited<ReturnType<typeof loadGuideLinks>>[0]
|
||||
|
||||
export async function loadGuideLinks() {
|
||||
const guideFiles = await glob(`**/*.md`, { cwd: guidesFolder })
|
||||
|
||||
const links: GuideLink[] = await Promise.all(
|
||||
const links = await Promise.all(
|
||||
guideFiles.map(async (file) => {
|
||||
const { data } = grayMatter(await readFile(join(guidesFolder, file)))
|
||||
|
||||
let order = data.order
|
||||
if (!Number.isFinite(order)) {
|
||||
order = Number.POSITIVE_INFINITY
|
||||
}
|
||||
|
||||
const result = grayMatter(await readFile(join(guidesFolder, file)))
|
||||
const data = frontmatterSchema.parse(result.data)
|
||||
return {
|
||||
title: data.meta?.title,
|
||||
order,
|
||||
title: data.meta.title,
|
||||
order: data.order ?? Number.POSITIVE_INFINITY,
|
||||
link: {
|
||||
type: "router",
|
||||
type: "router" as const,
|
||||
to: `/guides/${parse(file).name}`,
|
||||
children: data.meta?.title,
|
||||
children: data.meta.title,
|
||||
},
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user