mopress

    A modern documentation and static site generator for the MoonBit ecosystem, inspired by mdBook and Hakyll

    docs
    utils
    cli
    functional
    site-generator
    website
    Download zip
    Author
    Version
    0.3.0
    License
    GPL-3.0-or-later
    Last updated
    4 months ago
    Downloads
    128

    #himeno/mopress

    wakatime Language License CI

    MoPress is a modern document and static site generator for the MoonBit ecosystem, designed with reference to both mdBook and Hakyll. At its core, it uses an embedded DSL (Domain Specific Language) to declare configurations, while also offering a rich plugin system and customization capabilities to meet various needs.

    #Overview

    MoPress offers two usage modes:

    Book mode — out-of-the-box experience similar to mdBook. Configure via sena.toml and write Markdown. No code required.

    Site mode — declare rules and pipelines by DSL in site.mbtx for full control over how your content is processed and rendered. Inspired by Hakyll's composable compiler design.

    #Features

    • Composable pipeline API — chain transforms with |>
    • Front matter support
    • Built-in preprocessors: callout blocks, math (LaTeX), file includes
    • External preprocessor protocol (stdin/stdout, language-agnostic)
    • WebComponent-friendly — raw HTML in Markdown is preserved, bring your own components
    • Global CSS/JS injection
    • Lightweight template engine built-in
    • Outputs clean static HTML

    #Development

    #Environment

    • MoonBit
    • Just
    • Bun
    • Lefthook

    #Build

    just init just build just test

    #Example

    fn main {
    mopress([
    Glob(
    "*.markdown",
    Text(raw => {
    raw
    |> set_extension("html")
    |> render_markdown_and_frontmatter
    |> load_and_apply_template("test/src/templates/default.html")
    |> import_js("./custom.js")
    |> import_css("./custom.css")
    |> use_js("console.log('hi, moonbit! hi, mopress!')")
    |> use_css("some css code")
    |> unify
    }),
    ),
    Glob("images/*", Binary(raw => raw |> unify)),
    Glob("css/*", Copy),
    ])
    }

    #License

    Under the terms of the GNU General Public License, version 3 (GPLv3).

    build_book

    async fn build_book(config :
    BookConfig
    ) -> Unit

    Runs the full site build pipeline for the given book configuration.

    This orchestrates the entire build process: it parses SUMMARY.md under config.src to build the site's navigation structure, renders a 404 fallback page, and then walks the source directory to render every Markdown article (*.markdown) into its final HTML output alongside any configured static assets. All output is written under config.dest.

    This function does not return a value; build failures are expected to surface as raised errors from the underlying steps (config loading, file I/O, markdown processing, or templating) rather than through a return value.

    process_markdown_page

    Processes a single raw content item (typically a Markdown file, but also used for synthetic pages such as the 404 fallback) into its final rendered Thing, ready to be written to disk.

    The pipeline performed here is:
    1. Separate YAML frontmatter from the raw Markdown body.
    2. Run all configured markdown-text preprocessors on the raw text (see @bridge.run_markdown_preprocessors).
    3. Parse the preprocessed text into a Markdown AST.
    4. Run all configured markdown-ast transformers on the AST (see @bridge.run_markdown_transformers).
    5. Render the transformed AST (together with the original frontmatter) into HTML, and switch the item's extension to .html.
    6. Inject a standard set of template variables derived from config and summary (site metadata, breadcrumb, prev/next navigation, etc.).
    7. Apply the configured HTML template, then inject/import the configured CSS and JS assets and head/body snippets.

    summary is used to resolve the item's position within the site's table of contents, in order to compute breadcrumbs and previous/next links; it is expected to have already been parsed from the book's SUMMARY.md before calling this function.