Skip to content

Commit 05245d4

Browse files
committed
Card: Fixed relative pathing
1 parent deb5574 commit 05245d4

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

exampleSite/content/_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ description:
77
Documentation for hugo theme
88
{{<card-layout>}}
99
{{<card-section showAsCards="true">}}
10-
{{<card title="Test Product" titleUrl="/test-product/" icon="test-tubes" isLanding="true">}}
10+
{{<card title="Test Product" titleUrl="test-product/" icon="test-tubes" isLanding="true">}}
1111
See explanations and usages of shortcodes
1212
{{</card >}}
13-
{{<card title="NGINX Plus" titleUrl="/nginx/" brandIcon="NGINX-Plus-product-icon-RGB" isLanding="true">}}
13+
{{<card title="NGINX Plus" titleUrl="nginx/" brandIcon="NGINX-Plus-product-icon-RGB" isLanding="true">}}
1414
See a live example of theme components
1515
{{</card >}}
1616
{{</card-section>}}

exampleSite/content/test-product/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ This is a compilation of all our shortcodes to show how they look, function, res
5454

5555
{{<card-layout >}}
5656
{{<card-section title="NGINX" showAsCards="true" >}}
57-
{{<card title="NGINX Plus" titleUrl="/nginx/" brandIcon="NGINX-Plus-product-icon-RGB" >}}
57+
{{<card title="NGINX Plus" titleUrl="nginx/" brandIcon="NGINX-Plus-product-icon-RGB" >}}
5858
Installing NGINX
5959
{{</card >}}
6060
{{</card-section >}}

layouts/shortcodes/card.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,16 @@
3232
{{ $dataGrid = "half"}}
3333
{{ end }}
3434

35+
{{- /* Build the url */ -}}
36+
{{ if eq (substr $titleUrl 0 1) "/" }}
37+
{{ $suggestedUrlFix := substr $titleUrl 1 }}
38+
{{ errorf "Please do not start the param 'titleUrl' with a forward slash. Got: '%s', use '%s' instead." $titleUrl $suggestedUrlFix }}
39+
{{ end }}
40+
{{ $url := printf "%s%s" .Page.Permalink $titleUrl }}
41+
3542
{{- /* Validate that the parent is card-section and under 3 cards */ -}}
3643
{{- if (eq .Parent.Name "card-section") -}}
37-
<a href="{{- $titleUrl -}}" alt="{{- $title -}}" class="card{{ if eq $isFeatured "true" }} featured-card{{ end }}" data-grid="{{ $dataGrid }}" data-testid="{{ if eq $isFeatured "true" }}card__featured-card{{else}}card{{ end }}">
44+
<a href="{{- $url -}}" alt="{{- $title -}}" class="card{{ if eq $isFeatured "true" }} featured-card{{ end }}" data-grid="{{ $dataGrid }}" data-testid="{{ if eq $isFeatured "true" }}card__featured-card{{else}}card{{ end }}">
3845
<div class="card-container">
3946
{{- if $title -}}
4047
<div class="card-header">

0 commit comments

Comments
 (0)