Skip to content

Commit 88f2a47

Browse files
authored
Modify cards code to support new landing page archetype (#278)
* Card: Modify cards code to support new landing page archetype * Card: Update test-product landing page * Card: Update list based on new params
1 parent 4c2a990 commit 88f2a47

File tree

8 files changed

+147
-94
lines changed

8 files changed

+147
-94
lines changed

assets/css/v2/style.css

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,31 +1200,88 @@ h6:has(a):hover {
12001200
}
12011201

12021202
/* Landing page cards */
1203-
12041203
.text-content .card-layout {
1205-
grid-column: 1 / -1;
1204+
grid-column: 1;
12061205

12071206
.card-section {
1208-
margin-bottom: 1rem;
1207+
display: flex;
1208+
flex-direction: column;
1209+
gap: 1rem;
12091210

12101211
strong {
12111212
font-weight: 500;
12121213
}
1214+
1215+
/* Hide all the cards past 3 if it is a featured card section */
1216+
&.featured-section {
1217+
.card-section-content.card-grid > *:nth-child(n + 4) {
1218+
display: none;
1219+
}
1220+
}
12131221
}
12141222
}
12151223

12161224
/* Optional grid layout */
12171225
.card-grid {
12181226
display: grid;
1219-
grid-template-columns: repeat(auto-fit, minmax(120px, 500px));
1227+
grid-template-columns: repeat(auto-fit, minmax(33%, 1fr));
12201228
gap: 1.5rem;
1221-
margin-top: 1rem;
12221229

12231230
.card-container {
12241231
border: 1px solid oklch(var(--color-codeblock-border));
12251232
box-shadow: 3px 3px 0px oklch(var(--color-shadow));
1226-
padding: 1rem 2rem 2rem 2rem;
1227-
margin-bottom: 1.5rem;
1233+
padding: 1rem;
1234+
1235+
&.featured-card {
1236+
/* If there is a featured card, only the featured card should be full length */
1237+
grid-column: 1 / -1;
1238+
1239+
/* If there is a featured card AND two cards, the last one should be full length */
1240+
~ .card-container:nth-child(2n):last-child {
1241+
grid-column: 1 / -1;
1242+
}
1243+
}
1244+
}
1245+
1246+
/* If there is no featured card, last card that is the 3rd one should be full width */
1247+
&:not(:has(.featured-card)) .card-container:nth-child(3n):last-child {
1248+
grid-column: 1 / -1;
1249+
}
1250+
}
1251+
1252+
.card-container {
1253+
display: flex;
1254+
flex-direction: column;
1255+
gap: 0.5rem;
1256+
margin-bottom: 1rem;
1257+
1258+
.card-header {
1259+
display: flex;
1260+
flex-direction: row;
1261+
gap: 0.5rem;
1262+
1263+
.card-brand-icon {
1264+
height: 20px;
1265+
width: auto;
1266+
}
1267+
1268+
h2 {
1269+
padding: 0;
1270+
margin: 0;
1271+
font-size: 1rem;
1272+
}
1273+
}
1274+
}
1275+
1276+
.list-header-container {
1277+
display: flex;
1278+
gap: 1.5rem;
1279+
align-items: center;
1280+
justify-content: start;
1281+
1282+
img {
1283+
width: auto;
1284+
height: 3.5rem;
12281285
}
12291286
}
12301287

exampleSite/content/test-product/_index.md

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,45 @@ title: Test pages
44
weight: 100
55
hasCustomContent: true
66
---
7+
8+
## About
9+
10+
[//]: # "Give a short 1-2 sentence summary of what the product does and its value to a customer."
11+
This is a compilation of all our shortcodes to show how they look, function, respond, and coded.
12+
13+
## Featured Content
14+
15+
[//]: # "Maximum of three cards available to display."
16+
[//]: # "Each card should be less than 10 words for a description."
17+
[//]: # "If more than three cards are placed here, they are not displayed."
18+
[//]: # "If there is one card, it will take full width and be the only card in the row."
19+
[//]: # "If there is two cards, one card will take half width and there will be two cards in a row."
20+
[//]: # "If there is three cards, there will be two rows, where first row has two equal-sized cards, and second row will have a full width card. Can we inversed in order to feature content."
721
<!-- <card-layout> - Available params: title (required: string)-->
8-
{{< card-layout >}}
9-
<!-- <card-section> - Available params: title (required: string), showAsCards (optional: boolean, default false) -->
22+
{{<card-layout >}}
23+
<!-- <card-section> - Available params: title (required: string), showAsCards (optional: boolean, default "false"), isFeaturedSection (optional: boolean, default "false") -->
1024
<!-- If there is no "title" for <card-section>, it is implied it is the main content section and not a new content section -->
11-
{{< card-section >}}
12-
{{< card title="Call Out usages" >}}
13-
<!-- <card> - Available params: title (required: string), titleUrl (optional: string, relative path or absolute URL (e.g. https://google.com)) -->
25+
{{<card-section showAsCards="true" isFeaturedSection="true">}}
26+
{{<card title="Everything" titleUrl="everything" icon="circle-dot-dashed">}}
27+
All shortcodes in one page.
28+
{{</card >}}
29+
{{<card title="Call Out usages" titleUrl="call-out/all-callouts/" icon="message-square">}}
30+
<!-- <card> - Available params: title (required: string), titleUrl (optional: string, relative path or absolute URL (e.g. https://google.com)), icon (optional: string, pulled from lucide), brandIcon (optional: string, takes priority over icon if provided) -->
1431
Examples for call-out shortcode
15-
{{</ card >}}
16-
{{< card title="Code Block usages" >}}
32+
{{</card >}}
33+
{{<card title="Code Block usages" titleUrl="code-blocks/code-blocks-highlighting/" icon="code">}}
1734
Examples for codeblock shortcode
18-
{{</ card >}}
19-
{{</ card-section >}}
35+
{{</card >}}
36+
{{</card-section>}}
37+
{{</card-layout >}}
38+
39+
## Other Content
2040

21-
# Other Products on ExampleSite
22-
{{< card-section title="NGINX" showAsCards="true" >}}
23-
{{< card title="NGINX Plus" titleUrl="/nginx/" >}}
41+
[//]: # "Provide any sort of additional supporting content you may want customers to see as well (e.g. more cards, diagrams, changelogs, etc.)"
42+
{{<card-layout >}}
43+
{{<card-section title="NGINX" showAsCards="true" >}}
44+
{{<card title="NGINX Plus" titleUrl="/nginx/" brandIcon="NGINX-Plus-product-icon-RGB" >}}
2445
Installing NGINX
25-
{{</ card >}}
26-
{{</ card-section >}}
27-
{{</ card-layout >}}
46+
{{</card >}}
47+
{{</card-section >}}
48+
{{</card-layout >}}

layouts/_default/list.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@
2828
{{ end }}
2929
{{ end }}
3030
</section>
31-
<h1>{{ .Title }}</h1>
31+
<div class="list-header-container">
32+
<img src="/images/icons/{{ .Params.logo | default "NGINX-product-icon.svg" }}">
33+
<div class="list-header-title">
34+
<h1>{{ .Title }}</h1>
35+
{{ if index .Params "nd-subtitle" }}
36+
<p>{{ index .Params "nd-subtitle" | markdownify }}</p>
37+
{{ end }}
38+
</div>
39+
</div>
3240

3341
{{ partial "banner" . }}
34-
35-
{{ $hasCustomContent := .Params.hasCustomContent | default false }}
42+
{{ $hasCustomContent := index .Params "nd-landing-page" | default false }}
3643
{{ if $hasCustomContent }}
37-
{{ .Page.Scratch.Set "custom-landing-page-file-name" "custom-landing-page.html" }}
38-
{{ .Page.Scratch.Set "custom-landing-page-context" . }}
3944
{{ .Content }}
4045
{{ else }}
41-
{{ .Content }}
4246
{{ range .Pages.ByWeight }}
4347
<h2>
4448
<a href="{{ if .Params.url}}{{ .Params.url}}{{else}}{{ .Permalink }}{{end}}">{{ .Title }}</a>

layouts/partials/custom-landing-page.html

Lines changed: 0 additions & 48 deletions
This file was deleted.

layouts/partials/list-main.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ <h1 class="bd-title">
1111
</p>
1212
{{ end}}
1313
{{ partial "banner" .}}
14-
{{ $hasCustomContent := .Params.hasCustomContent | default false }}
14+
{{ $hasCustomContent := index .Params "nd-landing-page" | default false }}
1515
{{ if $hasCustomContent }}
16-
{{ .Page.Scratch.Set "custom-landing-page-file-name" "custom-landing-page.html" }}
17-
{{ .Page.Scratch.Set "custom-landing-page-context" . }}
1816
{{ .Content }}
1917
{{ else }}
2018
<section data-mf="false">

layouts/shortcodes/card-layout.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
<!-- Render the main content first with modifications, then render the custom content -->
2-
{{ $customLandingPageFileName := .Page.Scratch.Get "custom-landing-page-file-name" }}
3-
{{ $customLandingPageContext := .Page.Scratch.Get "custom-landing-page-context" }}
4-
{{ partial $customLandingPageFileName $customLandingPageContext }}
5-
<div class="card-layout">{{- .Inner | markdownify -}}</div>
2+
<div class="card-layout">{{ .Inner | markdownify }}</div>

layouts/shortcodes/card-section.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{ $title := .Get "title" }}
2+
{{ $isFeaturedSectionParam := .Get "isFeaturedSection" | default "false" }}
23
{{ $showAsCardsParam := .Get "showAsCards" | default "false"}}
34
{{- /* Validate the parameter strictly */ -}}
45
{{- if not (in (slice "true" "false") $showAsCardsParam) -}}
@@ -8,13 +9,20 @@
89
{{- $current := .Page.Scratch.Get "showAsCards" | default (dict) -}}
910
{{- $newShowAsCards := dict ($title | default "main") ($showAsCards) -}}
1011
{{- .Page.Scratch.Set "showAsCards" (merge $current ($newShowAsCards)) -}}
11-
{{- $class := "card-grid wide" -}}
12+
{{- /* Limit the cards if it is a featured section */ -}}
13+
{{- if not (in (slice "true" "false") $isFeaturedSectionParam) -}}
14+
{{- warnf "The '<card-section>' Shortcode parameter 'isFeaturedSection' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $isFeaturedSectionParam -}}
15+
{{- end -}}
16+
{{- $isFeaturedSection := cond (eq $isFeaturedSectionParam "true") "true" "false" -}}
17+
{{- $class := "card-grid" -}}
1218
{{- /* Validate that the parent is card-layout */ -}}
1319
{{ if eq .Parent.Name "card-layout"}}
14-
<div class="card-section" data-mf="true" style="display: none;">
20+
<div class="card-section {{if eq $isFeaturedSection "true"}}featured-section{{ end }}">
1521
{{- if $title -}}
1622
<strong class="card-section-title">{{- $title -}}</strong>
1723
<div class="card-section-content{{ if eq $showAsCards "true" }} {{ $class }} {{ end }}">{{- .Inner -}}</div>
24+
{{ else }}
25+
<div class="card-section-content{{ if eq $showAsCards "true" }} {{ $class }} {{ end }}">{{ .Inner }}</div>
1826
{{ end }}
1927
</div>
2028
<div class="row" data-mf="false">

layouts/shortcodes/card.html

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
{{- $title := .Get "title" -}}
22
{{- $titleUrl := .Get "titleUrl" | default "/" -}}
3-
{{- $icon := .Get "icon" | default "NGINX-product-icon" -}}
3+
{{- $icon := .Get "icon" | default "book-open" -}}
4+
{{- $brandIcon := .Get "brandIcon" -}}
5+
{{- $isFeaturedParam := .Get "isFeatured" | default "false" }}
6+
{{- /* Validate the parameter strictly */ -}}
7+
{{- if not (in (slice "true" "false") $isFeaturedParam) -}}
8+
{{- warnf "The '<card>' Shortcode parameter 'isFeatured' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $isFeaturedParam -}}
9+
{{- end -}}
10+
{{- $isFeatured := cond (eq $isFeaturedParam "true") "true" "false" -}}
411
{{- $current := .Page.Scratch.Get "cards" | default (slice) -}}
512
{{- $newCard := dict "title" ($title) "content" (.Inner) -}}
613
{{- .Page.Scratch.Set "cards" ($current | append $newCard) -}}
7-
{{- /* Validate that the parent is card-section */ -}}
8-
{{- if eq .Parent.Name "card-section" -}}
9-
<div class="card-container" style="display: none;" data-mf="true">
14+
{{- /* Validate that the parent is card-section and under 3 cards */ -}}
15+
{{- if (eq .Parent.Name "card-section") -}}
16+
<div class="card-container {{ if eq $isFeatured "true" }}featured-card{{ end }}">
1017
{{- if $title -}}
11-
{{- if $titleUrl -}}
12-
<h2 class="card-title"><a href="{{- $titleUrl -}}">{{- $title -}}</a></h2>
13-
{{- else -}}
14-
<h2 class="card-title">{{- $title -}}</h2>
15-
{{- end -}}
18+
<div class="card-header">
19+
{{- if $brandIcon -}}
20+
<img class="card-brand-icon" src="/images/icons/{{ $brandIcon }}.svg">
21+
{{- else -}}
22+
{{- if $icon -}}
23+
{{ partial "lucide" (dict "context" . "icon" $icon) }}
24+
{{- end -}}
25+
{{- end -}}
26+
{{- if $titleUrl -}}
27+
<h2 class="card-title"><a href="{{- $titleUrl -}}">{{- $title -}}</a></h2>
28+
{{- else -}}
29+
<h2 class="card-title">{{- $title -}}</h2>
30+
{{- end -}}
31+
</div>
1632
{{- else -}}
1733
{{ errorf "Mainframe: Missing param 'title'" }}
1834
{{- end -}}

0 commit comments

Comments
 (0)