hugo-theme-paradox/layouts/shortcodes/page-ref.html

27 lines
1.1 KiB
HTML

{{- $ref := relref . (.Get "ref") }}
{{- $path := (index (split (.Get "ref") "#") 0) }}
{{- $anchor := (index (split (.Get "ref") "#") 1)}}
{{- $page := .Site.GetPage $path -}}
{{- $pattern := printf `.*?\n#{2,6} (.+) \{#%s\}.*?` $anchor }}
{{- $title := $page.RawContent}}
{{- $heading := index (findRE $pattern $title 1) 0 }}
{{- $heading = replaceRE $pattern "$1" $heading }}
{{- with $page -}}
<a href="{{ $ref }}" class="ref-link page-ref">
<div class="ref-link__icon">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
</svg>
</div>
<div class="ref-link__text">
<span class="page-ref__title">
{{- .Title }}
</span>
{{- with $heading -}}
<span class="page-ref__section">
<br>§ {{$heading -}}
</span>
{{ end -}}
</div>
</a>
{{- end -}}