45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import type { GetServerSideProps } from "next";
|
|
import GuidanceReader, { type ReaderProps } from "@/components/GuidanceReader";
|
|
import { findGuide, guides } from "@/content/guides/catalog";
|
|
export default function Guide(props: ReaderProps) {
|
|
return <GuidanceReader {...props} />;
|
|
}
|
|
export const getServerSideProps: GetServerSideProps<ReaderProps> = async ({
|
|
params,
|
|
query,
|
|
}) => {
|
|
const r = query.revision;
|
|
if (r !== undefined && (typeof r !== "string" || !/^\d+$/.test(r)))
|
|
return { notFound: true };
|
|
const document = findGuide(
|
|
String(params?.id),
|
|
r === undefined ? undefined : Number(r),
|
|
);
|
|
if (!document) return { notFound: true };
|
|
return {
|
|
props: {
|
|
document,
|
|
source: "example",
|
|
versions: [{ revision: document.revision }],
|
|
links: document.links.map((link) => ({
|
|
...link,
|
|
resolved: !!findGuide(link.target, link.revision),
|
|
})),
|
|
backlinks: guides
|
|
.filter((g) =>
|
|
g.links.some(
|
|
(link) =>
|
|
link.target === document.id &&
|
|
link.revision === document.revision,
|
|
),
|
|
)
|
|
.map(({ id, title, revision }) => ({
|
|
id,
|
|
title,
|
|
revision,
|
|
source: "example",
|
|
})),
|
|
},
|
|
};
|
|
};
|