Skip to content

Commit a27abb4

Browse files
johanrinclaude
andcommitted
Improve SEO with meta tags and structured data fixes
- Add og:image:width and og:image:height for better social previews - Add twitter:image:alt for accessibility - Add DNS prefetch for Google Analytics - Add noindex to 404 page - Fix schema.org context to use https:// - Add image dimensions to JSON-LD structured data Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 66423ae commit a27abb4

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

layouts/partials/custom-head.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
{{/* Enhanced Open Graph and Twitter Card Meta Tags */}}
22

3+
{{/* DNS prefetch for external services */}}
4+
<link rel="dns-prefetch" href="https://www.googletagmanager.com" />
5+
<link rel="dns-prefetch" href="https://www.google-analytics.com" />
6+
7+
{{/* Prevent 404 pages from being indexed */}}
8+
{{ if eq .Kind "404" }}
9+
<meta name="robots" content="noindex, nofollow" />
10+
{{ end }}
11+
312
{{/* Canonical URL */}}
413
<link rel="canonical" href="{{ .Permalink }}" />
514

615
{{/* Open Graph URL - for all pages */}}
716
<meta property="og:url" content="{{ .Permalink }}" />
817

18+
{{/* Open Graph Image dimensions for better social previews */}}
19+
<meta property="og:image:width" content="1200" />
20+
<meta property="og:image:height" content="630" />
21+
22+
{{/* Twitter image alt text for accessibility */}}
23+
{{- $description := .Description | default .Site.Params.description -}}
24+
<meta name="twitter:image:alt" content="{{ $description }}" />
25+
926
{{/* Open Graph Type - set to "article" for posts, "website" for all other pages */}}
1027
{{ if eq .Section "posts" }}
1128
{{/* og:type="article" is already set in theme's meta/post.html */}}

layouts/partials/meta/post.html

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{{/* These meta tags are rendered only in the posts section (i.e. in single/list page) */}}
2+
{{ if eq .Section "posts" }}
3+
{{ $ISO_date := dateFormat "2006-01-02T15:04:05Z0700" .Date | safeHTML }}
4+
<!-- Pagination meta tags for list pages only -->
5+
{{ if ne .Page.Kind "page" }}
6+
{{ $paginator := .Paginate (where .Pages "Section" "blog") }}
7+
{{ if $paginator }}
8+
<link rel="first" href="{{ $paginator.First.URL }}" />
9+
<link rel="last" href="{{ $paginator.Last.URL }}" />
10+
{{ if $paginator.HasPrev }}
11+
<link rel="prev" href="{{ $paginator.Prev.URL }}" />
12+
{{end }}
13+
{{ if $paginator.HasNext }}
14+
<link rel="next" href="{{ $paginator.Next.URL }}" />
15+
{{end }}
16+
{{end }}
17+
{{end }}
18+
19+
<meta property="og:type" content="article" />
20+
<meta property="og:article:published_time" content={{ $ISO_date | safeHTML }} />
21+
<meta property="article:published_time" content={{ $ISO_date | safeHTML }} />
22+
<meta property="og:url" content="{{ .Permalink }}" />
23+
24+
{{ with.Site.Params.author }}
25+
<meta property="og:article:author" content="{{ .name }}" />
26+
<meta property="article:author" content="{{ .name }}" />
27+
<meta name="author" content="{{ .name }}" />
28+
{{ with.fediverseAccount }}
29+
<meta name="fediverse:creator" content="{{ . }}" />{{/* ref https://blog.joinmastodon.org/2024/07/highlighting-journalism-on-mastodon/ */}}
30+
{{ end }}
31+
{{ end }}
32+
33+
{{ with.Params.category }}
34+
<meta name="news_keywords" content="{{ index . 0 }}" />
35+
<meta property="article:section" content="{{ index . 0 }}" />
36+
{{ end }}
37+
38+
<script defer type="application/ld+json">
39+
{
40+
"@context": "https://schema.org",
41+
"@type": "Article",
42+
"headline": {{ .Title }},
43+
"author": {
44+
"@type": "Person",
45+
"name": "{{ .Site.Params.github }}"
46+
},
47+
"datePublished": "{{ dateFormat "2006-01-02" .Date }}",
48+
"description": {{ .Description }},
49+
"wordCount": {{ .WordCount }},
50+
"mainEntityOfPage": "True",
51+
"dateModified": "{{ dateFormat "2006-01-02" .Lastmod }}",
52+
"image": {
53+
"@type": "ImageObject",
54+
"url": "{{ with .Params.images }}{{ index . 0 | absURL }}{{ end }}",
55+
"width": 1200,
56+
"height": 630
57+
},
58+
"publisher": {
59+
"@type": "Organization",
60+
"name": "{{ .Site.Title }}"
61+
}
62+
}
63+
</script>
64+
{{ end }}

0 commit comments

Comments
 (0)