Skip to content

Commit 87b11eb

Browse files
authored
Merge pull request #64 from Mazizova/seo/indexing-basics
SEO: add robots.txt, noindex thin taxonomy pages, fix future sitemap lastmod
2 parents e93febc + 289afd3 commit 87b11eb

5 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎hugo.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ params:
3636
category_id: "DIC_kwDOSeSzss4DFPF-"
3737

3838
buildFuture: true
39+
enableRobotsTXT: true
3940

4041
markup:
4142
goldmark:

‎layouts/_default/sitemap.xml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{/*
2+
Same as Hugo's built-in sitemap, except it skips pages that are noindex
3+
(see partials/seo/indexable.html) and drops <lastmod> values in the
4+
future — upcoming events otherwise push list pages' lastmod past today,
5+
which search engines treat as invalid.
6+
*/}}
7+
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
8+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
9+
{{- range where .Pages "Sitemap.Disable" "ne" true }}
10+
{{- if and .Permalink (partial "seo/indexable.html" .) }}
11+
<url>
12+
<loc>{{ .Permalink }}</loc>
13+
{{- if and (not .Lastmod.IsZero) (le .Lastmod.Unix now.Unix) }}
14+
<lastmod>{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</lastmod>
15+
{{- end }}
16+
</url>
17+
{{- end }}
18+
{{- end }}
19+
</urlset>

‎layouts/partials/head.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{{ with .Params.author }}<meta name="author" content="{{ . }}">{{ end }}
1515

1616
{{/* ── Robots ── */}}
17-
<meta name="robots" content="index, follow">
17+
<meta name="robots" content="{{ if partial "seo/indexable.html" . }}index{{ else }}noindex{{ end }}, follow">
1818

1919
{{/* ── Feed auto-discovery (only present on pages that actually have one, e.g. /blog/) ── */}}
2020
{{ range .AlternativeOutputFormats }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{/*
2+
Whether a page should be indexed by search engines. Used by head.html
3+
(meta robots) and the sitemap template so the two never disagree.
4+
5+
Taxonomy overview pages (/pricing/, /levels/, ...) and most facet term
6+
pages (/pricing/free/, /countries/brazil/, ...) are thin filter views of
7+
the same resources, so they are noindex (links on them are still
8+
followed). Subcategory terms with at least 3 resources are kept — those
9+
are real topical landing pages ("Monitoring & Observability", ...).
10+
Any page can override with `robots: noindex` in front matter.
11+
*/}}
12+
{{ $indexable := true }}
13+
{{ if eq .Kind "taxonomy" }}
14+
{{ $indexable = false }}
15+
{{ else if eq .Kind "term" }}
16+
{{ $indexable = and (eq .Data.Plural "subcategories") (ge (len .Pages) 3) }}
17+
{{ end }}
18+
{{ with .Params.robots }}{{ if in . "noindex" }}{{ $indexable = false }}{{ end }}{{ end }}
19+
{{ return $indexable }}

‎layouts/robots.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
User-agent: *
2+
Allow: /
3+
4+
Sitemap: {{ "sitemap.xml" | absURL }}

0 commit comments

Comments
 (0)