import { MetaFunction, redirect, useCatch, useLoaderData } from 'remix'; import type { LoaderFunction, LinksFunction } from 'remix'; import type { GenericParent } from 'mystjs'; import { ReferencesProvider, ContentBlock } from '~/components'; import { getData, getConfig, getMetaTagsForArticle, getFolder, PageLoader, getFooterLinks, Config, } from '~/utils'; import { Footer } from '~/components/FooterLinks'; import { Bibliography } from '../../components/renderers/cite'; export const meta: MetaFunction = (args) => { const config = args.parentsData.root.config as Config | undefined; const data = args.data as PageLoader | undefined; if (!data) return {}; return getMetaTagsForArticle({ origin: '', url: args.location.pathname, title: `${data?.frontmatter.title} - ${config?.site.name}`, description: data.frontmatter.description, }); }; export const links: LinksFunction = () => { return [ { rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.css', integrity: 'sha384-MlJdn/WNKDGXveldHDdyRP1R4CTHr3FeuDNfhsLPYrq2t0UBkUdK2jyTnXPEK1NQ', crossOrigin: 'anonymous', }, ]; }; export const loader: LoaderFunction = async ({ params, request, }): Promise => { const folderName = params.folder; const config = await getConfig(request); const folder = getFolder(config, folderName); if (!folder) { throw new Response('Article was not found', { status: 404 }); } if (folder.index === params.id) { return redirect(`/${folderName}`); } const slug = params.loadIndexPage ? folder.index : params.slug; const loader = await getData(config, folderName, slug).catch((e) => { console.log(e); return null; }); if (!loader) throw new Response('Article was not found', { status: 404 }); const footer = getFooterLinks(config, folderName, slug); return { ...loader, footer }; }; export default function Page() { const article = useLoaderData(); const blocks = article.mdast.children as GenericParent[]; return (

{article.frontmatter.title}

{article.frontmatter.author && article.frontmatter.author.length > 0 && (
    {article.frontmatter.author?.map((author, i) => (
  1. {author}
  2. ))}
)} {blocks.map((node, index) => { return ; })} {article.references.cite.order.length > 0 && }
); } export function CatchBoundary() { const caught = useCatch(); // TODO: This can give a pointer to other pages in the space return (
{caught.status} {caught.statusText}
); } export function ErrorBoundary() { return ( <>

Test

Something went wrong.
); }