2022-04-28 16:37:12 +00:00
|
|
|
import Layout from '../../components/layout';
|
|
|
|
import { getAllNotes, getNote } from '../../util/slug';
|
|
|
|
import ReactMarkdown from 'react-markdown';
|
2022-04-30 13:56:18 +00:00
|
|
|
import SyntaxHighlighter from 'react-syntax-highlighter';
|
|
|
|
import { monokaiSublime } from 'react-syntax-highlighter/dist/cjs/styles/hljs';
|
2022-04-28 16:37:12 +00:00
|
|
|
import remarkGfm from 'remark-gfm';
|
|
|
|
|
|
|
|
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-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]}
|
|
|
|
style={monokaiSublime}
|
|
|
|
wrapLongLines={true}
|
|
|
|
PreTag='div'
|
|
|
|
codeTagProps={{style: {display: 'block'}}}
|
|
|
|
customStyle={{padding:'0', borderRadius: '1rem', maxHeight: '400px'}}
|
|
|
|
{...props}
|
|
|
|
>{children}</SyntaxHighlighter>
|
|
|
|
)
|
|
|
|
: <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) {
|
|
|
|
const note = getNote(params.page);
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: { note }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
const notes = getAllNotes();
|
|
|
|
return {
|
|
|
|
paths: notes.map((note: any) => {
|
|
|
|
return {
|
|
|
|
params: {
|
|
|
|
page: note.slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
fallback: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default Note;
|