contact messages: editor preview renders no button when messaging disabled

The preview registered the {contact:} directive unconditionally, so with
no configured label it showed the button with the 'Contact us'
placeholder while the served page renders nothing. Mirror the page
logic in the preview render path.
This commit is contained in:
LeoVasanko committed 2026-09-28 17:06:38 +00:00
1 parent 023783d189
commit ba2d6ec60c
3 files changed
+19 -12

No files matched your search

+3 -3
View File
@@ -36,15 +36,15 @@ A lone `{contact: Label}` line in article Markdown (the block-directive
machinery of `markdown.py`) renders
`<button class="contact-trigger">Label</button>`. An empty label falls
back to the configured site label (`Data.contact_label`, localized —
below; "Contact us" appears only as the inert preview's placeholder when
nothing is configured). `pagerite.js`
below; "Contact us" is the last-resort fallback when neither is set).
`pagerite.js`
click-delegates these buttons and lazy-loads
the contact bundle; the editor preview renders the same button inert, and
description/card mining resolves the tag to nothing. A per-button label
lives in the chunk, so translated pages localize it like any other text.
Feeds render the tag as its literal source (no directive context). When
messaging is disabled (no site label configured) the tag renders nothing
at all.
at all, in the editor preview just as on the served page.
## Site settings and localization
+11 -6
View File
@@ -600,13 +600,18 @@ async def editor_ws(ws: WebSocket) -> None:
chain = resolve(data.menu, path)
node = chain[-1] if chain else None
has_cards_tag = views._CARDS_TAG_RE.search(markdown) is not None
# {contact} buttons preview like the served page (inert);
# {cards} expands like page_content does, so the preview
# shows real cards, not the literal tag. No translation
# context: the preview has no lang of its own, so cards
# render in their originals.
# {contact} buttons preview like the served page: inert,
# and nothing at all when messaging is disabled (no
# configured label). {cards} expands like page_content
# does, so the preview shows real cards, not the literal
# tag. No translation context: the preview has no lang of
# its own, so cards render in their originals.
directives: dict = {
"contact": lambda args, _env: views._contact_tag(args, _env, data)
"contact": (
(lambda args, _env: views._contact_tag(args, _env, data))
if data.contact_label.strip()
else (lambda _args, _env: "")
)
}
if node is not None and has_cards_tag:
directives["cards"] = (
+5 -3
View File
@@ -1024,9 +1024,11 @@ def _contact_tag(args: str, _env: dict, data: Data | None = None, lang: str = ""
"""Expand a ``{contact: Label}`` directive: the button that opens the
visitor contact panel (docs/messages.md). The args are a per-button
label overriding the configured site label (Data.contact_label,
localized here; "Contact us" is just the inert preview's placeholder
when nothing is configured). pagerite.js binds the click and
lazy-loads the panel bundle; in the editor preview it stays inert."""
localized here; "Contact us" is the last-resort fallback). Callers
expand the tag only when messaging is enabled — with a blank
contact_label the tag renders nothing at all. pagerite.js binds the
click and lazy-loads the panel bundle; in the editor preview the
button stays inert."""
label = args.strip()
if not label and data is not None:
label = i18n.site_string(data, lang, data.contact_label)