From 0941f261a97b46e10bdc19ba5c8572b5cdf43bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan-Eric=20N=C3=A6ss?= Date: Tue, 7 Mar 2023 18:59:05 +0100 Subject: [PATCH] Move articles --- {articles => content/articles}/another.mdx | 0 {articles => content/articles}/new-article.mdx | 0 {articles => content/articles}/some-file.mdx | 0 src/pages/articles.tsx | 4 ++-- src/pages/articles/{[slug].tsx => [article].tsx} | 16 ++++++++-------- src/pages/index.tsx | 1 + tsconfig.json | 3 ++- 7 files changed, 13 insertions(+), 11 deletions(-) rename {articles => content/articles}/another.mdx (100%) rename {articles => content/articles}/new-article.mdx (100%) rename {articles => content/articles}/some-file.mdx (100%) rename src/pages/articles/{[slug].tsx => [article].tsx} (64%) diff --git a/articles/another.mdx b/content/articles/another.mdx similarity index 100% rename from articles/another.mdx rename to content/articles/another.mdx diff --git a/articles/new-article.mdx b/content/articles/new-article.mdx similarity index 100% rename from articles/new-article.mdx rename to content/articles/new-article.mdx diff --git a/articles/some-file.mdx b/content/articles/some-file.mdx similarity index 100% rename from articles/some-file.mdx rename to content/articles/some-file.mdx diff --git a/src/pages/articles.tsx b/src/pages/articles.tsx index c42df1a..3ff21df 100644 --- a/src/pages/articles.tsx +++ b/src/pages/articles.tsx @@ -31,10 +31,10 @@ export default function ListDocs({articles}: ListDocsProps) { export const getStaticProps = async () => { const fs = await import('fs'); - const files = fs.readdirSync('./articles') + const files = fs.readdirSync('./content/articles') .filter((file) => file.endsWith('mdx')); const modules = await Promise.all( - files.map((file) => import(`../../articles/${file}`)) + files.map((file) => import(`#/articles/${file}`)) ); const articles = modules.map((mod, index) => { const file = files[index] as string; diff --git a/src/pages/articles/[slug].tsx b/src/pages/articles/[article].tsx similarity index 64% rename from src/pages/articles/[slug].tsx rename to src/pages/articles/[article].tsx index 5921391..be4d6de 100644 --- a/src/pages/articles/[slug].tsx +++ b/src/pages/articles/[article].tsx @@ -2,10 +2,10 @@ import { GetStaticProps } from "next"; import { lazy, Suspense } from "react"; import { NavBar } from "@/components/NavBar"; -type SlugProps = {page: string, name: string}; +type ArticleProps = {page: string, name: string}; -export default function Slug({page, name}: SlugProps) { - const MDX = lazy(() => import(`../../../articles/${page}.mdx`)); +export default function Article({page, name}: ArticleProps) { + const MDX = lazy(() => import(`#/articles/${page}.mdx`)); return (<>

{name}

@@ -20,22 +20,22 @@ export default function Slug({page, name}: SlugProps) { export async function getStaticPaths() { const fs = await import('fs'); - const files = fs.readdirSync('./articles') + const files = fs.readdirSync('./content/articles') .filter((file) => file.endsWith('mdx')); return { paths: files.map(name => ({ params: { - slug: name.substring(0, name.length-4) + article: name.substring(0, name.length-4) } })), fallback: true, } } -type PageStaticProps = GetStaticProps; +type PageStaticProps = GetStaticProps; export const getStaticProps: PageStaticProps = async ({params}) => { - const file = (`${params?.slug}`); - const mdx = await import(`../../../articles/${file}.mdx`); + const file = (`${params?.article}`); + const mdx = await import(`#/articles/${file}.mdx`); return { props: { page: file, diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 7bce7b4..c20d783 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -5,5 +5,6 @@ export default function Home() { return (<>

Chocobois

+

We make game

); } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a16b416..55219d8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,8 @@ "incremental": true, "noUncheckedIndexedAccess": true, "paths": { - "@/*": ["./src/*"] + "@/*": ["./src/*"], + "#/*": ["./content/*"] } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.cjs", "**/*.mjs", "src"],