Bump script ver and refactor md metadata gen
Signed-off-by: Paul W. <lambdapaul@protonmail.com>
This commit is contained in:
		@@ -1,12 +1,23 @@
 | 
			
		||||
import Layout from '../../components/layout';
 | 
			
		||||
import { getAllNotes, getNote } from '../../lib/slug';
 | 
			
		||||
import ReactMarkdown from 'react-markdown';
 | 
			
		||||
import SyntaxHighlighter from 'react-syntax-highlighter';
 | 
			
		||||
import { monokaiSublime as hlTheme } from 'react-syntax-highlighter/dist/cjs/styles/hljs';
 | 
			
		||||
import remarkGfm from 'remark-gfm';
 | 
			
		||||
import rehypeRaw from 'rehype-raw';
 | 
			
		||||
import readMarkdown from '../../lib/read-markdown';
 | 
			
		||||
 | 
			
		||||
function Markdown({content}: any) {
 | 
			
		||||
import NotesInfo from '../../public/notes.json';
 | 
			
		||||
 | 
			
		||||
interface Note {
 | 
			
		||||
    title: string,
 | 
			
		||||
    mtime: string,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
interface Notes {
 | 
			
		||||
    [slug: string]: Note;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function Markdown({ content }: any) {
 | 
			
		||||
    return <ReactMarkdown
 | 
			
		||||
        remarkPlugins={[remarkGfm]}
 | 
			
		||||
        rehypePlugins={[rehypeRaw]}
 | 
			
		||||
@@ -36,7 +47,7 @@ function Markdown({content}: any) {
 | 
			
		||||
 | 
			
		||||
function Note({ note }: any) {
 | 
			
		||||
    return (<>
 | 
			
		||||
        <Layout name={note.title} title={note.title} ancestors={[{ name: 'Notes', path: 'notes' }]}>
 | 
			
		||||
        <Layout >
 | 
			
		||||
            <section className='block'>
 | 
			
		||||
                <Markdown content={note.content} />
 | 
			
		||||
            </section>
 | 
			
		||||
@@ -46,20 +57,26 @@ function Note({ note }: any) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function getStaticProps({ params }: any) {
 | 
			
		||||
    const note = getNote(params.note);
 | 
			
		||||
    const note: string = params.note;
 | 
			
		||||
    const notesInfo: Notes = NotesInfo;
 | 
			
		||||
    const noteInfo: Note = notesInfo[note];
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        props: { note }
 | 
			
		||||
    };
 | 
			
		||||
        props: {
 | 
			
		||||
            note: {
 | 
			
		||||
                ...noteInfo,
 | 
			
		||||
                content: await readMarkdown('notes', note, true)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function getStaticPaths() {
 | 
			
		||||
    const notes = getAllNotes();
 | 
			
		||||
    return {
 | 
			
		||||
        paths: notes.map((note: any) => {
 | 
			
		||||
        paths: Object.keys(NotesInfo).map((note: string) => {
 | 
			
		||||
            return {
 | 
			
		||||
                params: {
 | 
			
		||||
                    note: note.slug
 | 
			
		||||
                    note
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }),
 | 
			
		||||
 
 | 
			
		||||
@@ -1,36 +1,40 @@
 | 
			
		||||
import Link from 'next/link';
 | 
			
		||||
import Layout from '../../components/layout';
 | 
			
		||||
import date from '../../lib/date';
 | 
			
		||||
import { getNotesMeta, INoteMeta } from '../../lib/slug';
 | 
			
		||||
 | 
			
		||||
function NotesPage({ notesMeta }: { notesMeta: INoteMeta[] }) {
 | 
			
		||||
import date from '../../lib/date';
 | 
			
		||||
import NotesInfo from '../../public/notes.json';
 | 
			
		||||
 | 
			
		||||
function NoteEntry(props: { path: string, note: { title: string, mtime: string } }) {
 | 
			
		||||
    return (
 | 
			
		||||
        <Layout name='Notes'>
 | 
			
		||||
            <table>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td style={{ flex: '1 0 50%' }}>
 | 
			
		||||
                <Link href={props.path}>
 | 
			
		||||
                    {props.note.title}
 | 
			
		||||
                </Link>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td style={{ fontStyle: 'italic' }}>
 | 
			
		||||
                {props.note.mtime && date.toRelativeDate(new Date(props.note.mtime))}
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function NotesPage() {
 | 
			
		||||
    const notes = Object.entries(NotesInfo);
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
        <Layout>
 | 
			
		||||
            {!notes || notes.length === 0 && <>No notes found</> || <table>
 | 
			
		||||
                <tbody>
 | 
			
		||||
                {notesMeta && notesMeta.map((note: INoteMeta, i) => {
 | 
			
		||||
                    return (
 | 
			
		||||
                    <tr key={i}>
 | 
			
		||||
                        <td style={{flex: '1 0 50%'}}>
 | 
			
		||||
                            <Link href={`/notes/${note.slug}`}>
 | 
			
		||||
                                {note.title}
 | 
			
		||||
                            </Link>
 | 
			
		||||
                        </td>
 | 
			
		||||
                        <td style={{fontStyle: 'italic'}}>
 | 
			
		||||
                            {note.last_updated && date.toRelativeDate(new Date(note.last_updated))}
 | 
			
		||||
                        </td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                )})}
 | 
			
		||||
                    {notes.map(([slug, note]: any, i: number) => {
 | 
			
		||||
                        return <NoteEntry path={`/notes/${slug}`} note={note} key={i} />
 | 
			
		||||
                    })}
 | 
			
		||||
                </tbody>
 | 
			
		||||
            </table>
 | 
			
		||||
            </table>}
 | 
			
		||||
        </Layout>
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function getStaticProps() {
 | 
			
		||||
    return {
 | 
			
		||||
        props: { notesMeta: getNotesMeta() }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default NotesPage;
 | 
			
		||||
export default NotesPage;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user