2022-04-28 16:37:12 +00:00
|
|
|
import Layout from '../../components/layout';
|
2022-10-05 03:41:59 +00:00
|
|
|
import { getAllNotes, getNote } from '../../lib/slug';
|
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';
|
2022-04-28 16:37:12 +00:00
|
|
|
|
|
|
|
function Note({ note }: any) {
|
|
|
|
return (<>
|
|
|
|
<Layout name={note.title} title={note.title} ancestors={[{ name: 'Notes', path: 'notes' }]}>
|
|
|
|
<section className='block'>
|
|
|
|
<ReactMarkdown
|
2022-04-30 13:56:18 +00:00
|
|
|
remarkPlugins={[remarkGfm]}
|
2022-10-05 03:41:59 +00:00
|
|
|
rehypePlugins={[rehypeRaw]}
|
2022-04-28 16:37:12 +00:00
|
|
|
components={{
|
|
|
|
code({ node, inline, className, children, ...props }) {
|
|
|
|
const match = /language-(\w+)/.exec(className || '')
|
2022-04-30 13:56:18 +00:00
|
|
|
return !inline && match
|
|
|
|
? (
|
|
|
|
<SyntaxHighlighter
|
|
|
|
showLineNumbers={true}
|
|
|
|
language={match[1]}
|
2022-09-28 02:04:44 +00:00
|
|
|
//@ts-ignore
|
2022-10-05 03:41:59 +00:00
|
|
|
style={hlTheme}
|
2022-04-30 13:56:18 +00:00
|
|
|
PreTag='div'
|
2022-05-15 13:56:45 +00:00
|
|
|
codeTagProps={{ style: { display: 'block' } }}
|
|
|
|
customStyle={{ padding: '0', borderRadius: '1rem' }}
|
2022-04-30 13:56:18 +00:00
|
|
|
{...props}
|
2022-09-28 02:04:44 +00:00
|
|
|
>{String(children).replace(/\n$/, '')}</SyntaxHighlighter>
|
2022-04-30 13:56:18 +00:00
|
|
|
)
|
|
|
|
: <code className={className} {...props}>
|
|
|
|
{children}
|
|
|
|
</code>
|
2022-04-28 16:37:12 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>{note.content}</ReactMarkdown>
|
|
|
|
</section>
|
|
|
|
</Layout>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStaticProps({ params }: any) {
|
2022-10-05 03:41:59 +00:00
|
|
|
const note = getNote(params.note);
|
2022-04-28 16:37:12 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
props: { note }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
const notes = getAllNotes();
|
|
|
|
return {
|
|
|
|
paths: notes.map((note: any) => {
|
|
|
|
return {
|
|
|
|
params: {
|
2022-10-05 03:41:59 +00:00
|
|
|
note: note.slug
|
2022-04-28 16:37:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
fallback: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default Note;
|