Make button shortcode use portable links

This commit is contained in:
Alex Shpak
2025-09-14 23:38:46 +02:00
parent e379c19e75
commit 6c2d102c91
3 changed files with 5 additions and 12 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ layout: landing
{{< badge style="info" title="Badge" value="Value" >}} {{< badge style="default" title="Badge" value="Value" >}} {{< badge style="info" title="Badge" value="Value" >}} {{< badge style="default" title="Badge" value="Value" >}}
{{<button relref="/docs/example">}}Button{{</button>}} {{<button href="/docs/example">}}Button{{</button>}}
</div> </div>
@@ -9,5 +9,5 @@ Buttons are styled links that can lead to local page or external link.
{{</* button href="https://github.com/alex-shpak/hugo-book" */>}}Contribute{{</* /button */>}} {{</* button href="https://github.com/alex-shpak/hugo-book" */>}}Contribute{{</* /button */>}}
``` ```
{{<button relref="/">}}Get Home{{</button>}} {{<button href="/">}}Get Home{{</button>}}
{{<button href="https://github.com/alex-shpak/hugo-book">}}Contribute{{</button>}} {{<button href="https://github.com/alex-shpak/hugo-book">}}Contribute{{</button>}}
+3 -10
View File
@@ -1,12 +1,5 @@
{{- $ref := "" }} {{ $href := partial "docs/links/portable-link" (dict "Page" .Page "Destination" (.Get "href")) -}}
{{- $target := "" -}} {{ $isRemote := (urls.Parse $href).Scheme}}
{{- with .Get "href" -}} <a {{ with $href }}href="{{ $href }}"{{ end }} {{ with $isRemote }}target="_blank" rel="noopener"{{ end }} class="book-btn{{ with .Get "class" }} {{ . }}{{ end }}">
{{- $ref = . -}}
{{- $target = "_blank" -}}
{{- end -}}
{{- with .Get "relref" -}}
{{- $ref = relref $ . -}}
{{- end -}}
<a {{ with $ref }} href="{{.}}" {{ end }} {{ with $target }} target="{{.}}" rel="noopener" {{ end }} class="book-btn{{ with .Get "class" }} {{ . }}{{ end }}">
{{- .InnerDeindent -}} {{- .InnerDeindent -}}
</a> </a>