diff --git a/src/overrides/hooks/lists.py b/src/overrides/hooks/lists.py index 827dca4a0d..426900c0e4 100644 --- a/src/overrides/hooks/lists.py +++ b/src/overrides/hooks/lists.py @@ -7,29 +7,39 @@ import json # Updated _create_chip function to use the same linking logic as "maatregelen" -def _create_chip(item: str, chip_type: str, base_url: str, config: MkDocsConfig) -> str: +# Updated _create_chip function to use dynamic PR preview path logic +def _create_chip(item: str, chip_type: str, current_file: File, config: MkDocsConfig) -> str: if not item: return "" + # Initialize icon and color icon_svg, color_class = "", "" + + # Initialize base_url and detect PR preview environment + base_url = config.site_url if config.site_url else "/" + + if "minbzk.github.io" in base_url and "pr-preview" in current_file.abs_dest_path: + pr_preview_index = current_file.abs_dest_path.index("pr-preview") + pr_preview_path = current_file.abs_dest_path[pr_preview_index:].split('/')[0:3] # e.g., ['pr-preview', 'pr-269'] + base_url = "/" + "/".join(pr_preview_path) + "/" # Determine chip-specific styles and icons if chip_type == 'rol': color_class = 'deep-orange' icon_svg = '' - link = f'{base_url}rollen/{item}' + link = posixpath.join(base_url, 'rollen', item) elif chip_type == 'levenscyclus': color_class = 'indigo' icon_svg = '' - link = f'{base_url}levenscyclus/{item}' + link = posixpath.join(base_url, 'levenscyclus', item) elif chip_type == 'onderwerp': color_class = 'teal' icon_svg = '' - link = f'{base_url}onderwerpen/{item}' + link = posixpath.join(base_url, 'onderwerpen', item) else: color_class = 'blue' icon_svg = '' - link = f'{base_url}{chip_type}/{item}' + link = posixpath.join(base_url, chip_type, item) # Fallback to generic type return f''' @@ -57,10 +67,10 @@ def _create_table_row_2(file: File, filter_options: Dict[str, bool], current_fil onderwerpen = file.page.meta.get('onderwerp', []) vereiste = file.page.meta.get('vereiste', []) - rollen_chips = ''.join(_create_chip(rol, 'rol', base_url, config) for rol in rollen) if filter_options.get("rol", True) else "" - levenscyclus_chips = ''.join(_create_chip(lc, 'levenscyclus', base_url, config) for lc in levenscyclus) if filter_options.get("levenscyclus", True) else "" - onderwerp_chips = ''.join(_create_chip(onderwerp, 'onderwerp', base_url, config) for onderwerp in onderwerpen) if filter_options.get("onderwerp", True) else "" - vereiste_chips = ''.join(_create_chip(vereiste, 'vereiste', base_url, config) for vereiste in vereiste) if filter_options.get("vereiste", True) else "" + rollen_chips = ''.join(_create_chip(rol, 'rol', current_file, config) for rol in rollen) if filter_options.get("rol", True) else "" + levenscyclus_chips = ''.join(_create_chip(lc, 'levenscyclus', current_file, config) for lc in levenscyclus) if filter_options.get("levenscyclus", True) else "" + onderwerp_chips = ''.join(_create_chip(onderwerp, 'onderwerp', current_file, config) for onderwerp in onderwerpen) if filter_options.get("onderwerp", True) else "" + vereiste_chips = ''.join(_create_chip(vereiste, 'vereiste', current_file, config) for vereiste in vereiste) if filter_options.get("vereiste", True) else "" return "".join( [