Skip to content

Commit 975f42a

Browse files
committed
feat: improve blog layout and JSON-LD structure
- Added `list.html` layout to display post lists with pagination and featured post integration. - Enhanced `schema-jsonld.html` with additional `Blog` node and `ItemList` support for structured post lists. - Updated homepage layout to manage pagination initialization dynamically.
1 parent 271b01c commit 975f42a

3 files changed

Lines changed: 81 additions & 3 deletions

File tree

themes/custom/layouts/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ <h1 class="hidden">Laatste posts</h1>
44
<div class="flex flex-col gap-6">
55
{{- $pageSize := 5 -}}
66
{{- $posts := where .Site.RegularPages "Section" "posts" -}}
7-
{{- $paginator := .Paginate $posts $pageSize -}}
7+
{{- $paginator := .Paginator -}}
8+
{{- if not $paginator -}}
9+
{{- $paginator = .Paginate $posts $pageSize -}}
10+
{{- end -}}
811
{{- if eq $paginator.PageNumber 1 -}}
912
<section class="space-y-2">
1013
<h2 class="text-[0.7rem] font-medium uppercase tracking-[0.2em] text-slate-400 dark:text-slate-500">Intro</h2>

themes/custom/layouts/partials/schema-jsonld.html

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
{{- $siteTitle := .Site.Title | default "Site" -}}
88
{{- $orgId := printf "%s#org" $siteURL -}}
99
{{- $websiteId := printf "%s#website" $siteURL -}}
10+
{{- $blogId := printf "%s#blog" $siteURL -}}
1011
{{- $logoId := printf "%s#logo" $siteURL -}}
1112

1213
{{- $logoURL := .Site.Params.avatar -}}
@@ -115,6 +116,27 @@
115116
-}}
116117
{{- $nodes = $nodes | append $website -}}
117118

119+
{{- $siteDescription := .Site.Params.descriptionLong | default .Site.Params.description -}}
120+
{{- $blogNode := dict
121+
"@type" "Blog"
122+
"@id" $blogId
123+
"name" $siteTitle
124+
"url" $siteURL
125+
"isPartOf" (dict "@id" $websiteId)
126+
"publisher" (dict "@id" $orgId)
127+
-}}
128+
{{- if $siteDescription -}}
129+
{{- $blogNode = merge $blogNode (dict "description" $siteDescription) -}}
130+
{{- end -}}
131+
{{- if $personName -}}
132+
{{- $blogNode = merge $blogNode (dict "author" (dict "@id" $personId)) -}}
133+
{{- end -}}
134+
{{- $languageCode := .Site.Language.LanguageCode | default .Site.Language.Lang | default .Site.LanguageCode -}}
135+
{{- if $languageCode -}}
136+
{{- $blogNode = merge $blogNode (dict "inLanguage" $languageCode) -}}
137+
{{- end -}}
138+
{{- $nodes = $nodes | append $blogNode -}}
139+
118140
{{- if $personName -}}
119141
{{- $personNode := dict
120142
"@type" "Person"
@@ -147,13 +169,40 @@
147169
"name" $webpageName
148170
"isPartOf" (dict "@id" $websiteId)
149171
-}}
150-
{{- $languageCode := .Site.Language.LanguageCode | default .Site.Language.Lang | default .Site.LanguageCode -}}
151172
{{- if $languageCode -}}
152173
{{- $webpageNode = merge $webpageNode (dict "inLanguage" $languageCode) -}}
153174
{{- end -}}
175+
176+
{{- $isPostList := or .IsHome (and (eq .Kind "section") (eq .Section "posts")) -}}
177+
{{- if $isPostList -}}
178+
{{- $pageSize := 5 -}}
179+
{{- $posts := where .Site.RegularPages "Section" "posts" -}}
180+
{{- $paginator := .Paginate $posts $pageSize -}}
181+
{{- $listPages := $paginator.Pages -}}
182+
{{- if gt (len $listPages) 0 -}}
183+
{{- $itemListId := printf "%s#itemlist" $pageURL -}}
184+
{{- $itemListElements := slice -}}
185+
{{- range $index, $page := $listPages -}}
186+
{{- $itemListElements = $itemListElements | append (dict
187+
"@type" "ListItem"
188+
"position" (add $index 1)
189+
"item" (dict "@id" $page.Permalink "name" $page.Title)
190+
) -}}
191+
{{- end -}}
192+
{{- $itemListNode := dict
193+
"@type" "ItemList"
194+
"@id" $itemListId
195+
"itemListElement" $itemListElements
196+
"numberOfItems" (len $listPages)
197+
-}}
198+
{{- $webpageNode = merge $webpageNode (dict "mainEntity" (dict "@id" $itemListId)) -}}
199+
{{- $nodes = $nodes | append $itemListNode -}}
200+
{{- end -}}
201+
{{- end -}}
202+
154203
{{- $nodes = $nodes | append $webpageNode -}}
155204

156-
{{- if eq .Section "posts" -}}
205+
{{- if and .IsPage (eq .Section "posts") -}}
157206
{{- $imageURL := "" -}}
158207
{{- with .Params.cover.image -}}
159208
{{- with $.Resources.GetMatch . -}}
@@ -174,6 +223,7 @@
174223
"headline" .Title
175224
"datePublished" (.Date.Format "2006-01-02T15:04:05Z07:00")
176225
"mainEntityOfPage" (dict "@id" $webpageId)
226+
"isPartOf" (dict "@id" $blogId)
177227
"publisher" (dict "@id" $orgId)
178228
-}}
179229
{{- if $personName -}}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{ define "main" }}
2+
<div class="mx-auto flex w-full max-w-3xl flex-col gap-6 text-slate-800 dark:text-slate-100">
3+
<h1 class="hidden">Laatste posts</h1>
4+
<div class="flex flex-col gap-6">
5+
{{- $pageSize := 5 -}}
6+
{{- $posts := where .Site.RegularPages "Section" "posts" -}}
7+
{{- $paginator := .Paginator -}}
8+
{{- if not $paginator -}}
9+
{{- $paginator = .Paginate $posts $pageSize -}}
10+
{{- end -}}
11+
{{- if and (eq $paginator.PageNumber 1) (gt (len $paginator.Pages) 0) -}}
12+
{{- $featured := index $paginator.Pages 0 -}}
13+
{{ partial "featured-post-card.html" (dict "page" $featured) }}
14+
{{- end -}}
15+
{{- $listPages := $paginator.Pages -}}
16+
{{- if and (eq $paginator.PageNumber 1) (gt (len $paginator.Pages) 0) -}}
17+
{{- $listPages = after 1 $paginator.Pages -}}
18+
{{- end -}}
19+
{{ range $listPages }}
20+
{{ partial "post-card.html" (dict "page" .) }}
21+
{{ end }}
22+
</div>
23+
{{ partial "pagination.html" (dict "p" $paginator) }}
24+
</div>
25+
{{ end }}

0 commit comments

Comments
 (0)