Clean code

This commit is contained in:
DefectingCat
2022-08-18 18:04:25 +08:00
parent 741a19fd90
commit 0f87104e20
2 changed files with 14 additions and 8 deletions

View File

@ -33,6 +33,11 @@ export const postLists = async (): Promise<Post[]> => {
return (await Promise.all(files.map(readFileMeta))).sort(sortByDate); return (await Promise.all(files.map(readFileMeta))).sort(sortByDate);
}; };
/**
* Replace file name.
* @param filename
* @returns
*/
const readFilePath = async (filename: string) => { const readFilePath = async (filename: string) => {
const slug = filename.replace(/\.mdx$/, ''); const slug = filename.replace(/\.mdx$/, '');
return { return {
@ -42,11 +47,20 @@ const readFilePath = async (filename: string) => {
}; };
}; };
/**
* Read posts folder.
* @returns
*/
export const allPostsPath = async () => { export const allPostsPath = async () => {
const files = await fs.readdir(path.join(dataPath)); const files = await fs.readdir(path.join(dataPath));
return await Promise.all(files.map(readFilePath)); return await Promise.all(files.map(readFilePath));
}; };
/**
* Read single postcontent.
* @param slug
* @returns
*/
export const readSinglePost = async (slug: string) => { export const readSinglePost = async (slug: string) => {
const filename = path.join(`${dataPath}/${slug}.mdx`); const filename = path.join(`${dataPath}/${slug}.mdx`);
return await fs.readFile(filename, { encoding: 'utf-8' }); return await fs.readFile(filename, { encoding: 'utf-8' });

View File

@ -1,5 +1,3 @@
import { MDXProvider } from '@mdx-js/react';
import Anchor from 'components/mdx/Anchor';
import useRouterLoading from 'lib/hooks/useRouterLoading'; import useRouterLoading from 'lib/hooks/useRouterLoading';
import { ThemeProvider } from 'next-themes'; import { ThemeProvider } from 'next-themes';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
@ -14,10 +12,6 @@ const VercelLoading = dynamic(
() => import('components/RUA/loading/VercelLoading') () => import('components/RUA/loading/VercelLoading')
); );
const components = {
a: Anchor,
};
function MyApp({ Component, pageProps }: AppPropsWithLayout) { function MyApp({ Component, pageProps }: AppPropsWithLayout) {
const getLayout = Component.getLayout ?? ((page) => page); const getLayout = Component.getLayout ?? ((page) => page);
@ -40,9 +34,7 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
enableSystem enableSystem
defaultTheme="system" defaultTheme="system"
> >
{/* <MDXProvider components={components}> */}
{getLayout(<Component {...pageProps} />)} {getLayout(<Component {...pageProps} />)}
{/* </MDXProvider> */}
</ThemeProvider> </ThemeProvider>
{loading && <VercelLoading />} {loading && <VercelLoading />}