docmd icon indicating copy to clipboard operation
docmd copied to clipboard

[Feature]: be able to use environment variables provided at build time

Open cboitel opened this issue 3 months ago • 3 comments

Is your feature request related to a problem?

We are missing a way to provide data values at build/run time that would be replaced in generated documentation.

Describe the solution you'd like

One can also think of having a data.json files in assets directory (static or generated by CI) and be able to use it inside markdown pages: syntax used would allow to define url of asset file to retrieve and a jsonpath to use to extract value to be used.

We could as well allow to reference an environment variable's value in markdown pages: variable would be provided at build time.

Example:

This is the documentation site for version ${XXXX}.

In this example, ${XXXX} would be replaced by value of environment variable XXXX provided at build time in CI.

Syntax of placeholder are simply example: I believe there may be a more markdown way of referencing a

Describe alternatives you've considered

Preprocessing in CI using envsubst/sed/....

cboitel avatar Aug 25 '26 16:08 cboitel

Thanks for opening this @cboitel! Having build-time variables and data substitution in Markdown is definitely a useful workflow, especially in CI environments. We'd love to hear more about your ideal setup: would you prefer a dedicated data plugin (e.g. referencing keys from an assets/data.json or config data block), or direct interpolation for an allowlisted set of environment variables (like DOCMD_VAR_*)? Any thoughts on placeholder syntax (e.g. {{ var }} vs ${var}) would also be great to know as we plan this for upcoming releases.

mgks avatar Sep 19 '26 09:09 mgks

To experience, I wrote my own plugin to substitute variables:

  • since ${xxxx} can be used inside documentation, i would not recommend to use that syntax to prevent confusion
  • i used the {{ var }} syntax

I would assume replacing variables is a built-in feature as this is CI standard. If variable is not defined (not empty), I would report an error since resulting documentation will be incomplete.

I can provide my plugin code if needed.

To avoid confusion, {{ var }} syntax would only apply to var being a valid environment variable name (e.g. [A-Za-z0-9]) or to variables with DOCMD_VAR_xxx formats to avoid extracting CI run-time information.

As per reading structured data from a json file, I haven't experienced it but I would recommend to provide a data plugin since this is a less common use case in my opinion.

User should be able to configure plugin providing a map of variable key (which would be used in documentation) and associated data:

  • source location: a file name relative to assets or external url (httpx://ddd/data.json)
  • whether substitution should be done at build time or run-time (would default to false if not provided)
"data": {
  "mykey": {
      "source": "file_location_relative_to_assets"
      "runtime": false
  }
}

In Documentation:

  1. one you could reference the whole data or part of it using a JSON path syntax (e.g. {{ data.var.property }})
  2. decide whether you want the prettier version or compact one (e.g. {{ data.var.property pretty }}

Using data. prefix would avoid confusion with an environment variable name.

Hope it helps.

cboitel avatar Sep 21 '26 06:09 cboitel

Hi @cboitel,

Thank you for your patience and for sharing your plugin implementation and syntax proposals!

We are excited to share that full, first-class support for Environment and Reactive Variables has landed in v0.9.9.

What's included:

  1. Double-Mustache Syntax: Use {{ VAR_NAME }} or {{ env.API_KEY }} across Markdown text, tables, callouts, and code blocks.
  2. Build-Time System Environment: Read environment variables dynamically at build time using {{ env.MY_ENV_VAR }} or configure explicit aliases in docmd.config.json under "variables": { ... }.
  3. Built-in System Variables: Direct access to {{ docmd.version }}, {{ docmd.buildTime }}, {{ docmd.gitBranch }}, {{ docmd.gitCommit }}, etc.
  4. Client-Side Reactive Runtime: Read and mutate variables dynamically in the browser via window.docmd.var.get("key") and window.docmd.var.set("key", "val"), which instantly updates bound elements on the page.
  5. Code Block Copy Integration: Clicking "Copy" on code blocks now copies the live interpolated variable values.

Full documentation and examples are available in the Variables Guide.

I suppose now this issue is resolved in v0.9.9. Please test it out and feel free to create a new issue if you have any feedback!

I will close this issue after few days.

mgks avatar Nov 03 '26 17:11 mgks