Write up and down arrows on internal links to headings
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
4
layouts/_default/_markup/render-heading.html
Normal file
4
layouts/_default/_markup/render-heading.html
Normal file
@@ -0,0 +1,4 @@
|
||||
{{- .Page.Scratch.SetInMap "definedSections" (printf "#%s" .Anchor) true -}}
|
||||
<h{{ .Level }} id="{{ .Anchor }}">
|
||||
{{- .Text | safeHTML -}}
|
||||
</h{{ .Level }}>
|
||||
@@ -1,13 +1,30 @@
|
||||
{{- $scratch := newScratch -}}
|
||||
{{- $absoluteDest := absLangURL .Destination -}}
|
||||
{{- $siteRootUrl := absLangURL "" -}}
|
||||
{{- $isExternal := not (hasPrefix $absoluteDest $siteRootUrl) -}}
|
||||
{{- $isSamePage := hasPrefix .Destination "#" -}}
|
||||
|
||||
{{- if $isSamePage -}}
|
||||
{{- $scratch.Set "class" "same-page-link" -}}
|
||||
{{- if index (.Page.Scratch.Get "definedSections") .Destination -}}
|
||||
{{- $scratch.Set "icon" "arrow-up" -}}
|
||||
{{- else -}}
|
||||
{{- $scratch.Set "icon" "arrow-down" -}}
|
||||
{{- end -}}
|
||||
{{- else if $isExternal -}}
|
||||
{{- $scratch.Set "class" "external-link" -}}
|
||||
{{- $scratch.Set "icon" "external-link" -}}
|
||||
{{- end -}}
|
||||
<a href="{{ .Destination | safeURL }}"
|
||||
{{- with .Title }} title="{{ . }}"{{ end -}}
|
||||
{{- with $scratch.Get "class" -}}
|
||||
class="{{ . }}"
|
||||
{{- end -}}
|
||||
{{- if $isExternal -}}
|
||||
class="external-link" target="_blank" rel="noopener noreferrer"
|
||||
target="_blank" rel="noopener noreferrer"
|
||||
{{- end -}}
|
||||
>
|
||||
{{- with .Text | safeHTML }}{{ . }}{{ end -}}
|
||||
{{- if $isExternal -}}{{- partial "icon.html" "external-link" -}}{{- end -}}
|
||||
{{- with $scratch.Get "icon" -}}{{- partial "icon.html" . -}}{{- end -}}
|
||||
</a>
|
||||
{{- /* chomp trailing newline */ -}}
|
||||
|
||||
Reference in New Issue
Block a user