mdbake 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. mdbake-0.1.1/.github/workflows/ci.yml +35 -0
  2. mdbake-0.1.1/.github/workflows/release.yml +157 -0
  3. mdbake-0.1.1/.gitignore +5 -0
  4. mdbake-0.1.1/PKG-INFO +185 -0
  5. mdbake-0.1.1/README.md +165 -0
  6. mdbake-0.1.1/docs/guide/configuration.md +36 -0
  7. mdbake-0.1.1/docs/guide/middleware.md +49 -0
  8. mdbake-0.1.1/docs/index.md +19 -0
  9. mdbake-0.1.1/main.py +7 -0
  10. mdbake-0.1.1/mdbake.yml +14 -0
  11. mdbake-0.1.1/pyproject.toml +78 -0
  12. mdbake-0.1.1/src/mdbake/__init__.py +3 -0
  13. mdbake-0.1.1/src/mdbake/builder.py +216 -0
  14. mdbake-0.1.1/src/mdbake/builtin/__init__.py +1 -0
  15. mdbake-0.1.1/src/mdbake/builtin/draft.py +29 -0
  16. mdbake-0.1.1/src/mdbake/builtin/frontmatter_defaults.py +38 -0
  17. mdbake-0.1.1/src/mdbake/cli.py +51 -0
  18. mdbake-0.1.1/src/mdbake/config.py +130 -0
  19. mdbake-0.1.1/src/mdbake/files.py +110 -0
  20. mdbake-0.1.1/src/mdbake/frontmatter.py +34 -0
  21. mdbake-0.1.1/src/mdbake/links.py +104 -0
  22. mdbake-0.1.1/src/mdbake/markdown.py +111 -0
  23. mdbake-0.1.1/src/mdbake/middleware.py +131 -0
  24. mdbake-0.1.1/src/mdbake/nav.py +215 -0
  25. mdbake-0.1.1/src/mdbake/page.py +79 -0
  26. mdbake-0.1.1/src/mdbake/theme/base.html +46 -0
  27. mdbake-0.1.1/src/mdbake/theme/nav.html +21 -0
  28. mdbake-0.1.1/src/mdbake/theme/style.css +174 -0
  29. mdbake-0.1.1/src/mdbake/theme/toc.html +8 -0
  30. mdbake-0.1.1/src/mdbake/toc.py +33 -0
  31. mdbake-0.1.1/tests/conftest.py +10 -0
  32. mdbake-0.1.1/tests/fixtures/docs/.hidden.md +0 -0
  33. mdbake-0.1.1/tests/fixtures/docs/draft.md +4 -0
  34. mdbake-0.1.1/tests/fixtures/docs/guide/advanced/tuning.md +3 -0
  35. mdbake-0.1.1/tests/fixtures/docs/guide/index.md +3 -0
  36. mdbake-0.1.1/tests/fixtures/docs/guide/install.md +11 -0
  37. mdbake-0.1.1/tests/fixtures/docs/guide/usage.md +5 -0
  38. mdbake-0.1.1/tests/fixtures/docs/img/logo.svg +1 -0
  39. mdbake-0.1.1/tests/fixtures/docs/index.md +29 -0
  40. mdbake-0.1.1/tests/test_build.py +115 -0
  41. mdbake-0.1.1/tests/test_files.py +43 -0
  42. mdbake-0.1.1/tests/test_frontmatter.py +32 -0
  43. mdbake-0.1.1/tests/test_links.py +74 -0
  44. mdbake-0.1.1/tests/test_middleware.py +109 -0
  45. mdbake-0.1.1/tests/test_nav.py +80 -0
  46. mdbake-0.1.1/tests/test_toc.py +50 -0
  47. mdbake-0.1.1/uv.lock +438 -0
@@ -0,0 +1,35 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ workflow_dispatch:
9
+ # Lets the release workflow run the full CI before publishing.
10
+ workflow_call:
11
+
12
+ jobs:
13
+ lint:
14
+ name: Lint
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v7
18
+ - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
19
+ - uses: astral-sh/ruff-action@v4.0.0
20
+ with:
21
+ src: src/
22
+
23
+ test:
24
+ name: Test (Python ${{ matrix.python-version }})
25
+ runs-on: ubuntu-latest
26
+ strategy:
27
+ matrix:
28
+ python-version: ["3.13","3.14"]
29
+ steps:
30
+ - uses: actions/checkout@v7
31
+ - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
32
+ with:
33
+ python-version: ${{ matrix.python-version }}
34
+ - run: uv sync --locked --group dev
35
+ - run: uv run pytest tests/ -v
@@ -0,0 +1,157 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ # Actions are pinned to commit SHAs (updated by Dependabot).
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ check-version:
13
+ name: Check tag matches package version
14
+ runs-on: ubuntu-latest
15
+ outputs:
16
+ version: ${{ steps.version.outputs.version }}
17
+ prerelease: ${{ steps.version.outputs.prerelease }}
18
+ steps:
19
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
20
+ - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
21
+ - name: Compare tag with pyproject.toml version
22
+ id: version
23
+ env:
24
+ TAG: ${{ github.ref_name }}
25
+ run: |
26
+ version=$(uv version --short)
27
+ if [[ "${TAG}" != "v${version}" ]]; then
28
+ echo "::error::Tag ${TAG} does not match the package version ${version} in pyproject.toml (expected v${version})."
29
+ exit 1
30
+ fi
31
+ echo "version=${version}" >> "$GITHUB_OUTPUT"
32
+ # PEP 440 pre-releases (e.g. 1.0.0a1, 1.0.0b2, 1.0.0rc1, 1.0.0.dev1)
33
+ if [[ "${version}" =~ (a|b|rc|\.dev)[0-9]+$ ]]; then
34
+ echo "prerelease=true" >> "$GITHUB_OUTPUT"
35
+ else
36
+ echo "prerelease=false" >> "$GITHUB_OUTPUT"
37
+ fi
38
+
39
+ # ci:
40
+ # name: CI
41
+ # needs: check-version
42
+ # uses: ./.github/workflows/ci.yml
43
+
44
+ build:
45
+ name: Build distributions
46
+ needs: [check-version]
47
+ runs-on: ubuntu-latest
48
+ steps:
49
+ - uses: actions/checkout@v7
50
+ with:
51
+ persist-credentials: false
52
+ - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
53
+ with:
54
+ enable-cache: false # never build release artifacts from a cache
55
+ python-version: '3.14'
56
+ - name: Build sdist and wheel
57
+ run: uv build --no-sources
58
+ - name: Check wheel
59
+ run: |
60
+ # -I keeps the current directory off sys.path
61
+ # --isolated uses a fresh environment, with nothing reused from a previous run.
62
+ uv run --isolated --no-project --with dist/*.whl \
63
+ python -I -c "import mdbake, importlib.metadata as m; print(m.version('mdbake'))"
64
+ - name: Check distribution metadata
65
+ run: uvx twine check --strict dist/*
66
+ - uses: actions/upload-artifact@v7
67
+ with:
68
+ name: dist
69
+ path: dist/
70
+ if-no-files-found: error
71
+
72
+ github-release:
73
+ name: Create GitHub release
74
+ needs: [check-version, build]
75
+ runs-on: ubuntu-latest
76
+ permissions:
77
+ contents: write
78
+ steps:
79
+ - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
80
+ with:
81
+ name: dist
82
+ path: dist/
83
+ - name: Create release with distributions attached
84
+ env:
85
+ GH_TOKEN: ${{ github.token }}
86
+ TAG: ${{ github.ref_name }}
87
+ PRERELEASE: ${{ needs.check-version.outputs.prerelease }}
88
+ run: |
89
+ flags=()
90
+ if [[ "${PRERELEASE}" == "true" ]]; then
91
+ flags+=(--prerelease)
92
+ fi
93
+ gh release create "${TAG}" dist/* \
94
+ --repo "${GITHUB_REPOSITORY}" \
95
+ --title "${TAG}" \
96
+ --generate-notes \
97
+ --verify-tag \
98
+ "${flags[@]}"
99
+
100
+ # A dry run on TestPyPI; if the upload or the install check fails, nothing is published to PyPI.
101
+ publish-testpypi:
102
+ name: Publish to TestPyPI
103
+ needs: [check-version, build]
104
+ runs-on: ubuntu-latest
105
+ # Trusted publishing, like PyPI below, but configured on test.pypi.org.
106
+ environment:
107
+ name: testpypi
108
+ url: https://test.pypi.org/project/mdbake/${{ needs.check-version.outputs.version }}/
109
+ permissions:
110
+ id-token: write
111
+ steps:
112
+ - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
113
+ with:
114
+ name: dist
115
+ path: dist/
116
+ - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
117
+ with:
118
+ repository-url: https://test.pypi.org/legacy/
119
+ # TestPyPI rejects re-uploads, so re-running a release whose PyPI step failed would fail here.
120
+ skip-existing: true
121
+ # - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
122
+ # with:
123
+ # enable-cache: false
124
+ # python-version: "3.14"
125
+ # - name: Install from TestPyPI
126
+ # env:
127
+ # VERSION: ${{ needs.check-version.outputs.version }}
128
+ # # Only TestPyPI is used as the index, which works because the package has no
129
+ # # required dependencies. New uploads can take a minute to appear, so retry.
130
+ # run: |
131
+ # for i in 1 2 3; do
132
+ # uv run --no-project --refresh \
133
+ # --index https://test.pypi.org/simple/ \
134
+ # --index-strategy unsafe-best-match \
135
+ # --with "mdbake==${VERSION}" \
136
+ # python -c "import mdbake; print(mdbake.__version__)" && exit 0
137
+ # echo "Not available yet, retrying..."; sleep 20
138
+ # done
139
+ # exit 1
140
+
141
+ publish-pypi:
142
+ name: Publish to PyPI
143
+ needs: [check-version, publish-testpypi]
144
+ runs-on: ubuntu-latest
145
+ environment:
146
+ name: pypi
147
+ url: https://pypi.org/project/mdbake/${{ needs.check-version.outputs.version }}/
148
+ permissions:
149
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
150
+ steps:
151
+ - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
152
+ with:
153
+ name: dist
154
+ path: dist/
155
+ - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
156
+ with:
157
+ skip-existing: true
@@ -0,0 +1,5 @@
1
+ .idea/
2
+ .venv/
3
+ node_modules/
4
+ .DS_Store
5
+ __pycache__
mdbake-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.5
2
+ Name: mdbake
3
+ Version: 0.1.1
4
+ Summary: Bake HTML sites from MarkDown
5
+ Author-email: fm-labs <mdbake@fmlabs.dev>
6
+ License-Expression: MIT
7
+ Classifier: Operating System :: OS Independent
8
+ Classifier: Programming Language :: Python :: 3
9
+ Requires-Python: <4.0,>=3.13
10
+ Requires-Dist: click>=8.1
11
+ Requires-Dist: jinja2>=3.1
12
+ Requires-Dist: linkify-it-py>=2.0
13
+ Requires-Dist: markdown-it-py>=3.0
14
+ Requires-Dist: mdit-py-plugins>=0.4
15
+ Requires-Dist: pygments>=2.15
16
+ Requires-Dist: pyyaml>=6.0
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=9; extra == 'dev'
19
+ Description-Content-Type: text/markdown
20
+
21
+ # mdbake
22
+
23
+ A minimal Markdown → HTML documentation site generator.
24
+
25
+ - Reads all `*.md` files recursively from a docs directory
26
+ - Renders GitHub-flavored Markdown: tables, task lists, strikethrough, autolinks, footnotes, definition lists, Pygments code highlighting
27
+ - Builds navigation from `mdbake.yml`, or automatically from the directory tree
28
+ - Rewrites links between `.md` files into relative `.html` links and warns about broken links and missing `#anchors`
29
+ - Generates an in-page table of contents from headings
30
+ - Extensible through a middleware chain (frontmatter processing, text substitution, HTML post-processing, ...)
31
+
32
+ All output links are relative, so the generated site works when opened straight from disk (`file://`).
33
+
34
+ ## Installation
35
+
36
+ Requires Python 3.10+.
37
+
38
+ ```bash
39
+ pip install -e . # or: uv pip install -e .
40
+ pip install -e '.[dev]' # with pytest
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ```bash
46
+ mdbake build # uses ./mdbake.yml if present, else docs/ -> site/
47
+ mdbake build -f path/to/mdbake.yml # explicit config file
48
+ mdbake build -d docs -o site # override docs_dir / site_dir
49
+ mdbake build --clean --strict # wipe site_dir first; fail on warnings
50
+ ```
51
+
52
+ | Option | Meaning |
53
+ |---|---|
54
+ | `-f, --config` | Config file (default: `./mdbake.yml` if it exists) |
55
+ | `-d, --docs-dir` | Markdown source directory (overrides config) |
56
+ | `-o, --site-dir` | Output directory (overrides config) |
57
+ | `--clean` | Delete `site_dir` before building (refuses if it contains `docs_dir`) |
58
+ | `-s, --strict` | Exit with an error if there were any warnings |
59
+ | `-v, --verbose` / `-q, --quiet` | More / less output |
60
+
61
+ ## Configuration
62
+
63
+ `mdbake.yml` (paths are relative to the config file):
64
+
65
+ ```yaml
66
+ site_name: My Docs
67
+ docs_dir: docs
68
+ site_dir: site
69
+ templates_dir: null # optional theme override
70
+ toc_depth: 3 # deepest heading level in "On this page"
71
+ nav: # optional; auto-generated from the dir tree if omitted
72
+ - Home: index.md
73
+ - Guide:
74
+ - guide/install.md # title taken from the page
75
+ - Usage: guide/usage.md # explicit title
76
+ - GitHub: https://github.com/example/project
77
+ middleware:
78
+ - mdbake.builtin.draft
79
+ - path: mdbake.builtin.frontmatter_defaults:FrontmatterDefaults
80
+ options: {defaults: {author: Docs Team}, required: [title]}
81
+ extra: # free-form, available in templates
82
+ lang: en
83
+ ```
84
+
85
+ ### Pages and URLs
86
+
87
+ | Source | Output |
88
+ |---|---|
89
+ | `foo/bar.md` | `foo/bar.html` |
90
+ | `foo/index.md` or `foo/README.md` | `foo/index.html` |
91
+ | other files (images, ...) | copied as-is |
92
+
93
+ Dotfiles and dot-directories are ignored. Optional YAML frontmatter at the top of a page is available as `page.meta`.
94
+
95
+ **Page title**: explicit nav title → frontmatter `title` → first `# H1` → file name.
96
+
97
+ ### Navigation
98
+
99
+ Without `nav`, the directory tree is used: the root `index.md` first, then pages, then
100
+ sub-directories as sections (a directory's `index.md` becomes the section link). Add
101
+ `nav_order: <number>` to a page's frontmatter to reorder. Pages missing from an explicit
102
+ `nav` are still built, with a warning.
103
+
104
+ ## Middleware
105
+
106
+ A middleware is any module or class exposing some of these hooks. A hook returns the new
107
+ value, or `None` to keep the current one. Middleware runs in config order.
108
+
109
+ | Hook | Typical use |
110
+ |---|---|
111
+ | `on_config(config)` | tweak settings (`return config.replace(...)`) |
112
+ | `on_files(files, *, config)` | add/remove files |
113
+ | `on_page_source(page, *, site)` | frontmatter processing; set `page.skip = True` to drop a page |
114
+ | `on_page_markdown(markdown, *, page, site)` | macros, text substitution |
115
+ | `on_page_html(html, *, page, site)` | post-process HTML |
116
+ | `on_nav(nav, *, site)` | reorder or hide navigation |
117
+ | `on_page_context(ctx, *, page, site)` | extra template variables |
118
+ | `on_post_build(*, site)` | sitemap, search index, ... |
119
+ | `md_setup(md)` | register markdown-it plugins |
120
+
121
+ Specs are dotted paths with an optional `:Attr`. Classes are instantiated with `options`
122
+ as keyword arguments; modules are used as-is. The config file's directory is on
123
+ `sys.path`, so a local `myhooks.py` next to `mdbake.yml` can be loaded directly:
124
+
125
+ ```python
126
+ # myhooks.py
127
+ from datetime import date
128
+
129
+
130
+ class Stamp:
131
+ def __init__(self, format="%Y-%m-%d"):
132
+ self.format = format
133
+
134
+ def on_page_html(self, html, *, page, site):
135
+ return html + f"<p><small>Built {date.today():{self.format}}</small></p>"
136
+ ```
137
+
138
+ ```yaml
139
+ middleware:
140
+ - path: myhooks:Stamp
141
+ options: {format: "%d.%m.%Y"}
142
+ ```
143
+
144
+ Built-ins:
145
+
146
+ - `mdbake.builtin.draft`: drops pages with `draft: true` (`mdbake.builtin.draft:Draft` with `include_drafts: true` keeps them)
147
+ - `mdbake.builtin.frontmatter_defaults:FrontmatterDefaults`: options `defaults`, `required`, `strict`
148
+
149
+ ## Theming
150
+
151
+ The built-in theme (in `src/mdbake/theme/`) has a left sidebar nav, an "On this page" TOC,
152
+ prev/next links, light/dark mode via `prefers-color-scheme`, and a mobile layout. To customize
153
+ it, set `templates_dir` and put any of `base.html`, `nav.html`, `toc.html` or `style.css`
154
+ there; missing files fall back to the built-in ones.
155
+
156
+ Template context: `page`, `nav`, `toc`, `config`, `site_name`, `extra`, `base_url`,
157
+ `assets_url`, `home_url`, and `url(target)` to make a site-root URL relative to the current page.
158
+
159
+ ## Development
160
+
161
+ ```bash
162
+ pytest
163
+ mdbake build -d tests/fixtures/docs -o /tmp/fixture-site
164
+ ```
165
+
166
+ Project layout:
167
+
168
+ ```
169
+ src/mdbake/
170
+ cli.py command line interface
171
+ config.py mdbake.yml loading
172
+ files.py file discovery, source → output paths
173
+ frontmatter.py YAML frontmatter splitting
174
+ markdown.py markdown-it setup, heading ids, highlighting
175
+ links.py relative link rewriting
176
+ toc.py table of contents
177
+ nav.py navigation (explicit / auto), prev/next
178
+ page.py Page model
179
+ middleware.py middleware loader and pipeline
180
+ builder.py build orchestration
181
+ builtin/ bundled middleware
182
+ theme/ default templates and CSS
183
+ ```
184
+
185
+ See [BUILDME.md](BUILDME.md) for the original design plan.
mdbake-0.1.1/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # mdbake
2
+
3
+ A minimal Markdown → HTML documentation site generator.
4
+
5
+ - Reads all `*.md` files recursively from a docs directory
6
+ - Renders GitHub-flavored Markdown: tables, task lists, strikethrough, autolinks, footnotes, definition lists, Pygments code highlighting
7
+ - Builds navigation from `mdbake.yml`, or automatically from the directory tree
8
+ - Rewrites links between `.md` files into relative `.html` links and warns about broken links and missing `#anchors`
9
+ - Generates an in-page table of contents from headings
10
+ - Extensible through a middleware chain (frontmatter processing, text substitution, HTML post-processing, ...)
11
+
12
+ All output links are relative, so the generated site works when opened straight from disk (`file://`).
13
+
14
+ ## Installation
15
+
16
+ Requires Python 3.10+.
17
+
18
+ ```bash
19
+ pip install -e . # or: uv pip install -e .
20
+ pip install -e '.[dev]' # with pytest
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ mdbake build # uses ./mdbake.yml if present, else docs/ -> site/
27
+ mdbake build -f path/to/mdbake.yml # explicit config file
28
+ mdbake build -d docs -o site # override docs_dir / site_dir
29
+ mdbake build --clean --strict # wipe site_dir first; fail on warnings
30
+ ```
31
+
32
+ | Option | Meaning |
33
+ |---|---|
34
+ | `-f, --config` | Config file (default: `./mdbake.yml` if it exists) |
35
+ | `-d, --docs-dir` | Markdown source directory (overrides config) |
36
+ | `-o, --site-dir` | Output directory (overrides config) |
37
+ | `--clean` | Delete `site_dir` before building (refuses if it contains `docs_dir`) |
38
+ | `-s, --strict` | Exit with an error if there were any warnings |
39
+ | `-v, --verbose` / `-q, --quiet` | More / less output |
40
+
41
+ ## Configuration
42
+
43
+ `mdbake.yml` (paths are relative to the config file):
44
+
45
+ ```yaml
46
+ site_name: My Docs
47
+ docs_dir: docs
48
+ site_dir: site
49
+ templates_dir: null # optional theme override
50
+ toc_depth: 3 # deepest heading level in "On this page"
51
+ nav: # optional; auto-generated from the dir tree if omitted
52
+ - Home: index.md
53
+ - Guide:
54
+ - guide/install.md # title taken from the page
55
+ - Usage: guide/usage.md # explicit title
56
+ - GitHub: https://github.com/example/project
57
+ middleware:
58
+ - mdbake.builtin.draft
59
+ - path: mdbake.builtin.frontmatter_defaults:FrontmatterDefaults
60
+ options: {defaults: {author: Docs Team}, required: [title]}
61
+ extra: # free-form, available in templates
62
+ lang: en
63
+ ```
64
+
65
+ ### Pages and URLs
66
+
67
+ | Source | Output |
68
+ |---|---|
69
+ | `foo/bar.md` | `foo/bar.html` |
70
+ | `foo/index.md` or `foo/README.md` | `foo/index.html` |
71
+ | other files (images, ...) | copied as-is |
72
+
73
+ Dotfiles and dot-directories are ignored. Optional YAML frontmatter at the top of a page is available as `page.meta`.
74
+
75
+ **Page title**: explicit nav title → frontmatter `title` → first `# H1` → file name.
76
+
77
+ ### Navigation
78
+
79
+ Without `nav`, the directory tree is used: the root `index.md` first, then pages, then
80
+ sub-directories as sections (a directory's `index.md` becomes the section link). Add
81
+ `nav_order: <number>` to a page's frontmatter to reorder. Pages missing from an explicit
82
+ `nav` are still built, with a warning.
83
+
84
+ ## Middleware
85
+
86
+ A middleware is any module or class exposing some of these hooks. A hook returns the new
87
+ value, or `None` to keep the current one. Middleware runs in config order.
88
+
89
+ | Hook | Typical use |
90
+ |---|---|
91
+ | `on_config(config)` | tweak settings (`return config.replace(...)`) |
92
+ | `on_files(files, *, config)` | add/remove files |
93
+ | `on_page_source(page, *, site)` | frontmatter processing; set `page.skip = True` to drop a page |
94
+ | `on_page_markdown(markdown, *, page, site)` | macros, text substitution |
95
+ | `on_page_html(html, *, page, site)` | post-process HTML |
96
+ | `on_nav(nav, *, site)` | reorder or hide navigation |
97
+ | `on_page_context(ctx, *, page, site)` | extra template variables |
98
+ | `on_post_build(*, site)` | sitemap, search index, ... |
99
+ | `md_setup(md)` | register markdown-it plugins |
100
+
101
+ Specs are dotted paths with an optional `:Attr`. Classes are instantiated with `options`
102
+ as keyword arguments; modules are used as-is. The config file's directory is on
103
+ `sys.path`, so a local `myhooks.py` next to `mdbake.yml` can be loaded directly:
104
+
105
+ ```python
106
+ # myhooks.py
107
+ from datetime import date
108
+
109
+
110
+ class Stamp:
111
+ def __init__(self, format="%Y-%m-%d"):
112
+ self.format = format
113
+
114
+ def on_page_html(self, html, *, page, site):
115
+ return html + f"<p><small>Built {date.today():{self.format}}</small></p>"
116
+ ```
117
+
118
+ ```yaml
119
+ middleware:
120
+ - path: myhooks:Stamp
121
+ options: {format: "%d.%m.%Y"}
122
+ ```
123
+
124
+ Built-ins:
125
+
126
+ - `mdbake.builtin.draft`: drops pages with `draft: true` (`mdbake.builtin.draft:Draft` with `include_drafts: true` keeps them)
127
+ - `mdbake.builtin.frontmatter_defaults:FrontmatterDefaults`: options `defaults`, `required`, `strict`
128
+
129
+ ## Theming
130
+
131
+ The built-in theme (in `src/mdbake/theme/`) has a left sidebar nav, an "On this page" TOC,
132
+ prev/next links, light/dark mode via `prefers-color-scheme`, and a mobile layout. To customize
133
+ it, set `templates_dir` and put any of `base.html`, `nav.html`, `toc.html` or `style.css`
134
+ there; missing files fall back to the built-in ones.
135
+
136
+ Template context: `page`, `nav`, `toc`, `config`, `site_name`, `extra`, `base_url`,
137
+ `assets_url`, `home_url`, and `url(target)` to make a site-root URL relative to the current page.
138
+
139
+ ## Development
140
+
141
+ ```bash
142
+ pytest
143
+ mdbake build -d tests/fixtures/docs -o /tmp/fixture-site
144
+ ```
145
+
146
+ Project layout:
147
+
148
+ ```
149
+ src/mdbake/
150
+ cli.py command line interface
151
+ config.py mdbake.yml loading
152
+ files.py file discovery, source → output paths
153
+ frontmatter.py YAML frontmatter splitting
154
+ markdown.py markdown-it setup, heading ids, highlighting
155
+ links.py relative link rewriting
156
+ toc.py table of contents
157
+ nav.py navigation (explicit / auto), prev/next
158
+ page.py Page model
159
+ middleware.py middleware loader and pipeline
160
+ builder.py build orchestration
161
+ builtin/ bundled middleware
162
+ theme/ default templates and CSS
163
+ ```
164
+
165
+ See [BUILDME.md](BUILDME.md) for the original design plan.
@@ -0,0 +1,36 @@
1
+ ---
2
+ title: Configuration
3
+ ---
4
+ # Configuration file
5
+
6
+ `mdbake.yml` lives next to your project; paths in it are relative to the file.
7
+
8
+ | Key | Default | Meaning |
9
+ |---|---|---|
10
+ | `site_name` | `Documentation` | Shown in the top bar and page titles |
11
+ | `docs_dir` | `docs` | Markdown sources |
12
+ | `site_dir` | `site` | Output directory |
13
+ | `templates_dir` | — | Overrides `base.html`, `nav.html`, `toc.html`, `style.css` |
14
+ | `nav` | auto | Explicit navigation (see below) |
15
+ | `middleware` | `[]` | Middleware chain (see [Middleware](middleware.md)) |
16
+ | `toc_depth` | `3` | Deepest heading level in "On this page" |
17
+ | `extra` | `{}` | Free-form, passed to templates (`extra.lang` sets `<html lang>`) |
18
+
19
+ ## Navigation
20
+
21
+ ```yaml
22
+ nav:
23
+ - Home: index.md
24
+ - Guide:
25
+ - guide/install.md # title taken from the page
26
+ - Usage: guide/usage.md # explicit title
27
+ - GitHub: https://github.com/example
28
+ ```
29
+
30
+ Without `nav`, the directory tree is used: `index.md`/`README.md` first, then pages,
31
+ then sub-directories (whose `index.md` becomes the section link). Set `nav_order: <n>`
32
+ in frontmatter to reorder. Pages missing from an explicit `nav` are still built.
33
+
34
+ ## Page titles
35
+
36
+ Explicit nav title → frontmatter `title` → first `# H1` → file name.
@@ -0,0 +1,49 @@
1
+ # Middleware
2
+
3
+ Middleware is any module or class exposing some of these hooks. A hook returns the new
4
+ value, or `None` to keep it unchanged; middleware runs in config order.
5
+
6
+ | Hook | Use |
7
+ |---|---|
8
+ | `on_config(config)` | tweak settings (`config.replace(...)`) |
9
+ | `on_files(files, *, config)` | add/remove files |
10
+ | `on_page_source(page, *, site)` | frontmatter processing; set `page.skip = True` to drop |
11
+ | `on_page_markdown(markdown, *, page, site)` | text substitution, macros |
12
+ | `on_page_html(html, *, page, site)` | post-process HTML |
13
+ | `on_nav(nav, *, site)` | reorder/hide navigation |
14
+ | `on_page_context(ctx, *, page, site)` | extra template variables |
15
+ | `on_post_build(*, site)` | sitemap, search index, ... |
16
+ | `md_setup(md)` | register markdown-it plugins |
17
+
18
+ ## Configuring
19
+
20
+ ```yaml
21
+ middleware:
22
+ - mdbake.builtin.draft # a module
23
+ - myhooks:Stamp # a class, instantiated without options
24
+ - path: myhooks:Stamp
25
+ options: {format: "%Y-%m-%d"} # passed as keyword arguments
26
+ ```
27
+
28
+ The config file's directory is on `sys.path`, so a local `myhooks.py` just works.
29
+
30
+ ## Example
31
+
32
+ ```python
33
+ from datetime import date
34
+
35
+
36
+ class Stamp:
37
+ def __init__(self, format="%Y-%m-%d"):
38
+ self.format = format
39
+
40
+ def on_page_html(self, html, *, page, site):
41
+ return html + f"<p><small>Built {date.today():{self.format}}</small></p>"
42
+ ```
43
+
44
+ ## Built-ins
45
+
46
+ - `mdbake.builtin.draft` — drops pages with `draft: true` (`Draft(include_drafts=True)` to keep them)
47
+ - `mdbake.builtin.frontmatter_defaults:FrontmatterDefaults` — `defaults`, `required`, `strict` options
48
+
49
+ Back to [the configuration](configuration.md#navigation).
@@ -0,0 +1,19 @@
1
+ # mdbake
2
+
3
+ A minimal Markdown → HTML documentation generator.
4
+
5
+ - Reads all `*.md` files from `docs_dir` recursively
6
+ - Renders GitHub-flavored Markdown (tables, task lists, strikethrough, autolinks, footnotes)
7
+ - Builds navigation from [`mdbake.yml`](guide/configuration.md#navigation) or the directory tree
8
+ - Rewrites links between `.md` files to relative `.html` links, warning on broken targets and anchors
9
+ - Extensible through a [middleware chain](guide/middleware.md)
10
+
11
+ ## Quick start
12
+
13
+ ```bash
14
+ pip install -e .
15
+ mdbake build # uses ./mdbake.yml if present
16
+ mdbake build -d docs -o site --strict
17
+ ```
18
+
19
+ Open `site/index.html` directly from disk: all links are relative.
mdbake-0.1.1/main.py ADDED
@@ -0,0 +1,7 @@
1
+ import sys
2
+ sys.path.append("src")
3
+
4
+ from mdbake.cli import main
5
+
6
+ if __name__ == '__main__':
7
+ main()
@@ -0,0 +1,14 @@
1
+ site_name: mdbake
2
+ docs_dir: docs
3
+ site_dir: dist/site
4
+ nav:
5
+ - Home: index.md
6
+ - Guide:
7
+ - guide/configuration.md
8
+ - guide/middleware.md
9
+ - markdown-it-py: https://github.com/executablebooks/markdown-it-py
10
+ middleware:
11
+ - mdbake.builtin.draft
12
+ - path: mdbake.builtin.frontmatter_defaults:FrontmatterDefaults
13
+ options:
14
+ defaults: {author: mdbake}