Add page routing and content fetchers
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user