mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
Clean code
This commit is contained in:
14
lib/posts.ts
14
lib/posts.ts
@ -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' });
|
||||||
|
@ -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 />}
|
||||||
|
Reference in New Issue
Block a user