perf(header): hoist page url out of menu loop

- compute the current page url once instead of per menu item
- use strings.Contains instead of findRE to detect external links
This commit is contained in:
Aditya Telange committed 2026-10-24 17:26:53 +05:30
1 parent 5f157eba7a
commit 26523e0fd8
1 file changed
+2 -3
+2 -3
View File
@@ -81,11 +81,10 @@
</div>
{{- end }}
</div>
{{- $currentPage := . }}
{{- $page_url:= .Permalink | absLangURL }}
<ul id="menu" class="menu">
{{- range site.Menus.main }}
{{- $menu_item_url := (cond (strings.HasSuffix .URL "/") .URL (printf "%s/" .URL) ) | absLangURL }}
{{- $page_url:= $currentPage.Permalink | absLangURL }}
{{- $is_search := eq (site.GetPage .KeyName).Layout `search` }}
<li>
<a href="{{ .URL | absLangURL }}" title="{{ .Title | default .Name }} {{- cond $is_search (" (Alt + /)" | safeHTMLAttr) ("" | safeHTMLAttr ) }}"
@@ -95,7 +94,7 @@
{{- .Name -}}
{{ .Post -}}
</span>
{{- if (findRE "://" .URL) }}&nbsp;
{{- if (strings.Contains .URL "://") }}&nbsp;
<svg fill="none" shape-rendering="geometricPrecision" stroke="currentColor" stroke-linecap="round"
stroke-linejoin="round" stroke-width="2.5" viewBox="0 0 24 24" height="12" width="12">
<path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"></path>