Skip to content

Commit f645f55

Browse files
authored
Merge pull request #3 from dfrnt-labs/vibe/crawl
Routing and redirects for /docs/
2 parents 4352022 + 60ba309 commit f645f55

File tree

7 files changed

+90
-20
lines changed

7 files changed

+90
-20
lines changed

public/staticwebapp.config.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"trailingSlash": "auto",
3+
"globalHeaders": {
4+
"X-Frame-Options": "deny"
5+
},
6+
"routes": [
7+
{
8+
"route": "/",
9+
"redirect": "https://docs.terminusdb.org/docs/",
10+
"statusCode": 301
11+
}
12+
],
13+
"responseOverrides": {
14+
"404": {
15+
"rewrite": "/404.tsx"
16+
}
17+
}
18+
}

src/components/_menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function getSlug(slug: string) {
1717
if (slug[0] === "/") {
1818
return slug
1919
}
20-
return "/" + slug
20+
return "/docs/" + slug
2121
}
2222

2323
function getMenuId(menuLabel: string) {

src/pages/[name].tsx renamed to src/pages/docs/[name].tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/* eslint-disable @next/next/no-img-element */
22
const TerminusClient = require("@terminusdb/terminusdb-client")
33
import axios from "axios"
4-
import Seo from "../components/seo"
5-
import { Layout } from "../components/_layout"
6-
import { getHtml, getSubTitle } from "../utils"
7-
import menu from "../menu.json"
4+
import Seo from "../../components/seo"
5+
import { Layout } from "../../components/_layout"
6+
import { getHtml, getSubTitle } from "../../utils"
7+
import menu from "../../menu.json"
88
import Link from "next/link"
9-
import { renderMarkdown } from "../lib/markdown"
9+
import { renderMarkdown } from "../../lib/markdown"
1010

1111
function getChildren(document, menu, level) {
1212
const menuPageSlug = menu[`Menu${level}Page`]["slug"]
1313
if (document.slug === menuPageSlug) {
1414
const deeperLevel = level + 1
1515
const children = menu[`Level${deeperLevel}`].map((child) => {
1616
return {
17-
slug: child[`Menu${deeperLevel}Page`]["slug"],
17+
slug: "docs/" + child[`Menu${deeperLevel}Page`]["slug"],
1818
label: child[`Menu${deeperLevel}Label`],
1919
}
2020
})
@@ -81,7 +81,7 @@ export async function getStaticPaths() {
8181
.filter((x) => {
8282
return typeof x["slug"] !== "undefined" && !exceptions.includes(x["slug"])
8383
})
84-
.map((x) => "/" + x["slug"])
84+
.map((x) => "/docs/" + x["slug"])
8585
return { paths: paths, fallback: false }
8686
}
8787

src/pages/docs/index.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

src/pages/javascript.tsx renamed to src/pages/docs/javascript.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
renderExamples,
55
formatShortHandAnchorIds,
66
formatAnchorIds,
7-
} from "../utils"
7+
} from "../../utils"
88
const TerminusClient = require("@terminusdb/terminusdb-client")
9-
import menu from "../menu.json"
10-
import { Layout } from "../components/_layout"
9+
import menu from "../../menu.json"
10+
import { Layout } from "../../components/_layout"
1111

1212
export default function JavaScript(props) {
1313
const modules = props.application.modules

src/pages/openapi.tsx renamed to src/pages/docs/openapi.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { OnThisPageContent } from "../components/_onThisPage"
2-
import menu from "../menu.json"
1+
import { OnThisPageContent } from "../../components/_onThisPage"
2+
import menu from "../../menu.json"
33
import dynamic from "next/dynamic"
44
const SwaggerUI = dynamic(import("swagger-ui-react"), { ssr: false })
55
import "swagger-ui-react/swagger-ui.css"
6-
import { Layout } from "../components/_layout"
6+
import { Layout } from "../../components/_layout"
77

88
// <div dangerouslySetInnerHTML={{__html: props.html }}/>
99
export default function Home(props) {

src/pages/python.tsx renamed to src/pages/docs/python.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
renderExamples,
66
formatShortHandAnchorIds,
77
formatAnchorIds,
8-
} from "../utils"
9-
import menu from "../menu.json"
10-
import { Layout } from "../components/_layout"
8+
} from "../../utils"
9+
import menu from "../../menu.json"
10+
import { Layout } from "../../components/_layout"
1111

1212
export default function Python(props) {
1313
const modules = props.application.modules
@@ -77,11 +77,11 @@ export default function Python(props) {
7777

7878
export async function getStaticProps(context) {
7979
const client = new TerminusClient.WOQLClient(
80-
"https://cloud.terminusdb.com/TerminatorsX",
80+
process.env.TERMINUSDB_API_ENDPOINT,
8181
{
8282
83-
organization: "TerminatorsX",
84-
db: "terminusCMS_docs",
83+
organization: process.env.TERMINUSDB_TEAM,
84+
db: process.env.TERMINUSDB_DB,
8585
token: process.env.TERMINUSDB_API_TOKEN,
8686
}
8787
)

0 commit comments

Comments
 (0)