Skip to content

Commit

Permalink
refactor: create constants/path.js (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
lumirlumir authored Sep 14, 2024
1 parent e262a10 commit 2881787
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/app/docs/[...categories]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { promises as fs } from 'fs';
import parse from 'html-react-parser';

import { REPOSITORY } from '@/constants/github';
import { DOCS } from '@/constants/path';
import Article from '@/layouts/Article';

export async function generateStaticParams() {
const paths = await fs.readdir(`${process.cwd()}/src/docs`, {
const paths = await fs.readdir(DOCS, {
encoding: 'utf-8',
recursive: true,
});
Expand All @@ -19,7 +20,7 @@ export async function generateStaticParams() {

export default async function Page({ params }) {
const markdown = await fs.readFile(
`${process.cwd()}/src/docs/${params.categories.join('/')}.md`,
`${DOCS}/${params.categories.join('/')}.md`,
'utf-8',
);

Expand Down
1 change: 1 addition & 0 deletions src/constants/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DOCS = `${process.cwd()}/src/docs`;
4 changes: 3 additions & 1 deletion src/layouts/Aside/Aside.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { promises as fs } from 'fs';
import Link from 'next/link';

import { DOCS } from '@/constants/path';

import styles from './Aside.module.scss';

export default async function Aside() {
Expand All @@ -16,7 +18,7 @@ export default async function Aside() {
);
}

const dirs = await fs.readdir(`${process.cwd()}/src/docs`, {
const dirs = await fs.readdir(DOCS, {
encoding: 'utf-8',
recursive: true,
});
Expand Down

0 comments on commit 2881787

Please sign in to comment.