{{ if not .IsHome }}
{{ if not (in .Params.display_breadcrumb "false" ) }}
{{ partial "breadcrumb" .}}
{{ end }}
{{ end }}
-
+
@@ -42,8 +40,7 @@
-
-
+
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index 9c5837b4..4284f4e2 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -1,28 +1,25 @@
{{ define "main" }}
-
{{ end }}
-
- {{ if not .IsHome }}
- {{ if not (in .Params.display_breadcrumb "false" ) }}
- {{ partial "breadcrumb" .}}
- {{ end }}
- {{ end }}
-
+
{{ partial "banner" .}}
+
- {{ if .Page.Lastmod }}
+ {{ if not .IsHome }}
+ {{ if not (in .Params.display_breadcrumb "false" ) }}
+ {{ partial "breadcrumb" .}}
+ {{ end }}
+ {{ end }}
+
+ {{ .Title }}
+ {{ $content | safeHTML }} + {{ if eq .Page.Draft true }}{{ partial "draft-badge.html" . }}{{ end }} {{ if in .Params.doctypes "beta" }}{{ partial "beta-badge" . }}{{ end }} -- {{ if .Page.Lastmod }}
{{ partial "page-meta-links" . }}
@@ -46,6 +43,4 @@
{{ .Title }}
- - {{ end }} diff --git a/layouts/partials/callout.html b/layouts/partials/callout.html index 314137ac..52bac5ee 100644 --- a/layouts/partials/callout.html +++ b/layouts/partials/callout.html @@ -13,10 +13,10 @@ {{ $sideOption := "side-callout" }} {{ $inlineOption := "inline-callout" }} +{{/* Default to inline callout */}} +{{ $dataGrid := "first-two-thirds" }} {{ if $sideline }} - {{ $class = printf "%s %s" $class $sideOption }} -{{ else }} - {{ $class = printf "%s %s" $class $inlineOption }} + {{ $dataGrid = "last-third" }} {{ end }} {{/* Render a different block, if "loud" callouts are used */}} @@ -33,7 +33,7 @@ {{ $isSpecialTitle := in $specialTitles $type }} {{ if $isSpecialTitle }} {{/* Loud callouts */}} -+{{ partial "feather" (dict "context" . "icon" $icon) .}} @@ -51,7 +51,7 @@ {{ $cleanTitle := strings.TrimSuffix ":" $title}} -+{{- with $icon -}} diff --git a/layouts/partials/homepage.html b/layouts/partials/homepage.html new file mode 100644 index 00000000..52bd5acf --- /dev/null +++ b/layouts/partials/homepage.html @@ -0,0 +1,5 @@ ++\ No newline at end of file diff --git a/layouts/redoc/single.html b/layouts/redoc/single.html index 2451793d..81248520 100644 --- a/layouts/redoc/single.html +++ b/layouts/redoc/single.html @@ -1,6 +1,7 @@ {{ define "main" }}+ {{ .Content }} +++ diff --git a/layouts/shortcodes/card-layout.html b/layouts/shortcodes/card-layout.html index e5337167..57d83472 100644 --- a/layouts/shortcodes/card-layout.html +++ b/layouts/shortcodes/card-layout.html @@ -1,2 +1,2 @@ -{{ partial "breadcrumb" . }}{{ .Content}}{{- .Inner | markdownify -}}+{{- .Inner | markdownify -}}diff --git a/layouts/shortcodes/card-section.html b/layouts/shortcodes/card-section.html index c05caa9b..26478172 100644 --- a/layouts/shortcodes/card-section.html +++ b/layouts/shortcodes/card-section.html @@ -1,6 +1,7 @@ {{ $title := .Get "title" }} {{ $isFeaturedSectionParam := .Get "isFeaturedSection" | default "false" }} {{ $showAsCardsParam := .Get "showAsCards" | default "false"}} + {{- /* Validate the parameter strictly */ -}} {{- if not (in (slice "true" "false") $showAsCardsParam) -}} {{- warnf "The '' Shortcode parameter 'showAsCards' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $showAsCardsParam -}} @@ -15,14 +16,18 @@ {{- end -}} {{- $isFeaturedSection := cond (eq $isFeaturedSectionParam "true") "true" "false" -}} {{- $class := "card-grid" -}} + +{{- /* Get number of cards */ -}} +{{ $cardCount := len (findRE " " .Inner) }} + {{- /* Validate that the parent is card-layout */ -}} {{ if eq .Parent.Name "card-layout"}} -+{{- if $title -}} {{- $title -}} -{{ else }} diff --git a/layouts/shortcodes/card.html b/layouts/shortcodes/card.html index b4d55878..7fdb157c 100644 --- a/layouts/shortcodes/card.html +++ b/layouts/shortcodes/card.html @@ -1,39 +1,63 @@ {{- $title := .Get "title" -}} -{{- $titleUrl := .Get "titleUrl" | default "/" -}} +{{- $titleUrl := .Get "titleUrl" | default "." -}} {{- $icon := .Get "icon" | default "book-open" -}} {{- $brandIcon := .Get "brandIcon" -}} -{{- $isFeaturedParam := .Get "isFeatured" | default "false" }} +{{- $isFeaturedParam := .Get "isFeaturedCard" | default "false" }} +{{- $isFullSizeParam := .Get "isFullSize" | default "false" -}} +{{- $isLandingParam := .Get "isLanding" | default "false" }} + {{- /* Validate the parameter strictly */ -}} {{- if not (in (slice "true" "false") $isFeaturedParam) -}} - {{- warnf "The '{{- .Inner -}}+{{ .Inner }}{{ else }} -{{ .Inner }}+{{ .Inner }}{{ end }}' Shortcode parameter 'isFeatured' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $isFeaturedParam -}} + {{- warnf "The ' ' Shortcode parameter 'isFeaturedCard' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $isFeaturedParam -}} {{- end -}} {{- $isFeatured := cond (eq $isFeaturedParam "true") "true" "false" -}} -{{- $current := .Page.Scratch.Get "cards" | default (slice) -}} -{{- $newCard := dict "title" ($title) "content" (.Inner) -}} -{{- .Page.Scratch.Set "cards" ($current | append $newCard) -}} + +{{- if not (in (slice "true" "false") $isFullSizeParam) -}} + {{- warnf "The ' ' Shortcode parameter 'isFullSize' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $isFullSizeParam -}} +{{- end -}} +{{- $isFullSize := cond (eq $isFullSizeParam "true") "true" "false" -}} + +{{- if not (in (slice "true" "false") $isLandingParam) -}} + {{- warnf "The ' ' Shortcode parameter 'isLanding' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $isLandingParam -}} +{{- end -}} +{{- $isLanding := cond (eq $isLandingParam "true") "true" "false" -}} + +{{- /* Set up the positioning */ -}} +{{ $dataGrid := "" }} +{{ if or (eq $isFullSize "true") (eq $isFeatured "true") }} + {{ $dataGrid = "wide"}} +{{ else if (eq $isLanding "true") }} + {{ $dataGrid = "third"}} +{{ else }} + {{ $dataGrid = "half"}} +{{ end }} + +{{- /* Build the url */ -}} +{{ if eq (substr $titleUrl 0 1) "/" }} + {{ $suggestedUrlFix := substr $titleUrl 1 }} + {{ errorf "Please do not start the param 'titleUrl' with a forward slash. Got: '%s', use '%s' instead." $titleUrl $suggestedUrlFix }} +{{ end }} +{{ $url := printf "%s%s" .Page.Permalink $titleUrl }} + {{- /* Validate that the parent is card-section and under 3 cards */ -}} {{- if (eq .Parent.Name "card-section") -}} - + +{{- if $title -}}+ {{- else -}} {{ errorf "The '{{- if $brandIcon -}}{{- else -}} {{ errorf "Mainframe: Missing param 'title'" }} {{- end -}} - {{ .Inner }} +- {{- else -}} - {{- if $icon -}} - {{ partial "lucide" (dict "context" . "icon" $icon) }} - {{- end -}} - {{- end -}} - {{- if $titleUrl -}} -
{{- $title -}}
- {{- else -}} -{{- $title -}}
+ {{- else if $icon -}} + {{ partial "lucide" (dict "context" . "icon" $icon) }} {{- end -}} +{{- $title -}}
{{ .Inner }}' must be nested directly inside the shortcode ' '. Please see the exampleSite for an example of usage." }} {{- end -}} \ No newline at end of file diff --git a/tests/src/cards.spec.js b/tests/src/cards.spec.js new file mode 100644 index 00000000..3f40eb38 --- /dev/null +++ b/tests/src/cards.spec.js @@ -0,0 +1,71 @@ +import { expect, test } from '@playwright/test'; + +test.describe('Testing for cards shortcode', () => { + test.beforeEach(async ({ page }) => { + const cardsUrl = 'test-product/cards/permitted'; + await page.goto(`/${cardsUrl}`); + }); + + test('should test basic section', async ({ page }) => { + const section = await page.locator('data-testid=cards-test__basic'); + const basicCode = await section.locator('data-testid=card-section-content'); + const showAsCardCode = await section.locator( + 'data-testid=card-section-content__card-grid' + ); + + expect(await basicCode.count()).toBeTruthy(); + expect(await showAsCardCode.count()).toBe(0); + }); + + test('should test showAsCard section', async ({ page }) => { + const section = await page.locator('data-testid=cards-test__showAsCards'); + const showAsCardCode = await section.locator( + 'data-testid=card-section-content__card-grid' + ); + + expect(await showAsCardCode.count()).toBeTruthy(); + }); + + test('should test featured section', async ({ page }) => { + const section = await page.locator( + 'data-testid=cards-test__featuredSection' + ); + const featuredSection = await section.locator( + 'data-testid=card-section__featured-section' + ); + const cards = await ( + await featuredSection.locator('data-testid=card') + ).all(); + + // Test featured section exists AND there are less than or equal to 3 cards. + expect(await featuredSection.count()).toBeTruthy(); + const visibleCards = []; + for (const card of cards) { + if (await card.isVisible()) { + visibleCards.push(card); + } + } + expect(visibleCards.length).toBeLessThanOrEqual(3); + }); + + test('should test featured card', async ({ page }) => { + const section = await page.locator('data-testid=cards-test__featuredCard'); + const featuredCard = await section.locator( + 'data-testid=card__featured-card' + ); + const cards = await (await section.locator('data-testid=card')).all(); + const featuredCardOrder = await featuredCard.evaluate((el) => { + return window.getComputedStyle(el).getPropertyValue('order'); + }); + + // Test featured card exist AND is the first one in the order + expect(await featuredCard.count()).toBeTruthy(); + expect(featuredCardOrder).toBe('1'); + for (const card of cards) { + const order = await card.evaluate((el) => { + return window.getComputedStyle(el).getPropertyValue('order'); + }); + expect(order).toBe('2'); + } + }); +});