import { Container } from '../components/Container'
import clientPromise from '../lib/mddb'
import { promises as fs } from 'fs';
import { MDXRemote } from 'next-mdx-remote'
import { Card } from '../components/Card'
import Head from 'next/head'
import parse from '../lib/markdown'
import { Mermaid } from '@portaljs/core';
export const getStaticProps = async ({ params }) => {
const urlPath = params.slug ? params.slug.join('/') : ''
const mddb = await clientPromise
const dbFile = await mddb.getFileByUrl(urlPath)
const source = await fs.readFile(dbFile.file_path,'utf-8')
let mdxSource = await parse(source, '.mdx')
return {
props: {
mdxSource,
},
}
}
export async function getStaticPaths() {
const mddb = await clientPromise
const allDocuments = await mddb.getFiles({ extensions: ['md', 'mdx'] })
const paths = allDocuments.filter(document => document.url_path !== '/').map((page) => {
const parts = page.url_path.split('/')
return { params: { slug: parts } }
})
return {
paths,
fallback: false,
}
}
const isValidUrl = (urlString) => {
try {
return Boolean(new URL(urlString))
} catch (e) {
return false
}
}
const Meta = ({keyValuePairs}) => {
const prettifyMetaValue = (value) => value.replaceAll('-',' ').charAt(0).toUpperCase() + value.replaceAll('-',' ').slice(1);
return (
<>
{keyValuePairs.map((entry) => {
return isValidUrl(entry[1]) ? (