From e0940bd4d32d5876ecee5060eedd11a88f37fd31 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Mon, 17 Aug 2026 12:47:50 +0800 Subject: [PATCH] fix(layouts): resolve accessibility and SEO issues from AI crawler support (#830) --- hugo.toml | 21 +++++++++++++++++++ layouts/_partials/base/head/index.html | 18 ++++++++++++++++ layouts/baseof.html | 1 - layouts/home.llms.txt | 29 ++++++++++++++++++++++++++ layouts/posts/single.html | 5 +++++ layouts/robots.txt | 18 ++++++++++++++++ 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 layouts/home.llms.txt diff --git a/hugo.toml b/hugo.toml index 05f882f9..be41e7cd 100644 --- a/hugo.toml +++ b/hugo.toml @@ -401,6 +401,15 @@ rel = "manifest" isPlainText = true isHTML = false +# Options to make output llms.txt file (AI-friendly site map). +# Add "llms" to home outputs to enable. +[outputFormats.llms] +baseName = "llms" +mediaType = "text/plain" +isPlainText = true +isHTML = false +notAlternative = true + # ------------------------------------------------------------------------------------- # Output Configuration # See: https://gohugo.io/configuration/outputs/ @@ -1157,6 +1166,18 @@ light_theme = "light" dark_theme = "dark" lazy_load = true +# robots.txt configuration (requires enableRobotsTXT = true). +[params.robots] +# Allow AI crawlers (unblock GPTBot/ClaudeBot etc.) + Content-Signal comment + AI hidden hint. +allow_crawlers = false +# Custom rules appended to robots.txt (optional). +# [[params.robots.rules]] +# user_agent = "SomeBot" +# disallow = "/" +# [[params.robots.rules]] +# user_agent = "GoodBot" +# allow = "/" + # Third-party library configuration for some custom CSS and JS files. # Files can be loaded from local assets (relative to /assets/) or remote CDN URLs. # The key is a unique identifier, the value is the file path or URL. diff --git a/layouts/_partials/base/head/index.html b/layouts/_partials/base/head/index.html index fad24ec1..40f51e86 100644 --- a/layouts/_partials/base/head/index.html +++ b/layouts/_partials/base/head/index.html @@ -19,6 +19,24 @@ +{{- /* Robots meta tag: respect page-level robots frontmatter; default to index,follow with max-image-preview:large only when cover exists */ -}} +{{- if isset .Params "robots" -}} + +{{- else -}} + {{- $hasCover := false -}} + {{- if .IsHome -}} + {{- $hasCover = isset .Site.Params.seo "cover" -}} + {{- else if .IsPage -}} + {{- $cover := dict "Page" . | partial "function/get-cover.html" -}} + {{- $hasCover = or $cover.Source $cover.Matches -}} + {{- end -}} + {{- if $hasCover -}} + + {{- else -}} + + {{- end -}} +{{- end -}} + {{- $keywords := .Keywords -}} {{- if not $keywords -}} {{- if .IsPage | and .Params.tags -}} diff --git a/layouts/baseof.html b/layouts/baseof.html index 5ea1ef4a..73232103 100644 --- a/layouts/baseof.html +++ b/layouts/baseof.html @@ -8,7 +8,6 @@ {{- end }} -