From 1d251ea203ddd608437c58ae38a6111328a8a091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Tue, 31 Mar 2026 15:17:02 +0200 Subject: [PATCH] Added variable support to cards and description macro --- docs/ibexa_engage/install_ibexa_engage.md | 6 ++-- docs/resources/release_process_and_roadmap.md | 2 +- main.py | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/ibexa_engage/install_ibexa_engage.md b/docs/ibexa_engage/install_ibexa_engage.md index 3fd434419e..8f4177890f 100644 --- a/docs/ibexa_engage/install_ibexa_engage.md +++ b/docs/ibexa_engage/install_ibexa_engage.md @@ -1,9 +1,9 @@ --- -description: Install and configure Ibexa Engage. +description: Install and configure [[= product_name_engage =]]. edition: experience --- -# Ibexa Engage +# [[= product_name_engage =]] [[= product_name_engage =]] is a data collection tool. It enables you to engage your audiences by using the [Qualifio](https://qualifio.com/) tools. You can use interactive content to gather valuable data, for example, customer data or recent orders list, and create connections. @@ -52,4 +52,4 @@ In `config/packages` directory add the following `ibexa_connector_qualifio.yaml` [[= product_name_base =]] configures the `channel` and `client_id` values so that the selections can be filled up automatically on [[= product_name =]] side. The `feed_url` and `variable_map` values don't need to be set at the installation process. - They're preconfigured and can be overwritten. \ No newline at end of file + They're preconfigured and can be overwritten. diff --git a/docs/resources/release_process_and_roadmap.md b/docs/resources/release_process_and_roadmap.md index 42ee5215b0..0357090395 100644 --- a/docs/resources/release_process_and_roadmap.md +++ b/docs/resources/release_process_and_roadmap.md @@ -2,7 +2,7 @@ description: "Ibexa DXP releases new versions periodically in different flavors: Ibexa Headless, Ibexa Experience and Ibexa Commerce, plus open-source Ibexa OSS." --- -# Ibexa DXP release process and roadmap +# [[= product_name =]] release process and roadmap ## Release process diff --git a/main.py b/main.py index 147a48bef5..05488011b3 100644 --- a/main.py +++ b/main.py @@ -64,6 +64,9 @@ def cards(pages, columns=1, style="cards", force_version=False): if isinstance(pages, str): pages = [pages] + variables = env.conf.get('extra', {}) + var_start = env.config['j2_variable_start_string'] + var_end = env.config['j2_variable_end_string'] cards = [] for page_data in pages: if isinstance(page_data, tuple): @@ -144,6 +147,8 @@ def cards(pages, columns=1, style="cards", force_version=False): href = page title = custom_title if custom_title else current_meta['short'] or current_meta['title'] description = custom_description if custom_description else current_meta['description'] or " " + title = resolve_variables(title, var_start, var_end, variables) + description = resolve_variables(description, var_start, var_end, variables) cards.append( CARDS_TEMPLATE % ( @@ -231,6 +236,16 @@ def release_note_entry_begin(header : str, date: str, categories : List[str]) -> def release_note_entry_end() -> str: return "" + def resolve_variables(text, var_start, var_end, variables): + """Replace variable references (e.g. [[= var =]]) with variables.""" + pattern = re.escape(var_start) + r'\s*([\w.]+)\s*' + re.escape(var_end) + def replacer(match): + key = match.group(1).strip() + if key not in variables: + raise KeyError("Undefined variable '%s' used in cards macro" % key) + return str(variables[key]) + return re.sub(pattern, replacer, text) + def slugify(text: str) -> str: return text.lower().replace(' ', '-') @@ -242,3 +257,16 @@ def validate_categories(categories: List[str]) -> None: raise ValueError( "Unknown category: {category}. Available categories are: {available_categories}".format(category=category, available_categories=" ".join(available_categories)) ) + + +def on_pre_page_macros(env): + """ + Resolve variable references in the page's description front matter field + so that they are substituted before MkDocs renders the tag. + """ + page = env._page + if page.meta and 'description' in page.meta: + page.meta['description'] = env.render( + markdown=page.meta['description'], + force_rendering=True + )