2022-04-28 16:37:12 +00:00
|
|
|
import ReactMarkdown from 'react-markdown';
|
2022-04-30 13:56:18 +00:00
|
|
|
import SyntaxHighlighter from 'react-syntax-highlighter';
|
2022-10-05 03:41:59 +00:00
|
|
|
import { monokaiSublime as hlTheme } from 'react-syntax-highlighter/dist/cjs/styles/hljs';
|
2022-04-28 16:37:12 +00:00
|
|
|
import remarkGfm from 'remark-gfm';
|
2022-10-05 03:41:59 +00:00
|
|
|
import rehypeRaw from 'rehype-raw';
|
2024-10-03 02:47:34 +00:00
|
|
|
import remarkDirective from 'remark-directive';
|
|
|
|
import remarkGithubAdmonitionsToDirectives from 'remark-github-admonitions-to-directives';
|
2022-04-28 16:37:12 +00:00
|
|
|
|
2024-10-03 02:47:34 +00:00
|
|
|
import Layout from '../../components/layout';
|
2023-10-30 04:55:45 +00:00
|
|
|
import readMarkdown from '../../lib/read-markdown';
|
2023-10-30 04:18:38 +00:00
|
|
|
import NotesInfo from '../../public/notes.json';
|
|
|
|
|
|
|
|
interface Note {
|
|
|
|
title: string,
|
|
|
|
mtime: string,
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Notes {
|
|
|
|
[slug: string]: Note;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Markdown({ content }: any) {
|
2023-09-20 04:25:34 +00:00
|
|
|
return <ReactMarkdown
|
2024-10-03 02:47:34 +00:00
|
|
|
remarkPlugins={[remarkGithubAdmonitionsToDirectives, remarkDirective]}
|
2023-09-20 04:25:34 +00:00
|
|
|
rehypePlugins={[rehypeRaw]}
|
|
|
|
components={{
|
2023-10-30 04:55:45 +00:00
|
|
|
code({ node, className, children, ...props }) {
|
2023-09-20 04:25:34 +00:00
|
|
|
const match = /language-(\w+)/.exec(className || '')
|
2023-10-30 04:55:45 +00:00
|
|
|
return match
|
2023-09-20 04:25:34 +00:00
|
|
|
? (
|
|
|
|
<SyntaxHighlighter
|
|
|
|
showLineNumbers={true}
|
|
|
|
language={match[1]}
|
|
|
|
//@ts-ignore
|
|
|
|
style={hlTheme}
|
|
|
|
PreTag='div'
|
|
|
|
codeTagProps={{ style: { display: 'block' } }}
|
|
|
|
customStyle={{ padding: '0', borderRadius: '1rem' }}
|
|
|
|
{...props}
|
|
|
|
>{String(children).replace(/\n$/, '')}</SyntaxHighlighter>
|
|
|
|
)
|
|
|
|
: <code className={className} {...props}>
|
|
|
|
{children}
|
|
|
|
</code>
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>{content}</ReactMarkdown>
|
|
|
|
}
|
|
|
|
|
2022-04-28 16:37:12 +00:00
|
|
|
function Note({ note }: any) {
|
|
|
|
return (<>
|
2023-10-30 04:18:38 +00:00
|
|
|
<Layout >
|
2022-04-28 16:37:12 +00:00
|
|
|
<section className='block'>
|
2023-09-20 04:25:34 +00:00
|
|
|
<Markdown content={note.content} />
|
2022-04-28 16:37:12 +00:00
|
|
|
</section>
|
|
|
|
</Layout>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStaticProps({ params }: any) {
|
2023-10-30 04:18:38 +00:00
|
|
|
const note: string = params.note;
|
|
|
|
const notesInfo: Notes = NotesInfo;
|
|
|
|
const noteInfo: Note = notesInfo[note];
|
2022-04-28 16:37:12 +00:00
|
|
|
|
|
|
|
return {
|
2023-10-30 04:18:38 +00:00
|
|
|
props: {
|
|
|
|
note: {
|
|
|
|
...noteInfo,
|
|
|
|
content: await readMarkdown('notes', note, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 16:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
return {
|
2023-10-30 04:18:38 +00:00
|
|
|
paths: Object.keys(NotesInfo).map((note: string) => {
|
2022-04-28 16:37:12 +00:00
|
|
|
return {
|
|
|
|
params: {
|
2023-10-30 04:18:38 +00:00
|
|
|
note
|
2022-04-28 16:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
fallback: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default Note;
|