diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 282c66e..7649bd8 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -12,7 +12,8 @@ "WebFetch(domain:a2ui-sdk.js.org)", "WebFetch(domain:www.copilotkit.ai)", "Bash(grep -l \"A2UIRenderer\\\\|useA2UISurface\\\\|a2ui-surface\" /Users/gb/Projects/bDS/src/renderer/components/**/*.tsx)", - "Bash(npm test)" + "Bash(npm test)", + "Bash(ls -la /Users/gb/Projects/bDS/*.md)" ] } } diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 728e942..32633ed 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -243,6 +243,37 @@ Notes: - Return the mutated `post` dict from your transform function. - Keep transforms small and deterministic, especially when multiple active transforms run in sequence. +### Macro scripts + +Macro scripts let you create custom `[[macro_name ...]]` blocks that expand during preview and page generation. Create a script with kind set to **macro** and pick a slug — the slug becomes the macro name used in Markdown. + +The entrypoint function always receives two arguments: + +```python +def render(context, post): + params = context["params"] # dict of macro parameters + language = context["language"] # project language code + post_slug = context["post_slug"] # slug of the host post + + title = post["title"] if post else "Unknown" + return {"html": f"
Post: {title}
"} +``` + +`context` is a dict containing `params` (the key-value pairs from the macro tag), `language`, and `post_slug`. `post` is the full PostData dict for the post containing the macro, or `None` when post data is unavailable. The function must return a dict with an `html` key containing the rendered HTML string. + +Macro scripts can also call the application API through the `bds_api` module: + +```python +from bds_api import bds + +def render(context, post): + tags = await bds.posts.get_tags() + items = "".join(f"