Modify breadcrumbs logic

First part of the breadcrumbs generation algorithm is to remove the
base URL from the parent's permalink URL.

In the existing code, this is achieve by replacing all instances of
base URL in the parent's permalink URL by an empty string.

This algorithm fails to produces breadcrumbs in the instance where the
base URL is "/" for example.

I believe this is erroneous as only the first instance of the base URLi,
starting at the beginning of the parent's permalink URL should be
replaced by an empty string.

This is the reason I replaced the call to "replace" by a call to
"replaceRE".
This commit is contained in:
David Segonds 2023-01-06 09:11:50 +01:00
parent d3d90be8a4
commit 4cc3fb26ce

View File

@ -1,6 +1,6 @@
{{- if (.Param "ShowBreadCrumbs") -}} {{- if (.Param "ShowBreadCrumbs") -}}
<div class="breadcrumbs"> <div class="breadcrumbs">
{{- $url := replace .Parent.Permalink (printf "%s" site.BaseURL) "" }} {{- $url := replaceRE (printf "^%s" site.BaseURL) "" .Parent.Permalink }}
{{- $lang_url := strings.TrimPrefix (printf "%s/" .Lang) $url -}} {{- $lang_url := strings.TrimPrefix (printf "%s/" .Lang) $url -}}
<a href="{{ "" | absLangURL }}">{{ i18n "home" | default "Home" }}</a> <a href="{{ "" | absLangURL }}">{{ i18n "home" | default "Home" }}</a>