Skip to content

Commit efc3861

Browse files
committed
Better meta tags
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 0ffaa6b commit efc3861

3 files changed

Lines changed: 86 additions & 21 deletions

File tree

layouts/_default/baseof.html

Lines changed: 86 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,64 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<meta http-equiv="x-ua-compatible" content="ie=edge">
88

9-
<title>{{ block "title" . }}{{ .Site.Title }}{{ end }}</title>
10-
<link rel="canonical" href="{{ .Site.BaseURL }}">
11-
<meta name="description" content="{{ block "description" . }}{{ .Site.Params.Description }}{{ end }}">
12-
13-
<meta property="og:type" content="website">
14-
<meta property="og:url" content="{{ .Site.BaseURL }}">
15-
<meta property="og:title" content="{{ .Site.Title }}">
16-
<meta property="og:description" content="{{ .Site.Params.Description }}">
17-
<meta property="og:image" content="{{ .Site.BaseURL }}screenshot.webp">
18-
<meta property="og:image:type" content="image/webp">
19-
<meta property="og:image:width" content="2592">
20-
<meta property="og:image:height" content="1191">
9+
{{- $isBlogPost := and .IsPage (eq .Section "blog") -}}
10+
{{- $title := cond .IsHome .Site.Title .Title -}}
11+
{{- $rawDescription := "" -}}
12+
{{- if .IsHome -}}
13+
{{- $rawDescription = .Site.Params.Description -}}
14+
{{- else -}}
15+
{{- $rawDescription = .Description | default (.Summary | plainify) | default .Site.Params.Description -}}
16+
{{- end -}}
17+
{{- $description := trim (replaceRE "\\s+" " " $rawDescription) " " -}}
18+
{{- if gt (len $description) 200 -}}
19+
{{- $description = printf "%s…" (substr $description 0 199) -}}
20+
{{- end -}}
21+
{{- $url := .Permalink -}}
22+
{{- $image := printf "%sscreenshot.webp" .Site.BaseURL -}}
23+
{{- $imageWidth := 2592 -}}
24+
{{- $imageHeight := 1191 -}}
25+
{{- if $isBlogPost -}}
26+
{{- $cover := "" -}}
27+
{{- with .Resources.GetMatch "*.webp" -}}{{- $cover = . -}}{{- end -}}
28+
{{- if not $cover -}}{{- with .Resources.GetMatch "*.png" -}}{{- $cover = . -}}{{- end -}}{{- end -}}
29+
{{- with $cover -}}
30+
{{- $image = .Permalink -}}
31+
{{- $imageWidth = .Width -}}
32+
{{- $imageHeight = .Height -}}
33+
{{- end -}}
34+
{{- end -}}
35+
{{- $ogType := cond $isBlogPost "article" "website" -}}
36+
{{- $author := "" -}}
37+
{{- if $isBlogPost -}}
38+
{{- $author = index .Site.Data.authors (.Params.author | default "") -}}
39+
{{- end -}}
40+
41+
<title>{{ $title }}</title>
42+
<link rel="canonical" href="{{ $url }}">
43+
<meta name="description" content="{{ $description }}">
44+
45+
<meta property="og:type" content="{{ $ogType }}">
46+
<meta property="og:url" content="{{ $url }}">
47+
<meta property="og:title" content="{{ $title }}">
48+
<meta property="og:description" content="{{ $description }}">
49+
<meta property="og:image" content="{{ $image }}">
50+
<meta property="og:image:width" content="{{ $imageWidth }}">
51+
<meta property="og:image:height" content="{{ $imageHeight }}">
52+
{{- if $isBlogPost }}
53+
<meta property="article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
54+
{{- if and (not .Lastmod.IsZero) (ne .Date.Unix .Lastmod.Unix) }}
55+
<meta property="article:modified_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}">
56+
{{- end }}
57+
{{- with $author }}
58+
<meta property="article:author" content="{{ .name }}">
59+
{{- end }}
60+
<meta property="article:section" content="Blog">
61+
{{- end }}
2162

2263
<meta name="twitter:card" content="summary_large_image">
23-
<meta name="twitter:title" content="{{ .Site.Title }}">
24-
<meta name="twitter:description" content="{{ .Site.Params.Description }}">
25-
<meta name="twitter:image" content="{{ .Site.BaseURL }}screenshot.webp">
64+
<meta name="twitter:title" content="{{ $title }}">
65+
<meta name="twitter:description" content="{{ $description }}">
66+
<meta name="twitter:image" content="{{ $image }}">
2667

2768
{{ $style := resources.Get "main.scss" | toCSS (dict "outputStyle" "compressed") }}
2869
<link rel="stylesheet" href="{{ $style.Permalink }}">
@@ -32,6 +73,36 @@
3273
<link rel="manifest" href="{{ .Site.BaseURL }}manifest.webmanifest">
3374
<link rel="alternate" type="application/rss+xml" title="{{ .Site.Title }} Blog" href="{{ .Site.BaseURL }}blog/index.xml">
3475

76+
{{- if $isBlogPost }}
77+
<script type="application/ld+json">
78+
{
79+
"@context": "https://schema.org",
80+
"@type": "BlogPosting",
81+
"headline": {{ .Title | jsonify | safeJS }},
82+
"description": {{ $description | jsonify | safeJS }},
83+
"image": {{ $image | jsonify | safeJS }},
84+
"datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" | jsonify | safeJS }},
85+
"dateModified": {{ (.Lastmod | default .Date).Format "2006-01-02T15:04:05Z07:00" | jsonify | safeJS }},
86+
"mainEntityOfPage": {{ $url | jsonify | safeJS }},
87+
{{- with $author }}
88+
"author": {
89+
"@type": "Person",
90+
"name": {{ .name | jsonify | safeJS }}{{ with .url }},
91+
"url": {{ . | jsonify | safeJS }}{{ end }}
92+
},
93+
{{- end }}
94+
"publisher": {
95+
"@type": "Organization",
96+
"name": "Sourcemeta",
97+
"logo": {
98+
"@type": "ImageObject",
99+
"url": {{ (printf "%slogo.svg" .Site.BaseURL) | jsonify | safeJS }}
100+
}
101+
}
102+
}
103+
</script>
104+
{{- end }}
105+
35106
<script defer src="https://cdn.telemetrydeck.com/websdk/telemetrydeck.min.js" data-app-id="5BEC8971-2BEA-4D7C-A436-54EBDF4D6D93"></script>
36107
</head>
37108
<body>

layouts/article/single.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{{ define "title" }}{{ .Title }}{{ end }}
2-
{{ define "description" }}{{ .Summary }}{{ end }}
3-
41
{{ define "main" }}
52
<main class="border-top">
63
<div class="container mt-4 mb-5">

layouts/blog/single.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{{ define "title" }}{{ .Title }}{{ end }}
2-
{{ define "description" }}{{ .Summary }}{{ end }}
3-
41
{{ define "main" }}
52
<main class="border-top">
63
<div class="container mt-5 mb-5">

0 commit comments

Comments
 (0)