|
| 1 | +/* eslint-disable @next/next/no-img-element */ |
| 2 | +const TerminusClient = require("@terminusdb/terminusdb-client") |
| 3 | +import Image from "next/image" |
| 4 | +import { Inter } from "next/font/google" |
| 5 | +const inter = Inter({ subsets: ["latin"] }) |
| 6 | +import axios from "axios" |
| 7 | +import "flowbite" |
| 8 | +import { getHtml, getSubTitle } from "../utils" |
| 9 | +import menu from "../menu.json" |
| 10 | +import { Layout } from "../components/_layout" |
| 11 | +import { renderMarkdown } from "../lib/markdown" |
| 12 | + |
| 13 | +export default function Home(props: { menu: any[]; entry: any[] }) { |
| 14 | + let html = getHtml(props.entry) |
| 15 | + let displayElement = <div dangerouslySetInnerHTML={{ __html: html }} /> |
| 16 | + return ( |
| 17 | + <Layout |
| 18 | + menu={props.menu} |
| 19 | + entry={props.entry} |
| 20 | + displayElement={displayElement} |
| 21 | + heading={props.entry.document?.title?.value ?? ""} |
| 22 | + subtitle={getSubTitle(props.entry.document)} |
| 23 | + seo_metadata={props.entry.document?.seo_metadata} |
| 24 | + /> |
| 25 | + ) |
| 26 | +} |
| 27 | + |
| 28 | +export async function getStaticProps({ params }) { |
| 29 | + // Connect and configure the TerminusClient |
| 30 | + const client = new TerminusClient.WOQLClient( |
| 31 | + process.env.TERMINUSDB_API_ENDPOINT, |
| 32 | + { |
| 33 | + user: process.env.TERMINUSDB_USER, |
| 34 | + organization: process.env.TERMINUSDB_TEAM, |
| 35 | + db: process.env.TERMINUSDB_DB, |
| 36 | + token: process.env.TERMINUSDB_API_TOKEN, |
| 37 | + } |
| 38 | + ) |
| 39 | + const query = { |
| 40 | + "@type": "Page", |
| 41 | + slug: "get-started", |
| 42 | + } |
| 43 | + const docs = await client.getDocument({ |
| 44 | + "@type": "Page", |
| 45 | + as_list: true, |
| 46 | + query: query, |
| 47 | + }) |
| 48 | + const docResult = docs[0] |
| 49 | + let html = await renderMarkdown(docResult?.["body"]?.["value"] ?? "") |
| 50 | + const entry = { html: html, document: docResult ?? null } |
| 51 | + return { props: { menu: menu, entry: entry } } |
| 52 | +} |
0 commit comments