Add page routing and content fetchers

This commit is contained in:
itsfinniii
2026-03-15 18:55:30 +01:00
parent bc11be5669
commit 21d5ba23a4
22 changed files with 923 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ import { createDirectusConnection } from "@/lib/directus";
import { print } from 'graphql';
import { formatDate } from "@/lib/dates";
import getAllPages from "@/graphql/pages/getAllPages.graphql";
import getPage from "@/graphql/pages/getPage.graphql";
export function dataToPage(pageRecord: any): WebPage {
let dates: string[] = [
@@ -285,6 +286,7 @@ export function dataToPage(pageRecord: any): WebPage {
}
let page: WebPage = {
type: "Webpage",
id: pageRecord["id"],
lastModified: lastModified,
url: pageRecord["url"],
@@ -320,3 +322,13 @@ export async function getAllWebpages(): Promise<WebPage[]> {
return pages;
}
export async function getWebpage(route: string): Promise<WebPage | null> {
const client = await createDirectusConnection();
const result = await client.query(print(getPage), {
date: formatDate(new Date(), "%Y-%M-%D"),
route: route
});
return dataToPage(result["Pages"][0]);
}