Git Product home page Git Product logo

aleph-plugin-mdx's Introduction

aleph-plugin-mdx

deno land nest.land

MDX 2 plugin for Aleph.js

Usage

// aleph.config.ts
import mdx from "https://deno.land/x/aleph_plugin_mdx@$VERSION/mod.ts";
import type { Config } from "https://deno.land/x/[email protected]/types.d.ts";

export default <Config> {
  plugins: [mdx()],
};

then, modify import_map.json.

{
  "imports": {
    ...,
    "react/jsx-runtime": "https://esm.sh/[email protected]/jsx-runtime"
  }
}

Why need import map?

By default, .mdx files are JSX transformed into the @jsx-runtime format.

It includes the following imports.

import {
  Fragment as _Fragment,
  jsx as _jsx,
  jsxs as _jsxs,
} from "react/jsx-runtime";

As you know, Deno imports remote modules with URL schema. This means that you need to change react/jsx-runtime to the correct URL.

Fortunately, Aleph.js has import map resolution enabled by default, so we will use that.

๐Ÿšง This process may be automated in the future.

Examples

API

This package exports default as plugin. It uses the same style as the official plugin.

default(options?)

options.rewritePagePath

Rewrite the page path

declare function rewritePagePath: (path: string) => string | undefined;

example:

pages
โ”œโ”€โ”€ get_started.mdx
โ””โ”€โ”€ index.tsx
// aleph.config.ts
import mdx from "https://deno.land/x/aleph_plugin_mdx@$VERSION/mod.ts";
import type { Config } from "https://deno.land/x/[email protected]/types.d.ts";
export default <Config> {
  plugins: [mdx({
    rewritePagePath(path) {
      return path.replaceAll("_", "-");
    },
  })],
};

output:

โ–ฒ SSG
  /
  /get-started

options.pageProps

Define props to page components.

declare const pageProps = Record<string | number, unknown>;

example:

// aleph.config.ts
import mdx from "https://deno.land/x/aleph_plugin_mdx@$VERSION/mod.ts";
import type { Config } from "https://deno.land/x/[email protected]/types.d.ts";
export default <Config> {
  plugins: [
    mdx({
      pageProps: { nav: [{ path: "/" }, { path: "/docs" }] },
    }),
  ],
};
pages
โ”œโ”€โ”€ docs
โ”‚   โ””โ”€โ”€ installation.mdx
โ””โ”€โ”€ docs.tsx
// docs.tsx
import type { MDXContent } from "https://esm.sh/@types/mdx/types.d.ts";
export type DocsProps = {
  Page?: MDXContent & { nav: { path: string }[] };
};
export default function Docs({ Page }: DocsProps) {
  if (!Page) return <></>;

  // Page.nav
  return <Page />;
}

others:

Passes the @mdx-js/mdx#compile options as is. For details, see compile options.

Note

This plugin depends on @mdx-js/[email protected].

License

Copyright ยฉ 2021-present TomokiMiyauci.

Released under the MIT license

aleph-plugin-mdx's People

Contributors

semantic-release-bot avatar tomokimiyauci avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.