From ba2d6ec60c67855c582fc11ff49ef8609c1b9cab Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Mon, 28 Sep 2026 17:06:38 +0000 Subject: [PATCH] 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. --- docs/messages.md | 6 +++--- pagerite/api.py | 17 +++++++++++------ pagerite/views.py | 8 +++++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/messages.md b/docs/messages.md index f9506c1..d6b60fa 100644 --- a/docs/messages.md +++ b/docs/messages.md @@ -36,15 +36,15 @@ A lone `{contact: Label}` line in article Markdown (the block-directive machinery of `markdown.py`) renders ``. 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 diff --git a/pagerite/api.py b/pagerite/api.py index 713ca94..a117cd0 100644 --- a/pagerite/api.py +++ b/pagerite/api.py @@ -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"] = ( diff --git a/pagerite/views.py b/pagerite/views.py index 1ef278f..a4f3b79 100644 --- a/pagerite/views.py +++ b/pagerite/views.py @@ -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)