diff --git a/public/images/loading.gif b/public/images/loading.gif new file mode 100644 index 0000000..e022aab Binary files /dev/null and b/public/images/loading.gif differ diff --git a/src/app/categories/[tag]/page.jsx b/src/app/categories/[tag]/page.jsx index 17b948d..0638b3d 100644 --- a/src/app/categories/[tag]/page.jsx +++ b/src/app/categories/[tag]/page.jsx @@ -3,30 +3,42 @@ import Link from 'next/link'; import { Fragment, Suspense } from 'react'; import { FaBook, FaTag, FaRegCalendarPlus, FaRegCalendarXmark } from 'react-icons/fa6'; +import Loading from '@/components/common/Loading'; + import { PATH_DOCS, EXT_MD_REGEXP } from '@/constants'; import { compareMarkdownDocument } from '@/utils/compare'; import { readMarkdownTagTree } from '@/utils/fs'; -import { markdownToText } from '@/utils/markup'; +import { markdownToJsx } from '@/utils/markup'; + +/* Next.js Declaration */ +// Control what happens when a dynamic segment is visited that was not generated with `generateStaticParams`. +export const dynamicParams = false; + +export async function generateStaticParams() { + const tagTree = await readMarkdownTagTree(PATH_DOCS); + const tags = Object.keys(tagTree); + + return tags.map(tag => ({ tag })); +} export default async function Page({ params, searchParams }) { const { sort = 'updated', order = 'desc' } = searchParams; - const tagTree = await readMarkdownTagTree(PATH_DOCS); return ( - loading...}> + }> {tagTree[params.tag] .sort(compareMarkdownDocument(sort, order)) .map(({ basename, data: { title, description, created, updated, tags } }) => (

- {markdownToText(title)} + {markdownToJsx(title)}

- {markdownToText(description)} + {markdownToJsx(description)}

{tags.map(tag => ( diff --git a/src/app/posts/[markdown]/loading.jsx b/src/app/posts/[markdown]/loading.jsx new file mode 100644 index 0000000..d696d1b --- /dev/null +++ b/src/app/posts/[markdown]/loading.jsx @@ -0,0 +1,5 @@ +import LoadingGif from '@/components/common/Loading'; + +export default function Loading() { + return ; +} diff --git a/src/app/posts/[markdown]/page.jsx b/src/app/posts/[markdown]/page.jsx index a14f0d0..19db1e4 100644 --- a/src/app/posts/[markdown]/page.jsx +++ b/src/app/posts/[markdown]/page.jsx @@ -2,7 +2,7 @@ import { join } from 'path'; import { PATH_DOCS, EXT_MD, EXT_MD_REGEXP } from '@/constants'; import { readMarkdownFile, readMarkdownFilesFromDir } from '@/utils/fs'; -import { markdownToText, markdownToJsx } from '@/utils/markup'; +import { markdownToText, markdownToJsxFromPath } from '@/utils/markup'; /* Custom Declaration */ function getFilePath(params) { @@ -34,5 +34,5 @@ export async function generateMetadata({ params }) { } export default async function Page({ params }) { - return <>{await markdownToJsx(getFilePath(params))}; + return <>{await markdownToJsxFromPath(getFilePath(params))}; } diff --git a/src/components/common/Loading/Loading.jsx b/src/components/common/Loading/Loading.jsx new file mode 100644 index 0000000..b1fb416 --- /dev/null +++ b/src/components/common/Loading/Loading.jsx @@ -0,0 +1,19 @@ +import Image from 'next/image'; + +import styles from './Loading.module.scss'; + +export default function Loading({ content }) { + return ( +

+
+ GitHub gif loading image +
{content} 불러오는 중...
+
+
+ ); +} diff --git a/src/components/common/Loading/Loading.module.scss b/src/components/common/Loading/Loading.module.scss new file mode 100644 index 0000000..2016751 --- /dev/null +++ b/src/components/common/Loading/Loading.module.scss @@ -0,0 +1,3 @@ +.loading { + @include props-flex-center; +} diff --git a/src/components/common/Loading/index.js b/src/components/common/Loading/index.js new file mode 100644 index 0000000..a57e397 --- /dev/null +++ b/src/components/common/Loading/index.js @@ -0,0 +1,3 @@ +import Loading from './Loading'; + +export default Loading; diff --git a/src/utils/markup.js b/src/utils/markup.js index 20195e9..56aed63 100644 --- a/src/utils/markup.js +++ b/src/utils/markup.js @@ -31,6 +31,7 @@ export async function markdownToHtml(markdownContent) { method: 'POST', headers: { Accept: 'application/vnd.github+json', + Authorization: `Bearer ${process.env.GH_PAT}`, 'Content-Type': 'application/json', 'X-GitHub-Api-Version': '2022-11-28', }, @@ -48,19 +49,31 @@ export async function markdownToHtml(markdownContent) { * Converts markdown content to JSX. * * @async + * @param {string} markdownContent Markdown content. + * @returns {Promise} A promise that resolves to JSX. + */ +export async function markdownToJsx(markdownContent) { + const html = await markdownToHtml(markdownContent); + const jsx = htmlToJsx(html); + + return jsx; +} + +/** + * Converts markdown content to JSX from path. + * + * @async * @param {string} pathToMarkdownFile Path to a markdown file. * @returns {Promise} A promise that resolves to JSX. */ -export async function markdownToJsx(pathToMarkdownFile) { +export async function markdownToJsxFromPath(pathToMarkdownFile) { const { content, data: { title }, } = await readMarkdownFile(pathToMarkdownFile); const markdownContent = writeTitleIntoMarkdown(title, content); - - const html = await markdownToHtml(markdownContent); - const jsx = htmlToJsx(html); + const jsx = await markdownToJsx(markdownContent); return jsx; }