Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dbuild/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ def _site_placeholders(text: str, env_file: bool = False) -> str:
text = re.sub(r"(?m)(\bPGID=)1000\b", r"\g<1>@PGID@", text)
if env_file:
text = re.sub(r"(?m)^#?\s*TZ=\S*$", "TZ=@TZ@", text)
else:
# A YAML value can't start with @: the highlighter splits it, and the
# site's settings panel never finds the placeholder. Quoted, it's one
# string (the README template quotes its volume lines for this).
text = re.sub(r"""(?m)^(\s*(?:-\s+|[\w.-]+:\s+))(@[A-Z_]+@[^\s#"']*)(?=[ \t]*(?:#.*)?$)""", r'\1"\2"', text)
return text


Expand Down
9 changes: 7 additions & 2 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def test_repo_compose_and_env_get_site_placeholders(self):
compose = " - PUID=1000\n - PGID=1000\n volumes:\n - /containers/app/config:/config\n"
assert _site_placeholders(compose) == (
" - PUID=@PUID@\n - PGID=@PGID@\n volumes:\n"
" - @CONTAINER_CONFIG_ROOT@/app/config:/config\n")
' - "@CONTAINER_CONFIG_ROOT@/app/config:/config"\n')
env = "CONFIG_LOCATION=/containers/app\n# TZ=UTC\n"
assert _site_placeholders(env, env_file=True) == (
"CONFIG_LOCATION=@CONTAINER_CONFIG_ROOT@/app\nTZ=@TZ@\n")
Expand All @@ -479,7 +479,12 @@ def test_the_whole_fleet_root_becomes_the_placeholder(self):
# swapped, so the page showed /path/to@CONTAINER_CONFIG_ROOT@/<app>.
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"
# quoted: a YAML value starting with @ is split by the highlighter
assert _site_placeholders(compose) == ' - "@CONTAINER_CONFIG_ROOT@/uptime-kuma:/config"\n'
long_form = " source: /path/to/containers/app/db\n"
assert _site_placeholders(long_form) == ' source: "@CONTAINER_CONFIG_ROOT@/app/db"\n'
commented = " - /path/to/containers/x:/data # required\n"
assert _site_placeholders(commented) == ' - "@CONTAINER_CONFIG_ROOT@/x:/data" # required\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"
Expand Down
Loading