From 0f87104e209f79e7d33ab7c747423b4058b34143 Mon Sep 17 00:00:00 2001 From: DefectingCat Date: Thu, 18 Aug 2022 18:04:25 +0800 Subject: [PATCH] Clean code --- lib/posts.ts | 14 ++++++++++++++ pages/_app.tsx | 8 -------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/posts.ts b/lib/posts.ts index 3d4061e..9d8966e 100644 --- a/lib/posts.ts +++ b/lib/posts.ts @@ -33,6 +33,11 @@ export const postLists = async (): Promise => { return (await Promise.all(files.map(readFileMeta))).sort(sortByDate); }; +/** + * Replace file name. + * @param filename + * @returns + */ const readFilePath = async (filename: string) => { const slug = filename.replace(/\.mdx$/, ''); return { @@ -42,11 +47,20 @@ const readFilePath = async (filename: string) => { }; }; +/** + * Read posts folder. + * @returns + */ export const allPostsPath = async () => { const files = await fs.readdir(path.join(dataPath)); return await Promise.all(files.map(readFilePath)); }; +/** + * Read single postcontent. + * @param slug + * @returns + */ export const readSinglePost = async (slug: string) => { const filename = path.join(`${dataPath}/${slug}.mdx`); return await fs.readFile(filename, { encoding: 'utf-8' }); diff --git a/pages/_app.tsx b/pages/_app.tsx index aa6bce6..a58c291 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,5 +1,3 @@ -import { MDXProvider } from '@mdx-js/react'; -import Anchor from 'components/mdx/Anchor'; import useRouterLoading from 'lib/hooks/useRouterLoading'; import { ThemeProvider } from 'next-themes'; import dynamic from 'next/dynamic'; @@ -14,10 +12,6 @@ const VercelLoading = dynamic( () => import('components/RUA/loading/VercelLoading') ); -const components = { - a: Anchor, -}; - function MyApp({ Component, pageProps }: AppPropsWithLayout) { const getLayout = Component.getLayout ?? ((page) => page); @@ -40,9 +34,7 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) { enableSystem defaultTheme="system" > - {/* */} {getLayout()} - {/* */} {loading && }