Skip to content

Commit 90eff01

Browse files
committed
feat: enhance schema markup, refine layouts, and improve error handling
- Added structured data for website, posts, and "about me" pages using JSON-LD - Adjusted post-card headings from `<h2>` to `<h1>` for semantic correctness - Refined meta title and description logic for better clarity and consistency - Centralized favicon and stylesheet link elements with minor adjustments - Introduced custom error responses for CloudFront to handle 403 and 404 errors effectively - Updated header logic for reusability by using partial templates
1 parent 350cc30 commit 90eff01

7 files changed

Lines changed: 83 additions & 27 deletions

File tree

hugo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ enableRobotsTXT = true
66

77
[params]
88
description = "Inzichten over home automation, Java en agile werken. Praktische tutorials en opinies in het Nederlands."
9+
descriptionLong = "Nederlandstalige blog over home automation, Java en agile werken, met heldere how-to's, praktijkvoorbeelden en meningen voor engineers die graag blijven leren."
910
keywords = ["Maarten Casteels", "home automation", "domotica", "java", "agile", "software engineering"]
11+
tagline = "Eerlijke inzichten over software en automatisatie"
1012

1113
languageCode = "nl-be"
1214
defaultContentLanguage = "nl"

infra/cloudfront.tf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ resource "aws_cloudfront_distribution" "cf_distribution" {
4343
}
4444
}
4545

46+
custom_error_response {
47+
error_code = 403
48+
response_page_path = "/404.html"
49+
response_code = 404
50+
error_caching_min_ttl = 60
51+
}
52+
53+
custom_error_response {
54+
error_code = 404
55+
response_page_path = "/404.html"
56+
response_code = 404
57+
error_caching_min_ttl = 60
58+
}
59+
4660
restrictions {
4761
geo_restriction {
4862
restriction_type = "none"
@@ -196,4 +210,4 @@ resource "aws_cloudfront_function" "rewrite_function" {
196210
runtime = "cloudfront-js-2.0"
197211
publish = true
198212
code = file("${path.module}/function.js")
199-
}
213+
}

static/ads.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# No ads are served on this site.

themes/custom/layouts/partials/head.html

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
<meta charset="utf-8" />
22
<meta name="viewport" content="width=device-width, initial-scale=1" />
3-
{{- $pageTitle := .Title | default .Site.Title -}}
4-
{{- $fullTitle := cond .IsHome .Site.Title (printf "%s · %s" $pageTitle .Site.Title) -}}
5-
{{- $rawDescription := .Params.description | default .Summary | default .Site.Params.description -}}
3+
{{- $siteTitle := .Site.Title | default "Site" -}}
4+
{{- $pageTitle := .Title | default $siteTitle -}}
5+
{{- $tagline := .Site.Params.tagline | default $siteTitle -}}
6+
{{- $fullTitle := "" -}}
7+
{{- if .IsHome -}}
8+
{{- $fullTitle = printf "%s · %s" $siteTitle $tagline -}}
9+
{{- else if or (eq .Kind "taxonomy") (eq .Kind "term") -}}
10+
{{- $termTitle := .Title | default $pageTitle -}}
11+
{{- if eq .Kind "term" -}}
12+
{{- $termTitle = .Data.Term | default $termTitle -}}
13+
{{- end -}}
14+
{{- $fullTitle = printf "Tag: %s · %s" $termTitle $siteTitle -}}
15+
{{- else -}}
16+
{{- $fullTitle = printf "%s · %s" $pageTitle $siteTitle -}}
17+
{{- end -}}
18+
{{- $rawDescription := "" -}}
19+
{{- if .IsHome -}}
20+
{{- $rawDescription = .Site.Params.descriptionLong | default .Site.Params.description -}}
21+
{{- else -}}
22+
{{- $rawDescription = .Params.description | default .Summary | default .Site.Params.description -}}
23+
{{- end -}}
624
{{- $description := "" -}}
725
{{- if $rawDescription -}}
8-
{{- $description = ($rawDescription | plainify | htmlUnescape | truncate 160) -}}
26+
{{- $description = ($rawDescription | plainify | htmlUnescape | truncate 220) -}}
927
{{- end -}}
1028
{{- $keywordsValue := "" -}}
11-
{{- if .Params.keywords -}}
12-
{{- if reflect.IsSlice .Params.keywords -}}
13-
{{- $keywordsValue = delimit .Params.keywords ", " -}}
14-
{{- else -}}
15-
{{- $keywordsValue = .Params.keywords -}}
16-
{{- end -}}
17-
{{- else if .Site.Params.keywords -}}
29+
{{- $isAboutPage := and .IsPage (eq .Section "over-mij") -}}
30+
{{- if and (or .IsHome $isAboutPage) .Site.Params.keywords -}}
1831
{{- if reflect.IsSlice .Site.Params.keywords -}}
1932
{{- $keywordsValue = delimit .Site.Params.keywords ", " -}}
2033
{{- else -}}
@@ -31,7 +44,7 @@
3144
<link rel="canonical" href="{{ .Permalink }}">
3245
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
3346
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
34-
<link rel="icon" type="image/x-icon" href="/favicon.ico">
47+
<link rel="shortcut icon" href="/favicon.ico">
3548
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
3649
<link rel="manifest" href="/site.webmanifest">
3750
{{ template "_internal/opengraph.html" . }}
@@ -99,8 +112,7 @@
99112

100113
{{ $css := resources.Get "css/main.css" | css.PostCSS }}
101114
{{ if hugo.IsProduction }}
102-
{{ $css = $css | minify | fingerprint }}
103-
{{ else }}
104-
{{ $css = $css | fingerprint }}
115+
{{ $css = $css | minify }}
105116
{{ end }}
106-
<link rel="stylesheet" href="{{ $css.RelPermalink }}" integrity="{{ $css.Data.Integrity }}" crossorigin="anonymous" />
117+
{{ $css = $css | fingerprint }}
118+
<link rel="stylesheet" href="{{ $css.RelPermalink }}"{{ with $css.Data.Integrity }} integrity="{{ . }}" crossorigin="anonymous"{{ end }} />

themes/custom/layouts/partials/header.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
class="inline-flex min-w-0 items-center gap-3 rounded-full text-slate-900 hover:text-moss focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-moss dark:text-slate-100 dark:hover:text-mustard dark:focus-visible:outline-moss"
55
href="{{ .Site.Home.RelPermalink }}"
66
>
7-
<img
8-
src="{{ "/maarten.webp" | relURL }}"
9-
alt="Maarten"
10-
class="h-9 w-9 shrink-0 rounded-full border border-slate-200 object-cover dark:border-slate-800"
11-
loading="lazy"
12-
decoding="async"
13-
/>
7+
{{ partial "image.html" (dict
8+
"page" .
9+
"src" "/maarten.webp"
10+
"alt" ""
11+
"class" "h-9 w-9 shrink-0 rounded-full border border-slate-200 object-cover dark:border-slate-800"
12+
"sizes" "36px"
13+
"loading" "lazy"
14+
"decoding" "async"
15+
) }}
1416
<span class="truncate text-base font-semibold sm:text-lg">{{ .Site.Title }}</span>
1517
</a>
1618
<div class="ml-auto flex items-center gap-3 md:gap-4">

themes/custom/layouts/partials/post-card.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
{{- end -}}
4848

4949
<div class="space-y-2">
50-
<h2 class="text-xl font-semibold text-slate-900 dark:text-slate-100">
50+
<h1 class="text-xl font-semibold text-slate-900 dark:text-slate-100">
5151
<a
5252
class="hover:text-moss hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-moss dark:hover:text-mustard dark:focus-visible:outline-moss"
5353
href="{{ $page.RelPermalink }}"
5454
>
5555
<span class="absolute inset-0" aria-hidden="true"></span>
5656
<span class="relative z-10">{{ $title }}</span>
5757
</a>
58-
</h2>
58+
</h1>
5959

6060
{{- with $page.Date -}}
6161
<p class="text-sm text-slate-500 dark:text-slate-400">

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<script type="application/ld+json">
2+
{
3+
"@context": "https://schema.org",
4+
"@type": "WebSite",
5+
"name": {{ .Site.Title | jsonify }},
6+
"url": {{ .Site.BaseURL | jsonify }}
7+
}
8+
</script>
19
{{- if eq .Section "posts" -}}
210
{{- $rawDescription := .Params.description | default .Summary | default .Site.Params.description | default .Site.Title -}}
311
{{- $description := $rawDescription | plainify | htmlUnescape | truncate 160 -}}
@@ -18,14 +26,20 @@
1826
{{- $authorName = $author -}}
1927
{{- end -}}
2028
{{- end -}}
29+
{{- $hasModified := and .Lastmod (ne .Lastmod .Date) -}}
2130
<script type="application/ld+json">
2231
{
2332
"@context": "https://schema.org",
2433
"@type": "BlogPosting",
2534
"headline": {{ .Title | jsonify }},
2635
"datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" | jsonify }},
36+
{{- if $hasModified }}
2737
"dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | jsonify }},
28-
"mainEntityOfPage": {{ .Permalink | jsonify }},
38+
{{- end }}
39+
"mainEntityOfPage": {
40+
"@type": "WebPage",
41+
"@id": {{ .Permalink | jsonify }}
42+
},
2943
"description": {{ $description | jsonify }}{{ if $authorName }},
3044
"author": {
3145
"@type": "Person",
@@ -36,3 +50,14 @@
3650
}
3751
</script>
3852
{{- end -}}
53+
{{- if and .IsPage (eq .Section "over-mij") -}}
54+
{{- $sameAs := .Site.Params.sameAs -}}
55+
<script type="application/ld+json">
56+
{
57+
"@context": "https://schema.org",
58+
"@type": "Person",
59+
"name": "Maarten"{{ if $sameAs }},
60+
"sameAs": {{ $sameAs | jsonify }}{{ end }}
61+
}
62+
</script>
63+
{{- end -}}

0 commit comments

Comments
 (0)