Write up and down arrows on internal links to headings
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
parent
60041d1d37
commit
7b3ef86744
|
@ -150,7 +150,7 @@ a {
|
||||||
transition: color 0.25s;
|
transition: color 0.25s;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.external-link {
|
&.external-link, &.same-page-link {
|
||||||
.feather {
|
.feather {
|
||||||
fill: none;
|
fill: none;
|
||||||
margin-left: 0.25rem;
|
margin-left: 0.25rem;
|
||||||
|
|
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 -}}
|
{{- $absoluteDest := absLangURL .Destination -}}
|
||||||
{{- $siteRootUrl := absLangURL "" -}}
|
{{- $siteRootUrl := absLangURL "" -}}
|
||||||
{{- $isExternal := not (hasPrefix $absoluteDest $siteRootUrl) -}}
|
{{- $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 }}"
|
<a href="{{ .Destination | safeURL }}"
|
||||||
{{- with .Title }} title="{{ . }}"{{ end -}}
|
{{- with .Title }} title="{{ . }}"{{ end -}}
|
||||||
|
{{- with $scratch.Get "class" -}}
|
||||||
|
class="{{ . }}"
|
||||||
|
{{- end -}}
|
||||||
{{- if $isExternal -}}
|
{{- if $isExternal -}}
|
||||||
class="external-link" target="_blank" rel="noopener noreferrer"
|
target="_blank" rel="noopener noreferrer"
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
>
|
>
|
||||||
{{- with .Text | safeHTML }}{{ . }}{{ end -}}
|
{{- with .Text | safeHTML }}{{ . }}{{ end -}}
|
||||||
{{- if $isExternal -}}{{- partial "icon.html" "external-link" -}}{{- end -}}
|
{{- with $scratch.Get "icon" -}}{{- partial "icon.html" . -}}{{- end -}}
|
||||||
</a>
|
</a>
|
||||||
{{- /* chomp trailing newline */ -}}
|
{{- /* chomp trailing newline */ -}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user