Use mutable variables instead of scratch where possible
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
@@ -1,24 +1,25 @@
|
||||
{{- $scratch := newScratch -}}
|
||||
{{- $class := "" -}}
|
||||
{{- $icon := "" -}}
|
||||
{{- $absoluteDest := absLangURL .Destination -}}
|
||||
{{- $siteRootUrl := absLangURL "" -}}
|
||||
{{- $isExternal := not (hasPrefix $absoluteDest $siteRootUrl) -}}
|
||||
{{- $isSamePage := hasPrefix .Destination "#" -}}
|
||||
|
||||
{{- if $isSamePage -}}
|
||||
{{- $scratch.Set "class" "same-page-link" -}}
|
||||
{{- $class = "same-page-link" -}}
|
||||
{{- if index (.Page.Scratch.Get "definedSections") .Destination -}}
|
||||
{{- $scratch.Set "icon" "arrow-up" -}}
|
||||
{{- $icon = "arrow-up" -}}
|
||||
{{- else -}}
|
||||
{{- /* Do not render "down" links because don't know how to distinguish unseen titles from paragraph links. */ -}}
|
||||
{{- /* $scratch.Set "icon" "arrow-down" */ -}}
|
||||
{{- /* $icon = "arrow-down" */ -}}
|
||||
{{- end -}}
|
||||
{{- else if $isExternal -}}
|
||||
{{- $scratch.Set "class" "external-link" -}}
|
||||
{{- $scratch.Set "icon" "external-link" -}}
|
||||
{{- $class = "external-link" -}}
|
||||
{{- $icon = "external-link" -}}
|
||||
{{- end -}}
|
||||
<a href="{{ .Destination | safeURL }}"
|
||||
{{- with .Title }} title="{{ . }}"{{ end -}}
|
||||
{{- with $scratch.Get "class" -}}
|
||||
{{- with $class -}}
|
||||
class="{{ . }}"
|
||||
{{- end -}}
|
||||
{{- if (and site.Params.externalLinksInNewTab $isExternal) -}}
|
||||
@@ -26,6 +27,6 @@
|
||||
{{- end -}}
|
||||
>
|
||||
{{- with .Text | safeHTML }}{{ . }}{{ end -}}
|
||||
{{- with $scratch.Get "icon" -}}{{- partial "icon.html" . -}}{{- end -}}
|
||||
{{- with $icon -}}{{- partial "icon.html" . -}}{{- end -}}
|
||||
</a>
|
||||
{{- /* chomp trailing newline */ -}}
|
||||
|
||||
Reference in New Issue
Block a user