mopress

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

docs
utils
cli
functional
site-generator
website
moon add himeno/mopress@0.4.0
Download zip
Author
Version
0.4.0
License
GPL-3.0-or-later
Last updated
last month
Downloads
24
README

#MoPress

MoonBit License CI TypeScript Codeberg

MoPress is a modern documentation and general-purpose static site generator for the MoonBit ecosystem. Its design draws inspiration from both mdBook and Hakyll. At its core, MoPress uses an embedded DSL (Domain-Specific Language) for declarative configuration and functional processing pipelines to express build workflows. It also provides a rich, language-agnostic plugin system and extensive customization capabilities to accommodate a wide range of use cases.

#Why MoPress?

If all you want is to quickly write some documentation or publish a blog, you should not have to reinvent the wheel by building an entire build system from scratch. But when your requirements go beyond writing Markdown and applying templates, your tools should not get in your way—nor should you have to repeatedly deal with tedious implementation details.

MoPress attempts to serve both cases by providing two complementary modes of use:

  • Book Mode: An out-of-the-box experience similar to mdBook. All you need is a sena.toml configuration file and a collection of Markdown files—no code required. At the same time, it provides many capabilities beyond mdBook, including multiple plugin systems, code injection, custom templates, front matter, and AST transformations (i.e. transformers).

  • Site Mode: Declare Rules and processing Pipelines through a DSL in site.mbtx. Build workflows are expressed using a rich set of atomic Steps, giving you complete control over how content is processed and rendered. Through functional composition, Steps can be combined freely and flexibly for virtually unlimited expressiveness, without requiring you to concern yourself with tedious low-level implementation details.

Both modes share the same underlying capabilities, including Markdown parsing, the template engine, and the external plugin protocol. In fact, Site Mode is designed as a general-purpose static site generator, while Book Mode is both a best-practice example built on top of Site Mode and an out-of-the-box generator that presets a complete build workflow for book-style documentation websites.

#Features

  • Composable pipeline API — chain transforms with |>
  • Functional programming style
  • DSL for configuration and pipeline definition
  • 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

#Installation

#By MoonBit

moon add himeno/mopress

#Release

Please refer to the release page for the latest release.

#Start By Book Mode

mopress init mopress build mopress serve

title = "MoPress Doc" description = "A modern documentation and static site generator for the MoonBit ecosystem, inspired by mdBook and Hakyll" keywords = "Documentation,Static Site Generator,SSG,MoonBit,MoonLang,Moon,Functional,Haskell,mdBook,Hakyll" favicon = "https://himeno-sena.com/favicon.ico" logo = "https://himeno-sena.com/favicon.ico" authors = ["Himeno Sena"] language = "en" src = "./" dest = "./dest" repository = "https://github.com/biyuehu/mopress" [features] highlight-enabled = false highlight-theme = "github" mathjax-enabled = false [extensions] template = "templates/default.html" assets = ["images/**/*", "styles/**/*", "scripts/**/*", "plugins/runtime/**/*"] inject-head = [] inject-body = [] use-js = ["console.log('Hello, MoPress!');"] use-css = [] import-css = [] import-js = [] preprocessors = [] transformers = []

src/ ├── SUMMARY.md └── intro.md

#Start By Site Mode

mopress new my-book cd my-book moon run --target native site.mbtx build moon run --target native site.mbtx serve

import {
"himeno/mopress/core",
"moonbitlang/async",
}

///|
async fn main {
@core.mopress([
Glob(
"**/*.md",
Text(raw => {
raw
|> @core.set_extension(".html")
|> @core.render_markdown_and_frontmatter
|> @core.load_and_apply_template("templates/default.html")
|> @core.use_js(["console.log('hi, moonbit! hi, mopress!')"])
|> @core.unify
}),
),
Glob("styles/**/*", Copy),
])
}

#Supports

#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.

#
version

let version : String