Skip to content

Commit a568e47

Browse files
committed
Landing: Polished code + added error handling
1 parent 57c40a7 commit a568e47

File tree

7 files changed

+99
-36
lines changed

7 files changed

+99
-36
lines changed

assets/css/v2/style.css

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@ nav {
674674

675675
h2 {
676676
font-size: 1.5rem;
677-
margin: 1rem 0 0rem 0;
678677
}
679678

680679
hr {
@@ -1188,6 +1187,35 @@ h6:has(a):hover {
11881187
color: oklch(var(--color-brand));
11891188
}
11901189

1190+
/* Landing page cards */
1191+
1192+
.text-content .card-layout {
1193+
grid-column: 1 / -1;
1194+
1195+
.card-section {
1196+
margin-bottom: 1rem;
1197+
1198+
strong {
1199+
font-weight: 500;
1200+
}
1201+
}
1202+
}
1203+
1204+
/* Optional grid layout */
1205+
.card-grid {
1206+
display: grid;
1207+
grid-template-columns: repeat(auto-fit, minmax(120px, 500px));
1208+
gap: 1.5rem;
1209+
margin-top: 1rem;
1210+
1211+
.card {
1212+
border: 1px solid oklch(var(--color-codeblock-border));
1213+
box-shadow: 3px 3px 0px oklch(var(--color-shadow));
1214+
padding: 1rem 2rem 2rem 2rem;
1215+
margin-bottom: 1.5rem;
1216+
}
1217+
}
1218+
11911219
/* MARK: Tables
11921220
*/
11931221
table {

exampleSite/content/test-product/_index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,15 @@
22
description: Test pages for nginx-hugo-theme
33
title: Test pages
44
weight: 100
5+
hasCustomContent: true
56
---
7+
{{< card-layout >}}
8+
{{< card-section >}}
9+
{{< card title="Call Out usages" >}}
10+
Examples for <call-out> shortcode
11+
{{</ card >}}
12+
{{< card title="Code Block usages" >}}
13+
Examples for codeblock shortcode
14+
{{</ card >}}
15+
{{</ card-section >}}
16+
{{</ card-layout >}}

layouts/_default/list.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ <h1>{{ .Title }}</h1>
3232

3333
{{ partial "banner" . }}
3434

35-
{{ if (lt .WordCount 1) }}
36-
{{ .Content }}
37-
{{ range .Pages.ByWeight }}
38-
<h2>
39-
<a href="{{ if .Params.url}}{{ .Params.url}}{{else}}{{ .Permalink }}{{end}}">{{ .Title }}</a>
40-
</h2>
41-
{{ end }}
35+
{{ $hasCustomContent := .Params.hasCustomContent | default false }}
36+
{{ if $hasCustomContent }}
37+
{{ partial "custom-landing-page" . }}
4238
{{ else }}
43-
{{ partial "custom-landing-page" . }}
44-
{{end}}
39+
{{ .Content }}
40+
{{ range .Pages.ByWeight }}
41+
<h2>
42+
<a href="{{ if .Params.url}}{{ .Params.url}}{{else}}{{ .Permalink }}{{end}}">{{ .Title }}</a>
43+
</h2>
44+
{{ end }}
45+
{{ end }}
4546

4647
<hr>
4748
{{ if .Page.Lastmod }}
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{{ $cards := .Scratch.Get "cards" }}
2-
{{ range .Pages.ByWeight }}
3-
{{ $title := .Title }}
4-
<h2>
5-
<a href="{{ if .Params.url}}{{ .Params.url}}{{else}}{{ .Permalink }}{{end}}">{{ $title }}</a>
6-
</h2>
7-
{{ range $cards }}
8-
{{ if eq .title $title }}
9-
<p style="margin-left: 1rem;">{{ .content }}</p>
10-
{{ end }}
2+
{{ $class := "card-grid wide"}}
3+
<div>
4+
{{ range .Pages.ByWeight }}
5+
{{ $title := .Title }}
6+
<div class="card">
7+
<h2>
8+
<a href="{{ if .Params.url}}{{ .Params.url}}{{else}}{{ .Permalink }}{{end}}">{{ $title }}</a>
9+
</h2>
10+
{{ range $cards }}
11+
{{ if eq .title $title }}
12+
<p>{{ .content }}</p>
13+
{{ end }}
14+
{{ end }}
15+
</div>
1116
{{ end }}
12-
{{ end }}
17+
</div>
1318
{{ .Content }}

layouts/shortcodes/card-layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div data-mf="true" style="display: none">{{- .Inner | markdownify -}}</div>
1+
<div class="card-layout" data-mf="true" style="display: none">{{- .Inner | markdownify -}}</div>

layouts/shortcodes/card-section.html

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
<div class="card-section">
2-
{{- if .Get "title" -}}
3-
<strong>{{- .Get "title" -}}</strong>
4-
<div style="padding-left: 1rem;">{{- .Inner -}}</div>
5-
{{ end }}
6-
</div>
7-
<br><br>
1+
{{- /* Handle different versions of booleans */ -}}
2+
{{ $showAsCards := .Get 0 | default (.Get "showAsCards") | default "false"}}
3+
{{- /* Validate the parameter strictly */ -}}
4+
{{ if not (in (slice "true" "false") $showAsCards) }}
5+
{{ warnf "The '<card-section>' Shortcode parameter 'showAsCards' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $showAsCards}}
6+
{{ end }}
7+
{{ $class := "card-grid wide"}}
8+
{{- /* Validate that the parent is card-layout */ -}}
9+
{{ if eq .Parent.Name "card-layout"}}
10+
<div class="card-section">
11+
{{- if .Get "title" -}}
12+
<strong class="card-section-title">{{- .Get "title" -}}</strong>
13+
<div class="card-section-content{{ if eq $showAsCards "true" }} {{ $class }} {{ end }}">{{- .Inner -}}</div>
14+
{{ end }}
15+
</div>
16+
{{ else }}
17+
{{ errorf "The '<card-section>' must be nested directly inside the shortcode '<card-layout>'. Please see the exampleSite for an example of usage." }}
18+
{{ end }}

layouts/shortcodes/card.html

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
{{- $newCard := dict "title" (.Get "title") "content" (.Inner) -}}
33
{{- .Page.Scratch.Set "cards" ($current | append $newCard) -}}
44

5-
{{- if .Get "title" -}}
6-
{{- if .Get "titleUrl" -}}
7-
<h2 style="padding: 0;"><a href="{{- .Get "titleUrl" -}}">{{- .Get "title" -}}</a></h2>
8-
{{- else -}}
9-
<h2 style="padding: 0;">{{- .Get "title" -}}</h2>
10-
{{- end -}}
11-
{{ end }}
12-
<p>{{- .Inner -}}</p>
5+
{{- /* Validate that the parent is card-section */ -}}
6+
{{ if eq .Parent.Name "card-section"}}
7+
<div class="card">
8+
{{- if .Get "title" -}}
9+
{{- if .Get "titleUrl" -}}
10+
<h2 class="card-title"><a href="{{- .Get "titleUrl" -}}">{{- .Get "title" -}}</a></h2>
11+
{{- else -}}
12+
<h2 class="card-title">{{- .Get "title" -}}</h2>
13+
{{- end -}}
14+
{{ end }}
15+
<p>{{- .Inner -}}</p>
16+
</div>
17+
{{ else }}
18+
{{ errorf "The '<card>' must be nested directly inside the shortcode '<card-section>'. Please see the exampleSite for an example of usage." }}
19+
{{ end }}

0 commit comments

Comments
 (0)