|
| 1 | +# mkdocs-zip-bundle-plugin |
| 2 | + |
| 3 | +Turn code blocks into **downloadable files** — directly from your MkDocs docs. Tag any fenced code block with a bundle ID and filename and the plugin injects a download button. Group multiple blocks under one ID to produce a **ZIP archive**. Pair with [`mkdocs-placeholder-plugin`](https://github.com/six-two/mkdocs-placeholder-plugin) and the downloaded files contain the reader's own values, not your defaults. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Live demo |
| 8 | + |
| 9 | +Edit the fields below. Every code block on this page updates live. Click any download button — the file you get has **your values** in it, not the defaults. |
| 10 | + |
| 11 | +<div class="auto-input-table" data-columns="description,input"></div> |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +### Single file download |
| 16 | + |
| 17 | +Add `data-zip-bundle` and `data-zip-filename` to a code block. The plugin injects a download button — no ZIP, just the raw file. |
| 18 | + |
| 19 | +~~~markdown |
| 20 | +```yaml { data-zip-bundle="compose-only" data-zip-filename="compose.yaml" } |
| 21 | +services: |
| 22 | + @APP_NAME@: |
| 23 | + ... |
| 24 | +``` |
| 25 | +~~~ |
| 26 | + |
| 27 | +**Result:** |
| 28 | + |
| 29 | +```yaml { data-zip-bundle="compose-only" data-zip-filename="compose.yaml" } |
| 30 | +services: |
| 31 | + @APP_NAME@: |
| 32 | + image: ghcr.io/example/@APP_NAME@:latest |
| 33 | + container_name: @APP_NAME@ |
| 34 | + environment: |
| 35 | + - PUID=@PUID@ |
| 36 | + - PGID=@PGID@ |
| 37 | + - TZ=@TZ@ |
| 38 | + ports: |
| 39 | + - "@PORT@:8080" |
| 40 | + volumes: |
| 41 | + - @CONFIG_PATH@:/config |
| 42 | + restart: unless-stopped |
| 43 | +``` |
| 44 | +
|
| 45 | +--- |
| 46 | +
|
| 47 | +### Multi-file ZIP bundle |
| 48 | +
|
| 49 | +Use the **same `data-zip-bundle` ID** on multiple blocks. The button appears after the last one and downloads all files as a single ZIP. |
| 50 | + |
| 51 | +~~~markdown |
| 52 | +```yaml { data-zip-bundle="full-bundle" data-zip-filename="compose.yaml" } |
| 53 | +... |
| 54 | +``` |
| 55 | + |
| 56 | +```ini { data-zip-bundle="full-bundle" data-zip-filename="app.env" } |
| 57 | +... |
| 58 | +``` |
| 59 | + |
| 60 | +```bash { data-zip-bundle="full-bundle" data-zip-filename="setup.sh" } |
| 61 | +... |
| 62 | +``` |
| 63 | +~~~ |
| 64 | + |
| 65 | +**Result:** |
| 66 | + |
| 67 | +```yaml { data-zip-bundle="full-bundle" data-zip-filename="compose.yaml" } |
| 68 | +services: |
| 69 | + @APP_NAME@: |
| 70 | + image: ghcr.io/example/@APP_NAME@:latest |
| 71 | + container_name: @APP_NAME@ |
| 72 | + environment: |
| 73 | + - PUID=@PUID@ |
| 74 | + - PGID=@PGID@ |
| 75 | + - TZ=@TZ@ |
| 76 | + ports: |
| 77 | + - "@PORT@:8080" |
| 78 | + volumes: |
| 79 | + - @CONFIG_PATH@:/config |
| 80 | + restart: unless-stopped |
| 81 | +``` |
| 82 | + |
| 83 | +```ini { data-zip-bundle="full-bundle" data-zip-filename="app.env" } |
| 84 | +APP_NAME=@APP_NAME@ |
| 85 | +HOST=@HOST_IP@ |
| 86 | +PORT=@PORT@ |
| 87 | +CONFIG_PATH=@CONFIG_PATH@ |
| 88 | +TZ=@TZ@ |
| 89 | +PUID=@PUID@ |
| 90 | +PGID=@PGID@ |
| 91 | +``` |
| 92 | + |
| 93 | +```bash { data-zip-bundle="full-bundle" data-zip-filename="setup.sh" } |
| 94 | +#!/bin/sh |
| 95 | +set -e |
| 96 | +
|
| 97 | +mkdir -p @CONFIG_PATH@ |
| 98 | +chown @PUID@:@PGID@ @CONFIG_PATH@ |
| 99 | +
|
| 100 | +podman compose up -d |
| 101 | +echo "Done. Access at http://@HOST_IP@:@PORT@" |
| 102 | +``` |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +### Nested directories in the ZIP |
| 107 | + |
| 108 | +Use paths as filenames — the plugin creates the directory structure inside the ZIP automatically. |
| 109 | + |
| 110 | +~~~markdown |
| 111 | +```yaml { data-zip-bundle="nested" data-zip-filename="config/app.yaml" } |
| 112 | +... |
| 113 | +``` |
| 114 | + |
| 115 | +```bash { data-zip-bundle="nested" data-zip-filename="scripts/setup.sh" } |
| 116 | +... |
| 117 | +``` |
| 118 | +~~~ |
| 119 | + |
| 120 | +**Result:** |
| 121 | + |
| 122 | +```yaml { data-zip-bundle="nested" data-zip-filename="config/app.yaml" } |
| 123 | +server: |
| 124 | + host: @HOST_IP@ |
| 125 | + port: @PORT@ |
| 126 | + name: @APP_NAME@ |
| 127 | +timezone: @TZ@ |
| 128 | +``` |
| 129 | + |
| 130 | +```bash { data-zip-bundle="nested" data-zip-filename="scripts/setup.sh" } |
| 131 | +#!/bin/sh |
| 132 | +mkdir -p @CONFIG_PATH@/config |
| 133 | +cp config/app.yaml @CONFIG_PATH@/config/ |
| 134 | +podman compose up -d |
| 135 | +``` |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +### Custom button label |
| 140 | + |
| 141 | +Use `data-zip-label` to override the auto-generated button text. |
| 142 | + |
| 143 | +~~~markdown |
| 144 | +```yaml { data-zip-bundle="labeled" data-zip-filename="compose.yaml" data-zip-label="Download my config" } |
| 145 | +... |
| 146 | +``` |
| 147 | +~~~ |
| 148 | + |
| 149 | +**Result:** |
| 150 | + |
| 151 | +```yaml { data-zip-bundle="labeled" data-zip-filename="compose.yaml" data-zip-label="Download my config" } |
| 152 | +services: |
| 153 | + @APP_NAME@: |
| 154 | + image: ghcr.io/example/@APP_NAME@:latest |
| 155 | + ports: |
| 156 | + - "@PORT@:8080" |
| 157 | +``` |
| 158 | + |
| 159 | +--- |
| 160 | + |
| 161 | +## Installation |
| 162 | + |
| 163 | +```bash |
| 164 | +pip install mkdocs-zip-bundle-plugin mkdocs-placeholder-plugin |
| 165 | +``` |
| 166 | + |
| 167 | +## Full setup |
| 168 | + |
| 169 | +**`mkdocs.yml`** |
| 170 | + |
| 171 | +```yaml |
| 172 | +markdown_extensions: |
| 173 | + - attr_list # required — reads data-zip-* attributes |
| 174 | + - pymdownx.superfences |
| 175 | +
|
| 176 | +plugins: |
| 177 | + - search |
| 178 | + - zip-bundle: |
| 179 | + include_jszip: true |
| 180 | + - placeholder: |
| 181 | + placeholder_file: placeholder-plugin.yaml |
| 182 | +``` |
| 183 | + |
| 184 | +**`placeholder-plugin.yaml`** |
| 185 | + |
| 186 | +```yaml |
| 187 | +settings: |
| 188 | + normal_prefix: "@" |
| 189 | + normal_suffix: "@" |
| 190 | + auto_placeholder_tables: false # place the table manually where you want it |
| 191 | +
|
| 192 | +placeholders: |
| 193 | + APP_NAME: |
| 194 | + default: myapp |
| 195 | + description: Application name |
| 196 | + PORT: |
| 197 | + default: "8080" |
| 198 | + description: Application port |
| 199 | + HOST_IP: |
| 200 | + default: 192.168.1.100 |
| 201 | + description: Host IP address |
| 202 | +``` |
| 203 | + |
| 204 | +**Your page** |
| 205 | + |
| 206 | +Place the input table wherever you want it in your markdown: |
| 207 | + |
| 208 | +```markdown |
| 209 | +<div class="auto-input-table" data-columns="description,input"></div> |
| 210 | +``` |
| 211 | + |
| 212 | +Then tag your code blocks. The download button is injected automatically. At click time, the button reads the **live rendered text** — so whatever the reader typed into the inputs is what ends up in the downloaded file. |
| 213 | + |
| 214 | +[Configuration reference →](configuration.md){ .md-button } |
0 commit comments