From bdbae42253b19f6f52b12300a74a19064d303e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=A4=952077?= <274166795@qq.com> Date: Wed, 25 Jun 2025 05:02:27 +0000 Subject: [PATCH] add seo --- assets/css/custom.css | 4 + hugo.yaml | 20 +++- layouts/partials/custom/head-end.html | 136 +++++++++++++++++++++++++- 3 files changed, 156 insertions(+), 4 deletions(-) diff --git a/assets/css/custom.css b/assets/css/custom.css index f495648..382d1af 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -20,6 +20,10 @@ word-break: break-word; /* 兼容旧浏览器 */ } +.content blockquote p a { + display: none; +} + /* * --- 1. 定义核心色调 --- * Pornhub 标志性橙色: #ff9900 diff --git a/hugo.yaml b/hugo.yaml index 2578eb1..bfb9df3 100644 --- a/hugo.yaml +++ b/hugo.yaml @@ -57,6 +57,24 @@ menu: params: description: AI 洞察日报 是一个基于 Cloudflare Workers 驱动的内容聚合与生成平台。它每日为您精选 AI 领域的最新动态,包括行业新闻、热门开源项目、前沿学术论文、科技大V社交媒体言论,并通过 Google Gemini 模型进行智能处理与摘要生成,最终自动发布到 GitHub Pages 生成 AI 日报 + logo: "images/logo.png" + + author: + name: "何夕2077" + bio: "去海边整点薯条" + email: "justlikemaki@qq.com" + website: "https://ai.hubtoday.app/about/" + social: + - name: "GitHub" + url: "https://github.com/justlovemaki" + + publisher: + type: "Person" + name: "何夕2077" + url: "https://ai.hubtoday.app/about/" + sameAs: + - "https://github.com/justlovemaki" + displayUpdatedDate: true dateFormat: "2006/01/02 15:04:05" @@ -117,4 +135,4 @@ languages: ja: contentDir: content/ja languageName: 日本語 - weight: 4 + weight: 4 \ No newline at end of file diff --git a/layouts/partials/custom/head-end.html b/layouts/partials/custom/head-end.html index 0ab062e..3c9080f 100644 --- a/layouts/partials/custom/head-end.html +++ b/layouts/partials/custom/head-end.html @@ -1,9 +1,9 @@ \ No newline at end of file + + + +{{ "" | safeHTML }} + +{{/* --- Publisher Block --- */}} +{{- $publisher := "" -}} +{{- with .Site.Params.publisher -}} + {{- $p := . -}} + {{- $type := .type | default "Organization" -}} + {{- $name := .name | default $.Site.Title -}} + + {{- $publisherData := dict "@type" $type "name" $name -}} + {{- if eq $type "Organization" -}} + {{- with .logo -}} + {{- $logoData := dict "@type" "ImageObject" "url" ( . | absURL ) -}} + {{- $publisherData = merge $publisherData (dict "logo" $logoData) -}} + {{- end -}} + {{- else if eq $type "Person" -}} + {{- with .url -}} + {{- $publisherData = merge $publisherData (dict "url" ( . | absURL )) -}} + {{- end -}} + {{- with .sameAs -}} + {{- $publisherData = merge $publisherData (dict "sameAs" .) -}} + {{- end -}} + {{- end -}} + {{- $publisher = $publisherData -}} +{{- end -}} + + +{{/* --- Author Block --- */}} +{{- $author := "" -}} +{{/* 1. Check for single author in page Front Matter */}} +{{- $author_id := .Params.author -}} +{{- if and $author_id (index .Site.Data.authors $author_id) -}} + {{- $authorData := index .Site.Data.authors $author_id -}} + {{- $author = dict "@type" "Person" "name" $authorData.name -}} + {{- with $authorData.website -}} + {{- $author = merge $author (dict "url" ( . | absURL )) -}} + {{- end -}} +{{/* 2. Fallback to global author in hugo.yaml `params` */}} +{{- else if .Site.Params.author -}} + {{- $author = dict "@type" "Person" "name" .Site.Params.author.name -}} + {{- with .Site.Params.author.website -}} + {{- $author = merge $author (dict "url" ( . | absURL )) -}} + {{- end -}} +{{/* 3. Fallback to global author in hugo.yaml `author` */}} +{{- else if .Site.Author.name -}} + {{- $author = dict "@type" "Person" "name" .Site.Author.name -}} + {{- with .Site.Author.website -}} + {{- $author = merge $author (dict "url" ( . | absURL )) -}} + {{- end -}} +{{- end -}} + +{{- if .IsHome -}} + {{/* --- WebSite Schema --- */}} + {{- $schema := dict "@context" "https://schema.org" "@type" "WebSite" -}} + {{- $schema = merge $schema (dict "url" .Site.BaseURL "name" .Site.Title) -}} + {{- with .Site.Params.description -}} + {{- $schema = merge $schema (dict "description" .) -}} + {{- end -}} + {{- with $publisher -}} + {{- $schema = merge $schema (dict "publisher" .) -}} + {{- end -}} + + +{{- else if .IsPage -}} + {{/* --- Article/TechArticle Schema --- */}} + {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} + {{- $schema := dict "@context" "https://schema.org" "@type" "TechArticle" -}} + {{- $schema = merge $schema (dict + "mainEntityOfPage" (dict "@type" "WebPage" "@id" .Permalink) + "headline" .Title + "url" .Permalink + "wordCount" .WordCount + ) -}} + + {{- $description := .Description | default .Summary -}} + {{- with $description -}} + {{- $schema = merge $schema (dict "description" .) -}} + {{- end -}} + + {{- $image := "" -}} + {{- if .Params.image.url -}} + {{- $image = .Params.image -}} + {{- else if .Site.Params.image.url -}} + {{- $image = .Site.Params.image -}} + {{- end -}} + {{- with $image -}} + {{- if ge .width 696 -}} + {{- $imageData := dict "@type" "ImageObject" "url" ( .url | absURL ) "width" .width "height" .height -}} + {{- $schema = merge $schema (dict "image" $imageData) -}} + {{- end -}} + {{- end -}} + + {{- with .Type -}} + {{- $schema = merge $schema (dict "genre" .) -}} + {{- end -}} + {{- with .Params.tags -}} + {{- $schema = merge $schema (dict "keywords" (delimit . ", ")) -}} + {{- end -}} + + {{- $published := .PublishDate | default .Date -}} + {{- if not $published.IsZero -}} + {{- $schema = merge $schema (dict "datePublished" ($published.Format $iso8601)) -}} + {{- end -}} + {{- with .Lastmod -}} + {{- if not .IsZero -}} + {{- $schema = merge $schema (dict "dateModified" (.Format $iso8601)) -}} + {{- end -}} + {{- end -}} + + {{- with .Site.Copyright -}} + {{- $schema = merge $schema (dict "license" .) -}} + {{- end -}} + + {{- with $publisher -}} + {{- $schema = merge $schema (dict "publisher" .) -}} + {{- end -}} + {{- with $author -}} + {{- $schema = merge $schema (dict "author" .) -}} + {{- end -}} + + + +{{- end }} +{{ "" | safeHTML }} \ No newline at end of file