Skip to content

Commit d6c6fc4

Browse files
authored
add docs for Directives extension (#159)
* add docs for Directives extension Signed-off-by: alexvoss <alex@corealization.com>
1 parent 28fab68 commit d6c6fc4

4 files changed

Lines changed: 224 additions & 0 deletions

File tree

docs/assets/deployment-guide.zip

5.69 KB
Binary file not shown.

docs/assets/images/directives.webp

3.2 MB
Loading

docs/authoring/directives.md

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
---
2+
icon: lucide/git-branch
3+
tags:
4+
- Extensions
5+
- Authoring
6+
status: new
7+
---
8+
9+
# Directives
10+
11+
Directives let you build focused variants of a documentation site from one set
12+
of Markdown sources. Use them to select block content, insert values, and
13+
reuse whole source files for products, editions, deployment models, or other
14+
named variants.
15+
16+
!!! info "Preview in Zensical Spark"
17+
18+
The Directives extension is currently available only in [Zensical Spark].
19+
We will add more functionality based on feedback from Spark members.
20+
You can explore our example project within Zensical Studio (see below).
21+
22+
## See it in Zensical Studio
23+
24+
[Zensical Studio] provides syntax highlighting and variant-aware Markdown
25+
previews for directives (click to enlarge):
26+
27+
![shows switching between variants and how the source documents imports
28+
reusable content](../assets/images/directives.webp)
29+
30+
You can explore our example project [deployment-guide example] directly in
31+
Zensical Studio. You do not need to install the Directives extension - or even
32+
Zensical itself.
33+
34+
Switch between the `cloud` and `self-hosted` variants to see the exact content
35+
that each build produces. Follow links to explore how the project makes use of
36+
conditional directives and `@use` to reuse content and adapt it to ensure that
37+
each variant contains the appropriate content.
38+
39+
## Installation
40+
41+
Download the wheel provided within Zensical Spark, then install it into the
42+
Python environment that you use to build your site:
43+
44+
``` sh
45+
pip install path/to/zensical_directives-0.1.0-py3-none-any.whl
46+
```
47+
48+
## Configuration
49+
50+
Enable the extension in `zensical.toml`:
51+
52+
``` toml
53+
[project.markdown_extensions]
54+
zensical.directives = {}
55+
```
56+
57+
Create `catalog.toml` in the project root. It declares the values that source
58+
files may use and the named variants that select them:
59+
60+
``` toml
61+
default_variant = "cloud"
62+
63+
[variables.deployment]
64+
values = ["cloud", "self-hosted"]
65+
66+
[variables.authentication]
67+
values = ["single-sign-on", "local"]
68+
69+
[variants.cloud]
70+
deployment = "cloud"
71+
authentication = "single-sign-on"
72+
73+
[variants.self-hosted]
74+
deployment = "self-hosted"
75+
authentication = "local"
76+
```
77+
78+
### The catalog
79+
80+
`catalog.toml` gives directives a shared vocabulary and defines the build
81+
contexts that your documentation supports. It has three top-level parts:
82+
83+
| Part | Purpose |
84+
| ----------------- | ----------------------------------------------------------- |
85+
| `default_variant` | Names the variant used when no environment override is set. |
86+
| `variables` | Declares the values that source files may test or insert. |
87+
| `variants` | Names each build context and assigns its variable values. |
88+
89+
Each variable declares one string or a list of allowed strings. Every named
90+
variant must assign one allowed string value to every declared variable.
91+
92+
Variable names must start with an ASCII letter and may then use ASCII letters,
93+
digits, and underscores. Names beginning with an underscore are reserved for
94+
built-in values; `_variant` is the built-in name for the selected variant. The
95+
condition keywords `and`, `or`, and `not` are also reserved as variable names.
96+
97+
## Usage
98+
99+
### Quick start
100+
101+
Use the catalog values in your Markdown source:
102+
103+
``` markdown
104+
# Deploy Acme Platform
105+
106+
@if deployment = cloud
107+
108+
## Set up the cloud deployment
109+
110+
Create an Acme Platform workspace. The service is managed for you.
111+
112+
@elif deployment = self-hosted
113+
114+
## Set up the self-hosted deployment
115+
116+
Provision a Linux host and install the server package.
117+
118+
@use shared/deployment-overview.md
119+
120+
This guide covers the **@var{deployment}** deployment.
121+
```
122+
123+
Create the included source at `content/shared/deployment-overview.md`:
124+
125+
``` markdown
126+
Read the deployment overview before configuring the service.
127+
```
128+
129+
Build the catalog's default variant as usual:
130+
131+
``` sh
132+
zensical build
133+
```
134+
135+
Set `ZENSICAL_VARIANT` to build or preview another named variant:
136+
137+
``` sh
138+
ZENSICAL_VARIANT=self-hosted zensical serve
139+
```
140+
141+
`ZENSICAL_VARIANT` overrides `default_variant` when both are set.
142+
143+
### Conditional content
144+
145+
Use `@if`, `@elif`, and `@else` to select block content. A branch body starts
146+
four columns beyond its directive and may contain ordinary Markdown or nested
147+
directives:
148+
149+
``` markdown
150+
@if authentication = single-sign-on
151+
152+
Configure the SAML or OpenID Connect connection.
153+
154+
@else
155+
156+
Create the first administrator account locally.
157+
```
158+
159+
Conditions compare a catalog variable, or `_variant`, with a value. Combine
160+
comparisons with `and`, `or`, and `not`, and use parentheses when needed.
161+
Unquoted values may contain ASCII letters, digits, underscores, and hyphens.
162+
You may quote a value, and must do so when it contains whitespace, punctuation
163+
other than hyphens, or non-ASCII characters:
164+
165+
``` markdown
166+
@if deployment = self-hosted and authentication = "single-sign-on"
167+
168+
Configure the identity provider before inviting users.
169+
```
170+
171+
### Insert a value
172+
173+
Use `@var{name}` in ordinary Markdown text to insert a selected catalog value.
174+
The built-in `_variant` value is the selected variant's name:
175+
176+
``` markdown
177+
This guide covers the @var{deployment} deployment for the @var{_variant} variant.
178+
```
179+
180+
### Reuse a source file
181+
182+
Use `@use` on its own line to include a whole source file:
183+
184+
``` markdown
185+
@use shared/security-notice.md
186+
```
187+
188+
The path is relative to `content_dir`, which defaults to `content` in the
189+
project root. Quote a path that contains whitespace:
190+
191+
``` markdown
192+
@use "shared/security notice.md"
193+
```
194+
195+
Included files use the same selected variant, may contain directives and nested
196+
`@use` directives, and must remain inside `content_dir`.
197+
198+
Unlike a textual snippet, an included file retains its own source location.
199+
Relative links and images resolve from that file, then Zensical adapts their
200+
destinations for the page where the content appears. This also works through
201+
nested `@use` directives.
202+
203+
### Use alongside snippets and macros
204+
205+
Use directives when reuse and variation are part of the documentation model:
206+
the catalog defines the allowed values and variants, and each build contains
207+
only the selected content. Snippets remain useful for fixed source text, while
208+
macros suit generated text or template logic.
209+
210+
Snippets and macros run on the original page before directives are parsed.
211+
Included source files are not passed through those textual extensions again.
212+
213+
## Troubleshooting
214+
215+
Like other Markdown extensions, directives do not stop a build when Zensical
216+
cannot resolve a catalog or directive problem. It emits a warning and leaves
217+
the unresolved directive visible in the output instead. We will add validation
218+
to Zensical Studio first, so authors can find and fix these issues while
219+
writing.
220+
221+
[deployment-guide example]: ../assets/deployment-guide.zip
222+
[Zensical Spark]: https://zensical.org/spark/
223+
[Zensical Studio]: https://zensical.org/studio/

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ nav:
222222
- Content tabs: authoring/content-tabs.md
223223
- Data tables: authoring/data-tables.md
224224
- Diagrams: authoring/diagrams.md
225+
- Directives: authoring/directives.md
225226
- Footnotes: authoring/footnotes.md
226227
- Formatting: authoring/formatting.md
227228
- Grids: authoring/grids.md

0 commit comments

Comments
 (0)