Giter Site home page Giter Site logo

nicozweifel / mdx-butler Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 1 MB

Easily bundle and manage typed MDX files.

Home Page: https://mdx-butler.com

License: MIT License

Shell 0.32% JavaScript 3.37% TypeScript 95.99% MDX 0.31%
documentation mdx mdx-bundler server-side-rendering ssg ssr static-site-generation typescript esbuild

mdx-butler's Introduction

mdx-butler

Manage and serve MDX documents with typed Frontmatter in applications, that use Server Side Rendering or Static Site Generation.

Docs npm test test-docs

logo

Why use a Service?

Most web frameworks and build tools offer plugins to handle MDX documents. While convenient, these plugins can in some cases limit control, force specific dependencies, create performance bottlenecks and complicate the migration of your documentation to a Microservice, CMS or database in the future.

mdx-butler (built upon mdx-bundler) aims to offer a performant, flexible and framework-agnostic abstraction to manage your MDX documents. This maximizes flexibility and future-proofs your work for easy updates, migrations, and changes to your content source.

  • Enhanced content organization with typed Frontmatter and MDX syntax support for titles and descriptions within frontmatter.
  • Framework independent: Work smoothly without worrying about framework-specific plugins and dependencies.
  • Adaptability: Switch content sources (Backend/Service, CMS, database, etc.) without major rewrites.
  • Performance: Leverages mdx-bundler and esbuild for efficient compilation and bundling of MDX documents with imported dependencies.
  • Customization: Easily inject globals, components, and application logic for rich, interactive documentation.

Setup

Installation

pnpm i mdx-butler mdx-bundler esbuild

Framework Guides

Bundling

The easiest way to get all bundled documents within a folder is to call the docs function.

Warning

Exports like docs, MDXBundlerService or any others from the mdx-butler root entrypoint should only be imported in a server or build context.

Options and dependencies can be passed to docs or MDXBundlerService.create.

Note

If you require more control, consider injecting dependencies and using MDXBundlerService directly.

For more information check out the Configuration section!

import { docs } from "mdx-butler";

// ...

return docs({
  fields: {
    title: {
      required: true,
    },
  },
});

Tip

Automatically generates a FrontmatterProcessor, according to the given fields.

Types

To guarantee a correct type inference, specifying the Frontmatter type is recommended.

type Frontmatter = {
  title: string;
};

// ...

return docs<Frontmatter>({
  fields: {
    title: {
      required: true,
    },
  },
});

Note

The given Fields cannot be undefined after the Frontmatter has been processed.

If a required field is undefined, an Error will be thrown.

Component

import { Component } from "mdx-butler/client";

// ...

const doc = docs.filter((x) => slug === x.path)[0];

if (!doc) return <div>not found</div>;

return (
  <div>
    <h1>{doc.frontmatter.title}</h1>
    <Component doc={doc} />
  </div>
);

Tip

Start editing MDX documents inside /docs or the configured working directory

Security Notice

Caution

MDX is javascript. If not carefully done, evaluating user content can expose to XSS attacks.

Always be careful if you are not evaluating your own content.

Mentions

  • vike for providing a customizable, versatile web framework.
  • mdx-bundler for providing a blazingly fast esbuild based bundler for MDX files.
  • Contentlayer for providing inspiration around the MDX Developer Experience.

mdx-butler's People

Contributors

nicozweifel avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

verovariegata

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.