From 78d6a817ed93c79853d6baf3cfd6f4f84919b5be Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 20 Nov 2022 22:09:36 +0100 Subject: [PATCH] feat(frontend): add static page support at /page/[name], add tos + privacy link to login --- frontend/pages/login/discord.tsx | 6 +++-- frontend/pages/page/[page].tsx | 43 ++++++++++++++++++++++++++++++++ frontend/static_pages/.empty | 3 +++ frontend/static_pages/.gitignore | 1 + 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 frontend/pages/page/[page].tsx create mode 100644 frontend/static_pages/.empty create mode 100644 frontend/static_pages/.gitignore diff --git a/frontend/pages/login/discord.tsx b/frontend/pages/login/discord.tsx index 7423696..51e0822 100644 --- a/frontend/pages/login/discord.tsx +++ b/frontend/pages/login/discord.tsx @@ -8,6 +8,7 @@ import TextInput from "../../components/TextInput"; import Loading from "../../components/Loading"; import Button, { ButtonStyle } from "../../components/Button"; import Notice from "../../components/Notice"; +import BlueLink from "../../components/BlueLink"; interface CallbackResponse { has_account: boolean; @@ -191,8 +192,9 @@ export default function Discord() { Note: by clicking "Create - account", you agree to the terms of service and the privacy - policy. + account", you agree to the{" "} + terms of service and the{" "} + privacy policy. diff --git a/frontend/pages/page/[page].tsx b/frontend/pages/page/[page].tsx new file mode 100644 index 0000000..5ed6cd9 --- /dev/null +++ b/frontend/pages/page/[page].tsx @@ -0,0 +1,43 @@ +import { GetStaticProps } from "next"; +import { readdirSync } from "fs"; +import ReactMarkdown from "react-markdown"; +import { readFile } from "fs/promises"; +import { join } from "path"; +import Head from "next/head"; + +export async function getStaticPaths() { + const names = readdirSync("./static_pages").filter((name) => + name.endsWith(".md") + ); + + const paths = names.map((name) => ({ + params: { page: name.slice(0, -3) }, + })); + + return { + paths: paths, + fallback: false, + }; +} + +export const getStaticProps: GetStaticProps<{ text: string }> = async ({ + params, +}) => { + const text = await readFile(join("./static_pages", params!.page + ".md")); + return { props: { text: text.toString("utf8") } }; +}; + +export default function Page(props: { text: string }) { + const title = props.text.split("\n")[0].slice(2); + + return ( + <> + + {`${title} - pronouns.cc`} + +
+ {props.text} +
+ + ); +} diff --git a/frontend/static_pages/.empty b/frontend/static_pages/.empty new file mode 100644 index 0000000..528ee0f --- /dev/null +++ b/frontend/static_pages/.empty @@ -0,0 +1,3 @@ +Put any static pages here, in markdown format. + +The frontend requires `tos.md` and `privacy.md`, but you can add others if you wish. \ No newline at end of file diff --git a/frontend/static_pages/.gitignore b/frontend/static_pages/.gitignore new file mode 100644 index 0000000..dd44972 --- /dev/null +++ b/frontend/static_pages/.gitignore @@ -0,0 +1 @@ +*.md