netzo / fresh-netzo

Full-stack Deno Fresh meta-framework for building business web apps like internal tools, dashboards, admin panels and automated workflows.
https://netzo.io
MIT License
52 stars 2 forks source link

[plugins] add `mdx` plugin to support MDX routes #146

Open miguelrk opened 7 months ago

miguelrk commented 7 months ago

Deno fresh has built-in support for routes/**/*.(ts|jtsx|js|jsx) files but not for .mdx.

MDX lets you use JSX in your markdown content. You can import components, such as interactive charts or alerts, and embed them within your content. This makes writing long-form content with components a blast. 🚀 Continue reading ».

Netzo should allow using mdx files for routes to allow usage like similar to that of lume.land/plugins/mdx.

---
title: Dashboard
description: An overview of sales for this quarter. 
---

import { SalesPlot } from "@/islands/SalesPlot.tsx";

const data = await getData(...);

# {page.title}

{page.description}

<SalesPlot data={data} />

instead of the equivalent

import { SalesPlot } from "@/islands/SalesPlot.tsx";

const title = "Dashboard";
const description = "An overview of sales for this quarter.";

export default defineRoute(async (req, ctx) => {
  const data = await getData(...);
  return (
    <div>
      <Head>
        <title>{title} | Netzo</title>
        <meta name="description" content={description} />
      </Head>
      <h1 className="font-bold text-xl">{title}</h1>
      <p className="text-muted-foreground">{description}</p>
      <SalesPlot data={data} />
    </div>
  )
})

This could probably be done via a fresh plugin mdx() which analogous to the api() plugin, mounts some routes, only that in this case it walks the file system to generate them instead of generating them only from the config object.

Reference