diff --git a/dbuild/docs.py b/dbuild/docs.py index d64c44d..2c02180 100644 --- a/dbuild/docs.py +++ b/dbuild/docs.py @@ -33,6 +33,9 @@ # Constants for placeholder generation CONFIG_ROOT_VAR = "@CONTAINER_CONFIG_ROOT@" +# The config root a sample path starts with: /containers, or the fleet's +# /path/to/containers -- all of it, or the page keeps /path/to in front. +CONFIG_ROOT_RE = r"(? str: """ if not text: return "" - text = re.sub(r"/containers(?=/)", CONFIG_ROOT_VAR, text) + text = re.sub(CONFIG_ROOT_RE, CONFIG_ROOT_VAR, text) text = re.sub(r"(?m)(\bPUID=)1000\b", r"\g<1>@PUID@", text) text = re.sub(r"(?m)(\bPGID=)1000\b", r"\g<1>@PGID@", text) if env_file: @@ -514,7 +517,7 @@ def _choice_context(cfg: Config, context_env: list[dict[str, Any]]) -> dict[str, k, _, v = ln.partition("=") if k.endswith("_LOCATION") and v and v not in folders: folders.append(v) - folders = [f.replace("/containers", "@CONTAINER_CONFIG_ROOT@") for f in folders] + folders = [_re.sub(CONFIG_ROOT_RE, CONFIG_ROOT_VAR, f) for f in folders] director_text = director_env_text = "" if authored is not None: sliced = _director_for_option(authored, cfg, None if is_default else opts) diff --git a/tests/test_docs.py b/tests/test_docs.py index 8b69d66..811806e 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -474,6 +474,16 @@ def test_repo_compose_and_env_get_site_placeholders(self): "CONFIG_LOCATION=@CONTAINER_CONFIG_ROOT@/app\nTZ=@TZ@\n") assert _site_placeholders("") == "" + def test_the_whole_fleet_root_becomes_the_placeholder(self): + # 122 composes write /path/to/containers/: only /containers was + # swapped, so the page showed /path/to@CONTAINER_CONFIG_ROOT@/. + from dbuild.docs import _site_placeholders + compose = " - /path/to/containers/uptime-kuma:/config\n" + assert _site_placeholders(compose) == " - @CONTAINER_CONFIG_ROOT@/uptime-kuma:/config\n" + env = "DB_LOCATION=/path/to/containers/app/db\n" + assert _site_placeholders(env, env_file=True) == "DB_LOCATION=@CONTAINER_CONFIG_ROOT@/app/db\n" + assert _site_placeholders(" - /srv/containers/x:/x\n") == " - /srv/containers/x:/x\n", "only at a path's start" + # ── Stack choices ──────────────────────────────────────────────────────