From bc254bcab044aaa40346dadb0843aa638cf9444c Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Mon, 12 Aug 2024 17:46:33 +0800 Subject: [PATCH 01/22] :mag: Refactor: add JSON feed support and refactor output formats build in FixIt Close #475 --- hugo.toml | 51 ++++++++++++++--------- layouts/index.feed.json | 46 ++++++++++++++++++++ layouts/{index.json => index.search.json} | 0 layouts/partials/assets.html | 2 +- layouts/partials/head/link.html | 20 +++++---- layouts/partials/head/meta.html | 5 ++- layouts/partials/init/index.html | 2 +- 7 files changed, 94 insertions(+), 32 deletions(-) create mode 100644 layouts/index.feed.json rename layouts/{index.json => index.search.json} (100%) diff --git a/hugo.toml b/hugo.toml index 2c62cea4..135083f4 100644 --- a/hugo.toml +++ b/hugo.toml @@ -231,12 +231,12 @@ enableEmoji = true # ------------------------------------------------------------------------------------- [mediaTypes] - # Options to make output .md files - [mediaTypes."text/markdown"] - suffixes = ["md"] # Options to make output .txt files [mediaTypes."text/plain"] suffixes = ["txt"] + # Options to make output feed.json files + [mediaTypes."application/feed+json"] + suffixes = ["json"] # ------------------------------------------------------------------------------------- # Output Format Definitions @@ -244,11 +244,6 @@ enableEmoji = true # ------------------------------------------------------------------------------------- [outputFormats] - # Options to make output .md files - [outputFormats.MarkDown] - mediaType = "text/markdown" - isPlainText = true - isHTML = false # FixIt 0.3.0 | NEW Options to make output /archives/index.html file [outputFormats.archives] path = "archives" @@ -257,6 +252,7 @@ enableEmoji = true isPlainText = false isHTML = true permalinkable = true + notAlternative = true # FixIt 0.3.0 | NEW Options to make output /offline/index.html file [outputFormats.offline] path = "offline" @@ -265,18 +261,35 @@ enableEmoji = true isPlainText = false isHTML = true permalinkable = true + notAlternative = true # FixIt 0.3.0 | NEW Options to make output readme.md file - [outputFormats.README] + [outputFormats.readme] baseName = "readme" mediaType = "text/markdown" isPlainText = true isHTML = false + notAlternative = true # FixIt 0.3.0 | CHANGED Options to make output baidu_urls.txt file [outputFormats.baidu_urls] baseName = "baidu_urls" mediaType = "text/plain" isPlainText = true isHTML = false + notAlternative = true + # FixIt 0.3.10 | NEW Options to make output feed.json file + [outputFormats.feed] + baseName = "feed" + mediaType = "application/feed+json" + isPlainText = true + isHTML = false + # FixIt 0.3.10 | NEW Options to make output search.json file + [outputFormats.search] + baseName = "search" + mediaType = "application/json" + rel = "search" + isPlainText = true + isHTML = false + permalinkable = true # ------------------------------------------------------------------------------------- # Customizing Output Formats @@ -284,17 +297,17 @@ enableEmoji = true # ------------------------------------------------------------------------------------- # Options to make hugo output files, the optional values are below: -# home: ["HTML", "RSS", "JSON", "archives", "offline", "README", "baidu_urls"] -# page: ["HTML", "MarkDown"] -# section: ["HTML", "RSS"] -# taxonomy: ["HTML", "RSS"] -# term: ["HTML", "RSS"] +# home: html, rss, json, feed, archives, offline, readme, baidu_urls, search etc. +# page: html, markdown +# section: html, rss +# taxonomy: html, rss +# term: html, rss [outputs] - home = ["HTML", "RSS", "JSON", "archives"] - page = ["HTML", "MarkDown"] - section = ["HTML", "RSS"] - taxonomy = ["HTML"] - term = ["HTML", "RSS"] + home = ["html", "rss", "feed", "archives", "offline", "readme", "baidu_urls", "search"] + page = ["html", "markdown"] + section = ["html", "rss"] + taxonomy = ["html", "rss"] + term = ["html", "rss"] # ------------------------------------------------------------------------------------- # Taxonomies Configuration diff --git a/layouts/index.feed.json b/layouts/index.feed.json new file mode 100644 index 00000000..1720d6f5 --- /dev/null +++ b/layouts/index.feed.json @@ -0,0 +1,46 @@ +{{ $list := .Pages -}} +{{ $length := (len $list) -}} + +{ + "version" : "https://jsonfeed.org/version/1.1", + "title" : "{{- .Site.Title -}}", + "description": "{{- .Site.Params.description | default .Site.Title -}}", + "home_page_url" : "{{ .Site.BaseURL }}", + {{ with .OutputFormats.Get "JSONFeed" -}} + "feed_url" : "{{ .Permalink }}", + {{ end -}} + "icon" : "{{ `/apple-touch-icon.png` | absURL }}", + "favicon" : "{{ `/favicon.ico` | absURL }}", + {{ with .Site.Params.author.name -}} + "author" : { + "name" : "{{ . }}"{{ with $.Site.Params.author.link }}, + "url": "{{ . }}"{{ end }}{{ with $.Site.Params.author.avatar }}, + "avatar": "{{ . | absURL }}"{{ end }} + }, + {{ end -}} + "items" : [ + {{ range $index, $element := .Scratch.Get "mainSectionPages" -}} + { + "title" : {{ .Title | jsonify }}, + "date_published" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", + {{ if .Lastmod -}} + "date_modified" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", + {{ else -}} + "date_modified" : "{{ .LastMod.Format "2006-01-02T15:04:05Z07:00" }}", + {{ end -}} + "id" : "{{ .Permalink }}", + "url" : "{{ .Permalink }}", + {{ with .Summary -}} + "summary": {{ . | plainify | jsonify }}, + {{ end -}} + {{ with (.Param "author").name -}} + "author" : { + "name" : "{{ . }}" + }, + {{ end -}} + "content_html" : {{ .Content | jsonify }}, + "language": {{ .Language.Lang | default $.Lang | jsonify }} + }{{ if ne (add $index 1) $length }},{{ end }} + {{ end -}} + ] +} diff --git a/layouts/index.json b/layouts/index.search.json similarity index 100% rename from layouts/index.json rename to layouts/index.search.json diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index ebdb2a00..54ff1e5f 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -16,7 +16,7 @@ {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} {{- $config = dict "type" "algolia" "algoliaIndex" $search.algolia.index "algoliaAppID" $search.algolia.appID "algoliaSearchKey" $search.algolia.searchKey | dict "search" | merge $config -}} {{- else if eq $search.type "fuse" -}} - {{- with .Site.Home.OutputFormats.Get "json" -}} + {{- with .Site.Home.OutputFormats.Get "search" -}} {{- $config = dict "type" "fuse" "fuseIndexURL" .RelPermalink | dict "search" | merge $config -}} {{- end -}} {{- $source := $cdn.fuseJS | default "lib/fuse/fuse.min.js" -}} diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html index a48979ba..701557f9 100644 --- a/layouts/partials/head/link.html +++ b/layouts/partials/head/link.html @@ -1,5 +1,9 @@ {{- $cdn := .Scratch.Get "cdn" | default dict -}} {{- $fingerprint := .Scratch.Get "fingerprint" -}} +{{- $title := printf "%s | %s" .Title site.Title -}} +{{- if .IsHome -}} + {{- $title = site.Title -}} +{{- end -}} {{- if not .Site.Params.app.noFavicon -}} {{- with .Site.Params.app.svgFavicon -}} @@ -18,17 +22,15 @@ {{- end -}} {{- end -}} - -{{- if .Prev -}} - + +{{- with .Prev -}} + {{- end -}} -{{- if .Next -}} - +{{- with .Next -}} + {{- end -}} - -{{- with .OutputFormats.Get "RSS" -}} - - +{{- range .AlternativeOutputFormats -}} + {{- printf `` .Rel .MediaType.Type .Permalink $title | safeHTML -}} {{- end -}} {{- /* style.min.css */ -}} diff --git a/layouts/partials/head/meta.html b/layouts/partials/head/meta.html index dadc6cea..fda0a5e2 100644 --- a/layouts/partials/head/meta.html +++ b/layouts/partials/head/meta.html @@ -1,7 +1,8 @@ {{- $params := partial "function/params.html" -}} +{{- $author := .Param "author" -}} - - + + {{- $keywords := .Keywords -}} diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index ea2a9a49..fff5310b 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-c936e541" -}} +{{- .Scratch.Set "version" "v0.3.10-66e628d4" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} From 049f6bb1cd08ede12b4186cb58fb3da42afb8430 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Mon, 12 Aug 2024 22:14:57 +0800 Subject: [PATCH 02/22] :truck: Feat: migrate index templates to layouts/_default folder and home.[name].html --- demo/hugo.toml | 2 ++ layouts/{ => _default}/index.baidu_urls.txt | 0 layouts/{ => _default}/index.feed.json | 0 layouts/{ => _default}/index.html | 0 layouts/{ => _default}/index.readme.md | 0 layouts/{ => _default}/index.search.json | 0 layouts/{index.archives.html => home.archives.html} | 0 layouts/{index.offline.html => home.offline.html} | 0 layouts/partials/init/index.html | 2 +- layouts/{index.rss.xml => rss.xml} | 0 10 files changed, 3 insertions(+), 1 deletion(-) rename layouts/{ => _default}/index.baidu_urls.txt (100%) rename layouts/{ => _default}/index.feed.json (100%) rename layouts/{ => _default}/index.html (100%) rename layouts/{ => _default}/index.readme.md (100%) rename layouts/{ => _default}/index.search.json (100%) rename layouts/{index.archives.html => home.archives.html} (100%) rename layouts/{index.offline.html => home.offline.html} (100%) rename layouts/{index.rss.xml => rss.xml} (100%) diff --git a/demo/hugo.toml b/demo/hugo.toml index 03e4d21d..a38746df 100644 --- a/demo/hugo.toml +++ b/demo/hugo.toml @@ -35,3 +35,5 @@ baseURL = "http://example.org/" # FixIt theme version version = "0.3.X" # e.g. "0.2.X", "0.2.15", "v0.2.15" etc. # ... + [params.search] + enable = true diff --git a/layouts/index.baidu_urls.txt b/layouts/_default/index.baidu_urls.txt similarity index 100% rename from layouts/index.baidu_urls.txt rename to layouts/_default/index.baidu_urls.txt diff --git a/layouts/index.feed.json b/layouts/_default/index.feed.json similarity index 100% rename from layouts/index.feed.json rename to layouts/_default/index.feed.json diff --git a/layouts/index.html b/layouts/_default/index.html similarity index 100% rename from layouts/index.html rename to layouts/_default/index.html diff --git a/layouts/index.readme.md b/layouts/_default/index.readme.md similarity index 100% rename from layouts/index.readme.md rename to layouts/_default/index.readme.md diff --git a/layouts/index.search.json b/layouts/_default/index.search.json similarity index 100% rename from layouts/index.search.json rename to layouts/_default/index.search.json diff --git a/layouts/index.archives.html b/layouts/home.archives.html similarity index 100% rename from layouts/index.archives.html rename to layouts/home.archives.html diff --git a/layouts/index.offline.html b/layouts/home.offline.html similarity index 100% rename from layouts/index.offline.html rename to layouts/home.offline.html diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index fff5310b..a611c8d0 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-66e628d4" -}} +{{- .Scratch.Set "version" "v0.3.10-288e10e8" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/index.rss.xml b/layouts/rss.xml similarity index 100% rename from layouts/index.rss.xml rename to layouts/rss.xml From dcd9d8148244db9646559e9547320caa86d4fa07 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 10:35:26 +0800 Subject: [PATCH 03/22] :pencil: Style(ignore): fix typo --- layouts/_default/index.feed.json | 2 +- layouts/partials/init/index.html | 2 +- layouts/rss.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/layouts/_default/index.feed.json b/layouts/_default/index.feed.json index 1720d6f5..c440fef5 100644 --- a/layouts/_default/index.feed.json +++ b/layouts/_default/index.feed.json @@ -6,7 +6,7 @@ "title" : "{{- .Site.Title -}}", "description": "{{- .Site.Params.description | default .Site.Title -}}", "home_page_url" : "{{ .Site.BaseURL }}", - {{ with .OutputFormats.Get "JSONFeed" -}} + {{ with .OutputFormats.Get "feed" -}} "feed_url" : "{{ .Permalink }}", {{ end -}} "icon" : "{{ `/apple-touch-icon.png` | absURL }}", diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index a611c8d0..963390c1 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-288e10e8" -}} +{{- .Scratch.Set "version" "v0.3.10-049f6bb1" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/rss.xml b/layouts/rss.xml index dd7087f4..463b27cb 100644 --- a/layouts/rss.xml +++ b/layouts/rss.xml @@ -33,7 +33,7 @@ {{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}} {{- end -}} - {{ with .OutputFormats.Get "RSS" }} + {{ with .OutputFormats.Get "rss" }} {{ printf "" .Permalink .MediaType | safeHTML }} {{ end }} {{- range .Scratch.Get "mainSectionPages" | first (.Site.Params.home.rss | default 10) -}} From f9288d6cdd05dbdd9c27485f2c4686e332ea1be0 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 12:17:16 +0800 Subject: [PATCH 04/22] :truck: Chore: migrate index templates to default home templates --- layouts/{ => _default}/home.archives.html | 0 ...dex.baidu_urls.txt => home.baidu_urls.txt} | 0 .../{index.feed.json => home.feed.json} | 0 layouts/_default/{index.html => home.html} | 0 layouts/{ => _default}/home.offline.html | 0 .../{index.readme.md => home.readme.md} | 0 layouts/_default/home.search.json | 46 +++++++++++++++++++ layouts/_default/index.search.json | 46 ------------------- layouts/partials/init/index.html | 2 +- 9 files changed, 47 insertions(+), 47 deletions(-) rename layouts/{ => _default}/home.archives.html (100%) rename layouts/_default/{index.baidu_urls.txt => home.baidu_urls.txt} (100%) rename layouts/_default/{index.feed.json => home.feed.json} (100%) rename layouts/_default/{index.html => home.html} (100%) rename layouts/{ => _default}/home.offline.html (100%) rename layouts/_default/{index.readme.md => home.readme.md} (100%) create mode 100644 layouts/_default/home.search.json delete mode 100644 layouts/_default/index.search.json diff --git a/layouts/home.archives.html b/layouts/_default/home.archives.html similarity index 100% rename from layouts/home.archives.html rename to layouts/_default/home.archives.html diff --git a/layouts/_default/index.baidu_urls.txt b/layouts/_default/home.baidu_urls.txt similarity index 100% rename from layouts/_default/index.baidu_urls.txt rename to layouts/_default/home.baidu_urls.txt diff --git a/layouts/_default/index.feed.json b/layouts/_default/home.feed.json similarity index 100% rename from layouts/_default/index.feed.json rename to layouts/_default/home.feed.json diff --git a/layouts/_default/index.html b/layouts/_default/home.html similarity index 100% rename from layouts/_default/index.html rename to layouts/_default/home.html diff --git a/layouts/home.offline.html b/layouts/_default/home.offline.html similarity index 100% rename from layouts/home.offline.html rename to layouts/_default/home.offline.html diff --git a/layouts/_default/index.readme.md b/layouts/_default/home.readme.md similarity index 100% rename from layouts/_default/index.readme.md rename to layouts/_default/home.readme.md diff --git a/layouts/_default/home.search.json b/layouts/_default/home.search.json new file mode 100644 index 00000000..29336eff --- /dev/null +++ b/layouts/_default/home.search.json @@ -0,0 +1,46 @@ +{{- if .Site.Params.search.enable -}} + {{- $index := slice -}} + {{- $pages := where .Site.RegularPages "Params.password" "eq" nil -}} + {{- if .Site.Params.page.hiddenFromSearch -}} + {{- $pages = where $pages "Params.hiddenfromsearch" false -}} + {{- else -}} + {{- $pages = where $pages "Params.hiddenfromsearch" "!=" true -}} + {{- end -}} + {{- range $pages -}} + {{- $uri := .RelPermalink -}} + {{- if $.Site.Params.search.absoluteURL -}} + {{- $uri = .Permalink -}} + {{- end -}} + {{- $meta := dict "uri" $uri "title" .Title "tags" .Params.tags "categories" .Params.categories -}} + {{- $meta = $.Site.Params.dateFormat | default "2006-01-02" | .PublishDate.Format | dict "date" | merge $meta -}} + {{- with .Description -}} + {{- $index = $index | append (dict "content" . "objectID" $uri | merge $meta) -}} + {{- end -}} + {{- $params := .Params | merge $.Site.Params.page -}} + {{/* Extended Markdown syntax */}} + {{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" -}} + {{/* Remove line number for code */}} + {{- $content = $content | replaceRE ` *\d*\n?` "" -}} + {{- range $i, $contenti := split $content "

*\d*\n?` "" -}} - {{- range $i, $contenti := split $content "

Date: Tue, 13 Aug 2024 14:35:37 +0800 Subject: [PATCH 05/22] :truck: Chore: migrate section templates to layouts/section folder --- hugo.toml | 12 +++--- layouts/_default/home.feed.json | 4 +- layouts/partials/init/index.html | 2 +- layouts/{posts => section}/rss.xml | 0 layouts/section/section.feed.json | 46 ++++++++++++++++++++++ layouts/{_default => section}/section.html | 0 6 files changed, 55 insertions(+), 9 deletions(-) rename layouts/{posts => section}/rss.xml (100%) create mode 100644 layouts/section/section.feed.json rename layouts/{_default => section}/section.html (100%) diff --git a/hugo.toml b/hugo.toml index 135083f4..c8ce3ddc 100644 --- a/hugo.toml +++ b/hugo.toml @@ -299,15 +299,15 @@ enableEmoji = true # Options to make hugo output files, the optional values are below: # home: html, rss, json, feed, archives, offline, readme, baidu_urls, search etc. # page: html, markdown -# section: html, rss -# taxonomy: html, rss -# term: html, rss +# section: html, rss, feed +# taxonomy: html, rss, feed +# term: html, rss, feed [outputs] home = ["html", "rss", "feed", "archives", "offline", "readme", "baidu_urls", "search"] page = ["html", "markdown"] - section = ["html", "rss"] - taxonomy = ["html", "rss"] - term = ["html", "rss"] + section = ["html", "rss", "feed"] + taxonomy = ["html", "rss", "feed"] + term = ["html", "rss", "feed"] # ------------------------------------------------------------------------------------- # Taxonomies Configuration diff --git a/layouts/_default/home.feed.json b/layouts/_default/home.feed.json index c440fef5..13144cd9 100644 --- a/layouts/_default/home.feed.json +++ b/layouts/_default/home.feed.json @@ -24,9 +24,9 @@ "title" : {{ .Title | jsonify }}, "date_published" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", {{ if .Lastmod -}} - "date_modified" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", - {{ else -}} "date_modified" : "{{ .LastMod.Format "2006-01-02T15:04:05Z07:00" }}", + {{ else -}} + "date_modified" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", {{ end -}} "id" : "{{ .Permalink }}", "url" : "{{ .Permalink }}", diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index eca413ff..8ac951e0 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-dcd9d814" -}} +{{- .Scratch.Set "version" "v0.3.10-f9288d6c" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/posts/rss.xml b/layouts/section/rss.xml similarity index 100% rename from layouts/posts/rss.xml rename to layouts/section/rss.xml diff --git a/layouts/section/section.feed.json b/layouts/section/section.feed.json new file mode 100644 index 00000000..13144cd9 --- /dev/null +++ b/layouts/section/section.feed.json @@ -0,0 +1,46 @@ +{{ $list := .Pages -}} +{{ $length := (len $list) -}} + +{ + "version" : "https://jsonfeed.org/version/1.1", + "title" : "{{- .Site.Title -}}", + "description": "{{- .Site.Params.description | default .Site.Title -}}", + "home_page_url" : "{{ .Site.BaseURL }}", + {{ with .OutputFormats.Get "feed" -}} + "feed_url" : "{{ .Permalink }}", + {{ end -}} + "icon" : "{{ `/apple-touch-icon.png` | absURL }}", + "favicon" : "{{ `/favicon.ico` | absURL }}", + {{ with .Site.Params.author.name -}} + "author" : { + "name" : "{{ . }}"{{ with $.Site.Params.author.link }}, + "url": "{{ . }}"{{ end }}{{ with $.Site.Params.author.avatar }}, + "avatar": "{{ . | absURL }}"{{ end }} + }, + {{ end -}} + "items" : [ + {{ range $index, $element := .Scratch.Get "mainSectionPages" -}} + { + "title" : {{ .Title | jsonify }}, + "date_published" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", + {{ if .Lastmod -}} + "date_modified" : "{{ .LastMod.Format "2006-01-02T15:04:05Z07:00" }}", + {{ else -}} + "date_modified" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", + {{ end -}} + "id" : "{{ .Permalink }}", + "url" : "{{ .Permalink }}", + {{ with .Summary -}} + "summary": {{ . | plainify | jsonify }}, + {{ end -}} + {{ with (.Param "author").name -}} + "author" : { + "name" : "{{ . }}" + }, + {{ end -}} + "content_html" : {{ .Content | jsonify }}, + "language": {{ .Language.Lang | default $.Lang | jsonify }} + }{{ if ne (add $index 1) $length }},{{ end }} + {{ end -}} + ] +} diff --git a/layouts/_default/section.html b/layouts/section/section.html similarity index 100% rename from layouts/_default/section.html rename to layouts/section/section.html From 008af168241b33c71dbc16375d741d2a48e9fcc3 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 14:41:13 +0800 Subject: [PATCH 06/22] :sparkles: Feat: add JSON feed support for section pages (#475) --- layouts/_default/home.feed.json | 6 +----- layouts/partials/init/index.html | 2 +- layouts/section/section.feed.json | 6 +----- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/layouts/_default/home.feed.json b/layouts/_default/home.feed.json index 13144cd9..6a177d25 100644 --- a/layouts/_default/home.feed.json +++ b/layouts/_default/home.feed.json @@ -23,11 +23,7 @@ { "title" : {{ .Title | jsonify }}, "date_published" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", - {{ if .Lastmod -}} - "date_modified" : "{{ .LastMod.Format "2006-01-02T15:04:05Z07:00" }}", - {{ else -}} - "date_modified" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", - {{ end -}} + "date_modified" : "{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}", "id" : "{{ .Permalink }}", "url" : "{{ .Permalink }}", {{ with .Summary -}} diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 8ac951e0..92740909 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-f9288d6c" -}} +{{- .Scratch.Set "version" "v0.3.10-65de5cad" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/section/section.feed.json b/layouts/section/section.feed.json index 13144cd9..6a177d25 100644 --- a/layouts/section/section.feed.json +++ b/layouts/section/section.feed.json @@ -23,11 +23,7 @@ { "title" : {{ .Title | jsonify }}, "date_published" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", - {{ if .Lastmod -}} - "date_modified" : "{{ .LastMod.Format "2006-01-02T15:04:05Z07:00" }}", - {{ else -}} - "date_modified" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", - {{ end -}} + "date_modified" : "{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}", "id" : "{{ .Permalink }}", "url" : "{{ .Permalink }}", {{ with .Summary -}} From 874913ce127a7b53c5cafe9eb43aaf709c7b8ca1 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 16:37:51 +0800 Subject: [PATCH 07/22] :construction: Feat: add common template for JSON feed (#475) --- hugo.toml | 13 ++++-- layouts/_default/home.feed.json | 43 +------------------ layouts/partials/feed/json-feed.html | 64 ++++++++++++++++++++++++++++ layouts/partials/head/link.html | 2 +- layouts/partials/init/index.html | 2 +- layouts/section/section.feed.json | 41 +----------------- layouts/taxonomy/list.feed.json | 3 ++ 7 files changed, 81 insertions(+), 87 deletions(-) create mode 100644 layouts/partials/feed/json-feed.html create mode 100644 layouts/taxonomy/list.feed.json diff --git a/hugo.toml b/hugo.toml index c8ce3ddc..b63fc610 100644 --- a/hugo.toml +++ b/hugo.toml @@ -297,16 +297,16 @@ enableEmoji = true # ------------------------------------------------------------------------------------- # Options to make hugo output files, the optional values are below: -# home: html, rss, json, feed, archives, offline, readme, baidu_urls, search etc. +# home: html, rss, feed, archives, offline, readme, baidu_urls, search etc. # page: html, markdown # section: html, rss, feed -# taxonomy: html, rss, feed +# taxonomy: html # term: html, rss, feed [outputs] home = ["html", "rss", "feed", "archives", "offline", "readme", "baidu_urls", "search"] page = ["html", "markdown"] section = ["html", "rss", "feed"] - taxonomy = ["html", "rss", "feed"] + taxonomy = ["html"] term = ["html", "rss", "feed"] # ------------------------------------------------------------------------------------- @@ -820,6 +820,13 @@ enableEmoji = true # ["barber-shop", "big-counter", "bounce", "center-atom", "center-circle", "center-radar", "center-simple", # "corner-indicator", "fill-left", "flash", "flat-top", "loading-bar", "mac-osx", "material", "minimal"] theme = "minimal" + + # FixIt 0.3.10 | NEW Feed config for RSS, Atom and JSON feed. + [params.feed] + # The number of posts to include in the feed. Default is -1, which means all posts. + limit = 10 + # whether to show the full text content in feed. + fullText = false # FixIt 0.2.15 | NEW Developer options # Select the scope named `public_repo` to generate personal access token, diff --git a/layouts/_default/home.feed.json b/layouts/_default/home.feed.json index 6a177d25..8e6d15b7 100644 --- a/layouts/_default/home.feed.json +++ b/layouts/_default/home.feed.json @@ -1,42 +1 @@ -{{ $list := .Pages -}} -{{ $length := (len $list) -}} - -{ - "version" : "https://jsonfeed.org/version/1.1", - "title" : "{{- .Site.Title -}}", - "description": "{{- .Site.Params.description | default .Site.Title -}}", - "home_page_url" : "{{ .Site.BaseURL }}", - {{ with .OutputFormats.Get "feed" -}} - "feed_url" : "{{ .Permalink }}", - {{ end -}} - "icon" : "{{ `/apple-touch-icon.png` | absURL }}", - "favicon" : "{{ `/favicon.ico` | absURL }}", - {{ with .Site.Params.author.name -}} - "author" : { - "name" : "{{ . }}"{{ with $.Site.Params.author.link }}, - "url": "{{ . }}"{{ end }}{{ with $.Site.Params.author.avatar }}, - "avatar": "{{ . | absURL }}"{{ end }} - }, - {{ end -}} - "items" : [ - {{ range $index, $element := .Scratch.Get "mainSectionPages" -}} - { - "title" : {{ .Title | jsonify }}, - "date_published" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", - "date_modified" : "{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}", - "id" : "{{ .Permalink }}", - "url" : "{{ .Permalink }}", - {{ with .Summary -}} - "summary": {{ . | plainify | jsonify }}, - {{ end -}} - {{ with (.Param "author").name -}} - "author" : { - "name" : "{{ . }}" - }, - {{ end -}} - "content_html" : {{ .Content | jsonify }}, - "language": {{ .Language.Lang | default $.Lang | jsonify }} - }{{ if ne (add $index 1) $length }},{{ end }} - {{ end -}} - ] -} +{{- partial "feed/json-feed.html" . -}} diff --git a/layouts/partials/feed/json-feed.html b/layouts/partials/feed/json-feed.html new file mode 100644 index 00000000..09623e38 --- /dev/null +++ b/layouts/partials/feed/json-feed.html @@ -0,0 +1,64 @@ +{{- $pages := .Scratch.Get "mainSectionPages" -}} +{{- $limit := .Site.Params.feed.limit -}} +{{- if ge $limit 1 -}} + {{- $pages = $pages | first $limit }} +{{- end -}} +{{- $length := $pages.Len -}} +{{- $fullText := (.Param "feed").fullText -}} +{{- $title := title (.Params.Title | default ((T .Section) | default .Section | dict "Some" | T "allSome")) -}} +{{- if .Site.Params.withSiteTitle -}} + {{- $title = printf "%s %s %s" $title .Site.Params.titleDelimiter .Site.Title -}} +{{- end -}} +{{- if .IsHome -}} + {{- $title = .Site.Title -}} +{{- end -}} + +{ + "version": "https://jsonfeed.org/version/1.1", + "title": "{{- $title -}}", + "description": "{{- .Site.Params.description | default .Site.Title -}}", + "home_page_url": "{{ .Site.BaseURL }}", + {{ with .OutputFormats.Get "feed" -}} + "feed_url": "{{ .Permalink }}", + {{ end -}} + {{ with .Site.LanguageCode -}} + "language": "{{ . }}", + {{ end -}} + "icon": "{{ `/apple-touch-icon.png` | absURL }}", + "favicon": "{{ `/favicon.ico` | absURL }}", + {{ with .Site.Params.author.name -}} + "author": { + "name": "{{ . }}"{{ with $.Site.Params.author.link }}, + "url": "{{ . }}"{{ end }}{{ with $.Site.Params.author.avatar }}, + "avatar": "{{ . | absURL }}"{{ end }} + }, + {{ end -}} + "items": [ + {{ range $index, $element := $pages -}} + { + "title": {{ .Title | jsonify }}, + "date_published": "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", + "date_modified": "{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}", + "id": "{{ .Permalink }}", + "url": "{{ .Permalink }}", + {{ with .Params.author.name -}} + "author": { + "name": "{{ . }}"{{ with $.Params.author.link }}, + "url": "{{ . }}"{{ end }}{{ with $.Params.author.avatar }}, + "avatar": "{{ . | absURL }}"{{ end }} + }, + {{ end -}} + {{ with .Summary -}} + "summary": {{ . | plainify | jsonify }}, + {{ if not $fullText -}} + "content_html": {{ . | plainify | jsonify }} + {{- end }} + {{- end -}} + {{- if $fullText -}} + "content_html": {{ .Content | jsonify }} + {{- end }} + }{{ if ne (add $index 1) $pages.Len }}, + {{ end }} + {{- end }} + ] +} diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html index 701557f9..9f9677b1 100644 --- a/layouts/partials/head/link.html +++ b/layouts/partials/head/link.html @@ -1,6 +1,6 @@ {{- $cdn := .Scratch.Get "cdn" | default dict -}} {{- $fingerprint := .Scratch.Get "fingerprint" -}} -{{- $title := printf "%s | %s" .Title site.Title -}} +{{- $title := printf "%s %s %s" .Title .Site.Params.titleDelimiter .Site.Title -}} {{- if .IsHome -}} {{- $title = site.Title -}} {{- end -}} diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 92740909..a9af1b43 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-65de5cad" -}} +{{- .Scratch.Set "version" "v0.3.10-138c7ad1" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/section/section.feed.json b/layouts/section/section.feed.json index 6a177d25..ba23ee71 100644 --- a/layouts/section/section.feed.json +++ b/layouts/section/section.feed.json @@ -1,42 +1,3 @@ -{{ $list := .Pages -}} -{{ $length := (len $list) -}} - { - "version" : "https://jsonfeed.org/version/1.1", - "title" : "{{- .Site.Title -}}", - "description": "{{- .Site.Params.description | default .Site.Title -}}", - "home_page_url" : "{{ .Site.BaseURL }}", - {{ with .OutputFormats.Get "feed" -}} - "feed_url" : "{{ .Permalink }}", - {{ end -}} - "icon" : "{{ `/apple-touch-icon.png` | absURL }}", - "favicon" : "{{ `/favicon.ico` | absURL }}", - {{ with .Site.Params.author.name -}} - "author" : { - "name" : "{{ . }}"{{ with $.Site.Params.author.link }}, - "url": "{{ . }}"{{ end }}{{ with $.Site.Params.author.avatar }}, - "avatar": "{{ . | absURL }}"{{ end }} - }, - {{ end -}} - "items" : [ - {{ range $index, $element := .Scratch.Get "mainSectionPages" -}} - { - "title" : {{ .Title | jsonify }}, - "date_published" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", - "date_modified" : "{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}", - "id" : "{{ .Permalink }}", - "url" : "{{ .Permalink }}", - {{ with .Summary -}} - "summary": {{ . | plainify | jsonify }}, - {{ end -}} - {{ with (.Param "author").name -}} - "author" : { - "name" : "{{ . }}" - }, - {{ end -}} - "content_html" : {{ .Content | jsonify }}, - "language": {{ .Language.Lang | default $.Lang | jsonify }} - }{{ if ne (add $index 1) $length }},{{ end }} - {{ end -}} - ] + "test": "TODO for section list" } diff --git a/layouts/taxonomy/list.feed.json b/layouts/taxonomy/list.feed.json new file mode 100644 index 00000000..d9431896 --- /dev/null +++ b/layouts/taxonomy/list.feed.json @@ -0,0 +1,3 @@ +{ + "test": "TODO for term list" +} From 4b8b6856495ec865c6fb24a2e61abc5e2fe37cfd Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 18:01:22 +0800 Subject: [PATCH 08/22] :construction: Feat: add JSON feed support for section and term list pages --- layouts/_default/home.feed.json | 4 +++- layouts/partials/feed/json-feed.html | 16 +++++----------- layouts/partials/init/index.html | 2 +- layouts/section/section.feed.json | 10 +++++++--- layouts/taxonomy/list.feed.json | 10 +++++++--- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/layouts/_default/home.feed.json b/layouts/_default/home.feed.json index 8e6d15b7..75582f57 100644 --- a/layouts/_default/home.feed.json +++ b/layouts/_default/home.feed.json @@ -1 +1,3 @@ -{{- partial "feed/json-feed.html" . -}} +{{- $options := dict "Page" . "Site" .Site "OutputFormats" .OutputFormats -}} +{{- $options = dict "Title" .Site.Title "Pages" (.Scratch.Get "mainSectionPages") | merge $options -}} +{{- partial "feed/json-feed.html" $options -}} diff --git a/layouts/partials/feed/json-feed.html b/layouts/partials/feed/json-feed.html index 09623e38..a4ae90fd 100644 --- a/layouts/partials/feed/json-feed.html +++ b/layouts/partials/feed/json-feed.html @@ -1,21 +1,14 @@ -{{- $pages := .Scratch.Get "mainSectionPages" -}} +{{- $pages := .Pages -}} {{- $limit := .Site.Params.feed.limit -}} {{- if ge $limit 1 -}} - {{- $pages = $pages | first $limit }} + {{- $pages = $pages | first $limit -}} {{- end -}} {{- $length := $pages.Len -}} -{{- $fullText := (.Param "feed").fullText -}} -{{- $title := title (.Params.Title | default ((T .Section) | default .Section | dict "Some" | T "allSome")) -}} -{{- if .Site.Params.withSiteTitle -}} - {{- $title = printf "%s %s %s" $title .Site.Params.titleDelimiter .Site.Title -}} -{{- end -}} -{{- if .IsHome -}} - {{- $title = .Site.Title -}} -{{- end -}} +{{- /* TODO 加密的不显示,加入 hiddenFromFeed */ -}} { "version": "https://jsonfeed.org/version/1.1", - "title": "{{- $title -}}", + "title": "{{- .Title -}}", "description": "{{- .Site.Params.description | default .Site.Title -}}", "home_page_url": "{{ .Site.BaseURL }}", {{ with .OutputFormats.Get "feed" -}} @@ -35,6 +28,7 @@ {{ end -}} "items": [ {{ range $index, $element := $pages -}} + {{- $fullText := (.Param "feed").fullText -}} { "title": {{ .Title | jsonify }}, "date_published": "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index a9af1b43..688b63f5 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-138c7ad1" -}} +{{- .Scratch.Set "version" "v0.3.10-874913ce" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/section/section.feed.json b/layouts/section/section.feed.json index ba23ee71..cd70d6c9 100644 --- a/layouts/section/section.feed.json +++ b/layouts/section/section.feed.json @@ -1,3 +1,7 @@ -{ - "test": "TODO for section list" -} +{{- $title := title (.Params.Title | default ((T .Section) | default .Section | dict "Some" | T "allSome")) -}} +{{- if .Site.Params.withSiteTitle -}} + {{- $title = printf "%s %s %s" $title .Site.Params.titleDelimiter .Site.Title -}} +{{- end -}} +{{- $options := dict "Page" . "Site" .Site "OutputFormats" .OutputFormats -}} +{{- $options = dict "Title" $title "Pages" .Pages | merge $options -}} +{{- partial "feed/json-feed.html" $options -}} diff --git a/layouts/taxonomy/list.feed.json b/layouts/taxonomy/list.feed.json index d9431896..c3f44242 100644 --- a/layouts/taxonomy/list.feed.json +++ b/layouts/taxonomy/list.feed.json @@ -1,3 +1,7 @@ -{ - "test": "TODO for term list" -} +{{- $title := printf "%s %s" .Title (T .Data.Singular | default .Data.Singular) -}} +{{- if .Site.Params.withSiteTitle -}} + {{- $title = printf "%s %s %s" $title .Site.Params.titleDelimiter .Site.Title -}} +{{- end -}} +{{- $options := dict "Page" . "Site" .Site "OutputFormats" .OutputFormats -}} +{{- $options = dict "Title" $title "Pages" .Pages | merge $options -}} +{{- partial "feed/json-feed.html" $options -}} From cd574fa2537f95b614ab0ffde0ba79dc79e53530 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 20:35:14 +0800 Subject: [PATCH 09/22] :rocket: Chore: fix git stage error in update-version script --- build/update-version.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/update-version.js b/build/update-version.js index b18a2114..378f3242 100644 --- a/build/update-version.js +++ b/build/update-version.js @@ -39,8 +39,8 @@ const latestVersion = stage === 'version' ? version : devVersion; const lastVersion = initHtml.match(/v\d+\.\d+\.\d+(-\w+)?/)[0]; const newInitHtml = initHtml.replace(/v\d+\.\d+\.\d+(-\w+)?/, `v${latestVersion}`); fs.writeFileSync(initHtmlPath, newInitHtml); -// Add the updated file to the git stage -execSync('git add .'); +// Add the updated files to the git stage +execSync('git add layouts/partials/init/index.html package.json package-lock.json'); console.log(`Update the FixIt version from ${lastVersion} to v${latestVersion}.`); export default latestVersion; From cbdfa1b08606b9d0ffd48f9e93b366afffaeb626 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 20:37:07 +0800 Subject: [PATCH 10/22] :zap: Perf: add front matter hiddenFromFeed for JSON feed (#475) --- hugo.toml | 2 +- layouts/partials/feed/json-feed.html | 5 ++++- layouts/partials/init/index.html | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hugo.toml b/hugo.toml index b63fc610..c8baf772 100644 --- a/hugo.toml +++ b/hugo.toml @@ -824,7 +824,7 @@ enableEmoji = true # FixIt 0.3.10 | NEW Feed config for RSS, Atom and JSON feed. [params.feed] # The number of posts to include in the feed. Default is -1, which means all posts. - limit = 10 + limit = -1 # whether to show the full text content in feed. fullText = false diff --git a/layouts/partials/feed/json-feed.html b/layouts/partials/feed/json-feed.html index a4ae90fd..d9745ef0 100644 --- a/layouts/partials/feed/json-feed.html +++ b/layouts/partials/feed/json-feed.html @@ -1,10 +1,13 @@ {{- $pages := .Pages -}} +{{- /* Front matter: password */ -}} +{{- $pages = where $pages "Params.password" "eq" nil -}} +{{- /* Front matter: hiddenFromFeed */ -}} +{{- $pages = where $pages "Params.hiddenFromFeed" "ne" true -}} {{- $limit := .Site.Params.feed.limit -}} {{- if ge $limit 1 -}} {{- $pages = $pages | first $limit -}} {{- end -}} {{- $length := $pages.Len -}} -{{- /* TODO 加密的不显示,加入 hiddenFromFeed */ -}} { "version": "https://jsonfeed.org/version/1.1", diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 688b63f5..bc4167cf 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-874913ce" -}} +{{- .Scratch.Set "version" "v0.3.10-cd574fa2" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} From eb8d0276a72aaec00ff11671d388c57b643d2cec Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 20:41:49 +0800 Subject: [PATCH 11/22] :mag: Feat: add tags attribute for JSON feed (#475) --- layouts/partials/feed/json-feed.html | 3 +++ layouts/partials/init/index.html | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/layouts/partials/feed/json-feed.html b/layouts/partials/feed/json-feed.html index d9745ef0..e1abf399 100644 --- a/layouts/partials/feed/json-feed.html +++ b/layouts/partials/feed/json-feed.html @@ -45,6 +45,9 @@ "avatar": "{{ . | absURL }}"{{ end }} }, {{ end -}} + {{ with .Params.tags -}} + "tags": {{ . | jsonify }}, + {{ end -}} {{ with .Summary -}} "summary": {{ . | plainify | jsonify }}, {{ if not $fullText -}} diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index bc4167cf..0b92e8be 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-cd574fa2" -}} +{{- .Scratch.Set "version" "v0.3.10-cbdfa1b0" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} From 2c123a3d602de9ed783c7c60f9f4964bd0b8c251 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 22:01:50 +0800 Subject: [PATCH 12/22] :recycle: Refactor: refactor RSS feed templates Close #488 --- layouts/_default/home.feed.json | 2 +- layouts/{_default => page}/single.md | 0 layouts/partials/feed/json-feed.html | 6 +-- layouts/partials/feed/rss.html | 51 ++++++++++++++++++++++ layouts/partials/init/index.html | 2 +- layouts/rss.xml | 50 ++-------------------- layouts/section/rss.xml | 64 ++++------------------------ layouts/section/section.feed.json | 2 +- layouts/taxonomy/list.feed.json | 2 +- layouts/taxonomy/rss.xml | 50 ++++------------------ 10 files changed, 78 insertions(+), 151 deletions(-) rename layouts/{_default => page}/single.md (100%) create mode 100644 layouts/partials/feed/rss.html diff --git a/layouts/_default/home.feed.json b/layouts/_default/home.feed.json index 75582f57..45fbb691 100644 --- a/layouts/_default/home.feed.json +++ b/layouts/_default/home.feed.json @@ -1,3 +1,3 @@ -{{- $options := dict "Page" . "Site" .Site "OutputFormats" .OutputFormats -}} +{{- $options := dict "Site" .Site "OutputFormats" .OutputFormats -}} {{- $options = dict "Title" .Site.Title "Pages" (.Scratch.Get "mainSectionPages") | merge $options -}} {{- partial "feed/json-feed.html" $options -}} diff --git a/layouts/_default/single.md b/layouts/page/single.md similarity index 100% rename from layouts/_default/single.md rename to layouts/page/single.md diff --git a/layouts/partials/feed/json-feed.html b/layouts/partials/feed/json-feed.html index e1abf399..5f125db1 100644 --- a/layouts/partials/feed/json-feed.html +++ b/layouts/partials/feed/json-feed.html @@ -11,13 +11,13 @@ { "version": "https://jsonfeed.org/version/1.1", - "title": "{{- .Title -}}", - "description": "{{- .Site.Params.description | default .Site.Title -}}", + "title": "{{ .Title }}", + "description": "{{ .Site.Params.description | default .Site.Title }}", "home_page_url": "{{ .Site.BaseURL }}", {{ with .OutputFormats.Get "feed" -}} "feed_url": "{{ .Permalink }}", {{ end -}} - {{ with .Site.LanguageCode -}} + {{ with .Site.Language.LanguageCode -}} "language": "{{ . }}", {{ end -}} "icon": "{{ `/apple-touch-icon.png` | absURL }}", diff --git a/layouts/partials/feed/rss.html b/layouts/partials/feed/rss.html new file mode 100644 index 00000000..e1d6c3bf --- /dev/null +++ b/layouts/partials/feed/rss.html @@ -0,0 +1,51 @@ +{{- $pages := .Pages -}} +{{- /* Front matter: password */ -}} +{{- $pages = where $pages "Params.password" "eq" nil -}} +{{- /* Front matter: hiddenFromFeed */ -}} +{{- $pages = where $pages "Params.hiddenFromFeed" "ne" true -}} +{{- $limit := .Site.Params.feed.limit -}} +{{- if ge $limit 1 -}} + {{- $pages = $pages | first $limit -}} +{{- end -}} +{{- $length := $pages.Len -}} +{{- /* TODO 封面图、文章内图片链接、分类、标签等处理 */ -}} + +{{- printf "" | safeHTML }} + + + {{ .Title }} + {{ .Permalink }} + {{ .Site.Params.description | default .Site.Title }} + Hugo {{ hugo.Version }} & FixIt {{ .Version }} + {{ .Site.Language.LanguageCode }}{{ with .Site.Params.author.email }} + {{.}}{{ with $.Site.Params.author.name }} ({{ . }}){{ end }}{{ end }}{{ with .Site.Params.author.email }} + {{ . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end }}{{ end }}{{ with .Site.Copyright }} + {{ . }}{{ end }}{{ if not .Date.IsZero }} + {{ (index $pages.ByLastmod.Reverse 0).Lastmod.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }} + {{- with .OutputFormats.Get "rss" }} + {{ printf "" .Permalink .MediaType | safeHTML }} + {{- end }} + {{- range $pages }} + {{- $params := .Params | merge .Site.Params.Page }} + {{- $fullText := (.Param "feed").fullText }} + + {{ .Title }} + {{ .Permalink }} + {{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} + {{- with .Params.author.email }}{{ . }}{{ with $.Params.author.name }} ({{ . }}){{ end }}{{ end }} + {{ .Permalink }} + {{- if $fullText }} + + {{- "]*>.*` "" | replaceRE `]*( /)?>` "" | safeHTML -}} */ -}} + {{- $content | transform.XMLEscape | safeHTML }} + {{- "]]>" | safeHTML -}} + + {{- else }} + {{ .Summary | transform.XMLEscape | safeHTML }} + {{- end }} + + {{- end }} + + diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 0b92e8be..4b61fbe1 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-cbdfa1b0" -}} +{{- .Scratch.Set "version" "v0.3.10-eb8d0276" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/rss.xml b/layouts/rss.xml index 463b27cb..81a2adab 100644 --- a/layouts/rss.xml +++ b/layouts/rss.xml @@ -1,46 +1,4 @@ - - - - {{- .Site.Title -}} - - - {{- .Permalink -}} - - - {{- .Site.Params.description | default .Site.Title -}} - - Hugo -- gohugo.io - {{- with .Site.LanguageCode -}} - - {{- . -}} - - {{- end -}} - {{- with .Site.Params.author.email -}} - - {{- . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end -}} - - - {{- . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end -}} - - {{- end -}} - {{- with .Site.Copyright -}} - - {{- . -}} - - {{- end -}} - {{- if not .Date.IsZero -}} - - {{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}} - - {{- end -}} - {{ with .OutputFormats.Get "rss" }} - {{ printf "" .Permalink .MediaType | safeHTML }} - {{ end }} - {{- range .Scratch.Get "mainSectionPages" | first (.Site.Params.home.rss | default 10) -}} - {{- /* TODO 0.4.0 待重构为去掉 `.page` 改用 hugo 推荐的 .Param 方法获取页面参数 */ -}} - {{- $params := .Params | merge site.Params.page -}} - {{- if $params.password | or $params.hiddenFromRss }}{{ continue }}{{ end -}} - {{- dict "Page" . "Site" .Site | partial "rss/item.html" -}} - {{- end -}} - - +{{- $options := dict "Site" .Site "OutputFormats" .OutputFormats -}} +{{- $options = dict "Permalink" .Permalink "Version" (.Scratch.Get "version") | merge $options -}} +{{- $options = dict "Title" .Site.Title "Pages" (.Scratch.Get "mainSectionPages") | merge $options -}} +{{- partial "feed/rss.html" $options -}} diff --git a/layouts/section/rss.xml b/layouts/section/rss.xml index 6cb9c129..726cd5a4 100644 --- a/layouts/section/rss.xml +++ b/layouts/section/rss.xml @@ -1,56 +1,8 @@ - - - - {{- title (.Params.Title | default ((T .Section) | default .Section | dict "Some" | T "allSome")) -}} - {{- if .Site.Params.withSiteTitle }} {{ .Site.Params.titleDelimiter }} {{ .Site.Title }}{{- end -}} - - - {{- .Permalink -}} - - - {{- title (.Params.Title | default ((T .Section) | default .Section | dict "Some" | T "allSome")) }} | {{ .Site.Title -}} - - Hugo -- gohugo.io - {{- with .Site.LanguageCode -}} - - {{- . -}} - - {{- end -}} - {{- with .Site.Params.author.email -}} - - {{- . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end -}} - - - {{- . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end -}} - - {{- end -}} - {{- with .Site.Copyright -}} - - {{- . -}} - - {{- end -}} - {{- if not .Date.IsZero -}} - - {{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}} - - {{- end -}} - - {{- if .Site.Params.section.recentlyUpdated.rss -}} - {{- $postCount := 0 -}} - {{- $maxPostCount := .Site.Params.section.recentlyUpdated.maxCount | default 10 -}} - {{- $days := .Site.Params.section.recentlyUpdated.days | default 30 -}} - {{- range (where .Data.Pages.ByLastmod.Reverse "Section" "!=" "") -}} - {{- if gt (add .Lastmod.Unix (mul 86900 $days)) now.Unix -}} - {{- if lt $postCount $maxPostCount -}} - {{- if ne .Lastmod.Unix .Date.Unix }} - {{- dict "Page" . "Site" .Site | partial "rss/item.html" -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- range .Pages | first (.Site.Params.section.rss | default 10) -}} - {{- dict "Page" . "Site" .Site | partial "rss/item.html" -}} - {{- end -}} - - +{{- $title := title (.Params.Title | default ((T .Section) | default .Section | dict "Some" | T "allSome")) -}} +{{- if .Site.Params.withSiteTitle -}} + {{- $title = printf "%s %s %s" $title .Site.Params.titleDelimiter .Site.Title -}} +{{- end -}} +{{- $options := dict "Site" .Site "OutputFormats" .OutputFormats -}} +{{- $options = dict "Permalink" .Permalink "Version" (.Scratch.Get "version") | merge $options -}} +{{- $options = dict "Title" $title "Pages" .Pages | merge $options -}} +{{- partial "feed/rss.html" $options -}} diff --git a/layouts/section/section.feed.json b/layouts/section/section.feed.json index cd70d6c9..38be0179 100644 --- a/layouts/section/section.feed.json +++ b/layouts/section/section.feed.json @@ -2,6 +2,6 @@ {{- if .Site.Params.withSiteTitle -}} {{- $title = printf "%s %s %s" $title .Site.Params.titleDelimiter .Site.Title -}} {{- end -}} -{{- $options := dict "Page" . "Site" .Site "OutputFormats" .OutputFormats -}} +{{- $options := dict "Site" .Site "OutputFormats" .OutputFormats -}} {{- $options = dict "Title" $title "Pages" .Pages | merge $options -}} {{- partial "feed/json-feed.html" $options -}} diff --git a/layouts/taxonomy/list.feed.json b/layouts/taxonomy/list.feed.json index c3f44242..b31f7d16 100644 --- a/layouts/taxonomy/list.feed.json +++ b/layouts/taxonomy/list.feed.json @@ -2,6 +2,6 @@ {{- if .Site.Params.withSiteTitle -}} {{- $title = printf "%s %s %s" $title .Site.Params.titleDelimiter .Site.Title -}} {{- end -}} -{{- $options := dict "Page" . "Site" .Site "OutputFormats" .OutputFormats -}} +{{- $options := dict "Site" .Site "OutputFormats" .OutputFormats -}} {{- $options = dict "Title" $title "Pages" .Pages | merge $options -}} {{- partial "feed/json-feed.html" $options -}} diff --git a/layouts/taxonomy/rss.xml b/layouts/taxonomy/rss.xml index d3aab8e8..8a2d734c 100644 --- a/layouts/taxonomy/rss.xml +++ b/layouts/taxonomy/rss.xml @@ -1,42 +1,8 @@ - - - - {{- .Title }} - {{ T .Data.Singular | default .Data.Singular -}} - {{- if .Site.Params.withSiteTitle }} {{ .Site.Params.titleDelimiter }} {{ .Site.Title }}{{- end -}} - - - {{- .Permalink -}} - - - {{- .Title }} - {{ T .Data.Singular | default .Data.Singular }} | {{ .Site.Title -}} - - Hugo -- gohugo.io - {{- with .Site.LanguageCode -}} - - {{- . -}} - - {{- end -}} - {{- with .Site.Params.author.email -}} - - {{- . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end -}} - - - {{- . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end -}} - - {{- end -}} - {{- with .Site.Copyright -}} - - {{- . -}} - - {{- end -}} - {{- if not .Date.IsZero -}} - - {{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}} - - {{- end -}} - - {{- range .Pages | first (.Site.Params.list.rss | default 10) -}} - {{- dict "Page" . "Site" .Site | partial "rss/item.html" -}} - {{- end -}} - - +{{- $title := printf "%s %s" .Title (T .Data.Singular | default .Data.Singular) -}} +{{- if .Site.Params.withSiteTitle -}} + {{- $title = printf "%s %s %s" $title .Site.Params.titleDelimiter .Site.Title -}} +{{- end -}} +{{- $options := dict "Site" .Site "OutputFormats" .OutputFormats -}} +{{- $options = dict "Permalink" .Permalink "Version" (.Scratch.Get "version") | merge $options -}} +{{- $options = dict "Title" $title "Pages" .Pages | merge $options -}} +{{- partial "feed/rss.html" $options -}} From 1d651b5a4b82ff4f432e250e12a026eacc3ccb80 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 22:07:27 +0800 Subject: [PATCH 13/22] :construction: WIP: rename json-feed.html to json.html --- layouts/_default/home.feed.json | 2 +- layouts/partials/feed/{json-feed.html => json.html} | 0 layouts/partials/init/index.html | 2 +- layouts/partials/rss/item.html | 1 + layouts/section/section.feed.json | 2 +- layouts/taxonomy/list.feed.json | 2 +- 6 files changed, 5 insertions(+), 4 deletions(-) rename layouts/partials/feed/{json-feed.html => json.html} (100%) diff --git a/layouts/_default/home.feed.json b/layouts/_default/home.feed.json index 45fbb691..62e8d5f7 100644 --- a/layouts/_default/home.feed.json +++ b/layouts/_default/home.feed.json @@ -1,3 +1,3 @@ {{- $options := dict "Site" .Site "OutputFormats" .OutputFormats -}} {{- $options = dict "Title" .Site.Title "Pages" (.Scratch.Get "mainSectionPages") | merge $options -}} -{{- partial "feed/json-feed.html" $options -}} +{{- partial "feed/json.html" $options -}} diff --git a/layouts/partials/feed/json-feed.html b/layouts/partials/feed/json.html similarity index 100% rename from layouts/partials/feed/json-feed.html rename to layouts/partials/feed/json.html diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 4b61fbe1..4584b907 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-eb8d0276" -}} +{{- .Scratch.Set "version" "v0.3.10-2c123a3d" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/partials/rss/item.html b/layouts/partials/rss/item.html index bc86c4ab..90946f47 100644 --- a/layouts/partials/rss/item.html +++ b/layouts/partials/rss/item.html @@ -1,3 +1,4 @@ +{{/* TODO delate and delete rss config */}} {{- $params := .Page.Params | merge .Site.Params.Page -}} {{- $authorName := .Site.Params.author.name | default (T "single.author") -}} {{- with .Params.author -}} diff --git a/layouts/section/section.feed.json b/layouts/section/section.feed.json index 38be0179..a6951eac 100644 --- a/layouts/section/section.feed.json +++ b/layouts/section/section.feed.json @@ -4,4 +4,4 @@ {{- end -}} {{- $options := dict "Site" .Site "OutputFormats" .OutputFormats -}} {{- $options = dict "Title" $title "Pages" .Pages | merge $options -}} -{{- partial "feed/json-feed.html" $options -}} +{{- partial "feed/json.html" $options -}} diff --git a/layouts/taxonomy/list.feed.json b/layouts/taxonomy/list.feed.json index b31f7d16..a43a75a5 100644 --- a/layouts/taxonomy/list.feed.json +++ b/layouts/taxonomy/list.feed.json @@ -4,4 +4,4 @@ {{- end -}} {{- $options := dict "Site" .Site "OutputFormats" .OutputFormats -}} {{- $options = dict "Title" $title "Pages" .Pages | merge $options -}} -{{- partial "feed/json-feed.html" $options -}} +{{- partial "feed/json.html" $options -}} From 9cb752351bafb64ebd16eb7e5984e383e1ced5b1 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 13 Aug 2024 22:58:19 +0800 Subject: [PATCH 14/22] :construction: Feat: revert single.md --- layouts/{page => _default}/single.md | 0 layouts/partials/init/index.html | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename layouts/{page => _default}/single.md (100%) diff --git a/layouts/page/single.md b/layouts/_default/single.md similarity index 100% rename from layouts/page/single.md rename to layouts/_default/single.md diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 4584b907..fd329307 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-2c123a3d" -}} +{{- .Scratch.Set "version" "v0.3.10-1d651b5a" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} From 3581ee1c9b33c237b8188ab5c1713e9242913270 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 14 Aug 2024 14:53:00 +0800 Subject: [PATCH 15/22] :zap: Perf: enhance JSON feed 1.1 compatibility --- hugo.toml | 23 +++++++++++------------ layouts/partials/feed/json.html | 24 ++++++++++++++---------- layouts/partials/head/link.html | 3 +++ layouts/partials/init/index.html | 2 +- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/hugo.toml b/hugo.toml index c8baf772..c5b909c8 100644 --- a/hugo.toml +++ b/hugo.toml @@ -231,12 +231,10 @@ enableEmoji = true # ------------------------------------------------------------------------------------- [mediaTypes] - # Options to make output .txt files - [mediaTypes."text/plain"] - suffixes = ["txt"] - # Options to make output feed.json files - [mediaTypes."application/feed+json"] - suffixes = ["json"] + # FixIt 0.3.10 | NEW Options to make output feed.json files + # Warning: The application/feed+json media type will cause an unknown error in resources.GetRemote! + # [mediaTypes."application/feed+json"] + # suffixes = ["json"] # ------------------------------------------------------------------------------------- # Output Format Definitions @@ -279,7 +277,8 @@ enableEmoji = true # FixIt 0.3.10 | NEW Options to make output feed.json file [outputFormats.feed] baseName = "feed" - mediaType = "application/feed+json" + # Warning: The application/feed+json media type will cause an unknown error in resources.GetRemote! + mediaType = "application/json" isPlainText = true isHTML = false # FixIt 0.3.10 | NEW Options to make output search.json file @@ -297,11 +296,11 @@ enableEmoji = true # ------------------------------------------------------------------------------------- # Options to make hugo output files, the optional values are below: -# home: html, rss, feed, archives, offline, readme, baidu_urls, search etc. -# page: html, markdown -# section: html, rss, feed -# taxonomy: html -# term: html, rss, feed +# home = ["html", "rss", "feed", "archives", "offline", "readme", "baidu_urls", "search"] +# page = ["html", "markdown"] +# section = ["html", "rss", "feed"] +# taxonomy = ["html"] +# term = ["html", "rss", "feed"] [outputs] home = ["html", "rss", "feed", "archives", "offline", "readme", "baidu_urls", "search"] page = ["html", "markdown"] diff --git a/layouts/partials/feed/json.html b/layouts/partials/feed/json.html index 5f125db1..375d8f02 100644 --- a/layouts/partials/feed/json.html +++ b/layouts/partials/feed/json.html @@ -23,11 +23,13 @@ "icon": "{{ `/apple-touch-icon.png` | absURL }}", "favicon": "{{ `/favicon.ico` | absURL }}", {{ with .Site.Params.author.name -}} - "author": { - "name": "{{ . }}"{{ with $.Site.Params.author.link }}, - "url": "{{ . }}"{{ end }}{{ with $.Site.Params.author.avatar }}, - "avatar": "{{ . | absURL }}"{{ end }} - }, + "authors": [ + { + "name": "{{ . }}"{{ with $.Site.Params.author.link }}, + "url": "{{ . }}"{{ end }}{{ with $.Site.Params.author.avatar }}, + "avatar": "{{ . | absURL }}"{{ end }} + } + ], {{ end -}} "items": [ {{ range $index, $element := $pages -}} @@ -39,11 +41,13 @@ "id": "{{ .Permalink }}", "url": "{{ .Permalink }}", {{ with .Params.author.name -}} - "author": { - "name": "{{ . }}"{{ with $.Params.author.link }}, - "url": "{{ . }}"{{ end }}{{ with $.Params.author.avatar }}, - "avatar": "{{ . | absURL }}"{{ end }} - }, + "authors": [ + { + "name": "{{ . }}"{{ with $.Params.author.link }}, + "url": "{{ . }}"{{ end }}{{ with $.Params.author.avatar }}, + "avatar": "{{ . | absURL }}"{{ end }} + } + ], {{ end -}} {{ with .Params.tags -}} "tags": {{ . | jsonify }}, diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html index 9f9677b1..45eb2a9b 100644 --- a/layouts/partials/head/link.html +++ b/layouts/partials/head/link.html @@ -32,6 +32,9 @@ {{- range .AlternativeOutputFormats -}} {{- printf `` .Rel .MediaType.Type .Permalink $title | safeHTML -}} {{- end -}} +{{- with .OutputFormats.Get "feed" -}} + +{{- end -}} {{- /* style.min.css */ -}} {{- $options := dict "Source" "css/style.scss" "Fingerprint" $fingerprint -}} diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index fd329307..71846768 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-1d651b5a" -}} +{{- .Scratch.Set "version" "v0.3.10-cf42e4ea" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} From 4017cc9ffb8833bbf4f4128a867def97a090b7ba Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 15 Aug 2024 14:50:36 +0800 Subject: [PATCH 16/22] :recycle: Refactor: refactor post author map getting --- demo/hugo.toml | 3 +- layouts/partials/feed/json.html | 8 ++-- layouts/partials/feed/rss.html | 3 +- layouts/partials/function/get-author-map.html | 46 +++++++++++++++++++ layouts/partials/head/meta.html | 11 +++-- layouts/partials/init/index.html | 2 +- layouts/partials/single/post-author.html | 32 +------------ 7 files changed, 63 insertions(+), 42 deletions(-) create mode 100644 layouts/partials/function/get-author-map.html diff --git a/demo/hugo.toml b/demo/hugo.toml index a38746df..001730db 100644 --- a/demo/hugo.toml +++ b/demo/hugo.toml @@ -35,5 +35,4 @@ baseURL = "http://example.org/" # FixIt theme version version = "0.3.X" # e.g. "0.2.X", "0.2.15", "v0.2.15" etc. # ... - [params.search] - enable = true + diff --git a/layouts/partials/feed/json.html b/layouts/partials/feed/json.html index 375d8f02..eb4c875e 100644 --- a/layouts/partials/feed/json.html +++ b/layouts/partials/feed/json.html @@ -8,6 +8,7 @@ {{- $pages = $pages | first $limit -}} {{- end -}} {{- $length := $pages.Len -}} +{{- /* 支持 image 属性 */ -}} { "version": "https://jsonfeed.org/version/1.1", @@ -34,17 +35,18 @@ "items": [ {{ range $index, $element := $pages -}} {{- $fullText := (.Param "feed").fullText -}} + {{- $author := partial "function/get-author-map.html" .Params.author -}} { "title": {{ .Title | jsonify }}, "date_published": "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}", "date_modified": "{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}", "id": "{{ .Permalink }}", "url": "{{ .Permalink }}", - {{ with .Params.author.name -}} + {{ with $author.name -}} "authors": [ { - "name": "{{ . }}"{{ with $.Params.author.link }}, - "url": "{{ . }}"{{ end }}{{ with $.Params.author.avatar }}, + "name": "{{ . }}"{{ with $author.link }}, + "url": "{{ . }}"{{ end }}{{ with $author.avatar }}, "avatar": "{{ . | absURL }}"{{ end }} } ], diff --git a/layouts/partials/feed/rss.html b/layouts/partials/feed/rss.html index e1d6c3bf..c04ce310 100644 --- a/layouts/partials/feed/rss.html +++ b/layouts/partials/feed/rss.html @@ -28,11 +28,12 @@ {{- range $pages }} {{- $params := .Params | merge .Site.Params.Page }} {{- $fullText := (.Param "feed").fullText }} + {{- $author := partial "function/get-author-map.html" .Params.author -}} {{ .Title }} {{ .Permalink }} {{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} - {{- with .Params.author.email }}{{ . }}{{ with $.Params.author.name }} ({{ . }}){{ end }}{{ end }} + {{- with $author.email }}{{ . }}{{ with $author.name }} ({{ . }}){{ end }}{{ end }} {{ .Permalink }} {{- if $fullText }} diff --git a/layouts/partials/function/get-author-map.html b/layouts/partials/function/get-author-map.html new file mode 100644 index 00000000..a4433692 --- /dev/null +++ b/layouts/partials/function/get-author-map.html @@ -0,0 +1,46 @@ +{{- /* +Get author in map format. + +@param {String|Map} . the author name or map +@returns {Map} + +@example {{- $author := partial "function/get-author-map.html" .Params.author -}} +*/ -}} + +{{- if not (reflect.IsMap site.Params.author) -}} + {{- errorf "FixIt params error: site.Params.author must be a map, got %T." site.Params.author -}} +{{- end -}} + +{{- $default := dict "name" "" "link" "" "email" "" "avatar" "" -}} +{{- $author := site.Params.author | merge $default -}} +{{- $authorParam := dict -}} +{{- if reflect.IsMap . -}} + {{- $authorParam = . -}} +{{- else -}} + {{- with . -}} + {{- $authorParam = dict "name" . -}} + {{- end -}} +{{- end -}} + +{{- if isset $authorParam "name" | and (ne $authorParam.name site.Params.author.name) -}} + {{- $author = $authorParam | merge $default | merge $author -}} +{{- else -}} + {{- with $authorParam.link -}}{{ $author = dict "link" . | merge $author }}{{- end -}} + {{- with $authorParam.email -}}{{ $author = dict "email" . | merge $author }}{{- end -}} + {{- with $authorParam.avatar -}}{{ $author = dict "avatar" . | merge $author }}{{- end -}} +{{- end -}} + +{{- $gravatar := site.Params.gravatar -}} +{{- if $gravatar.enable | and $author.email -}} + {{- with $gravatar -}} + {{- /* TODO migrate to gravatar */ -}} + {{- $author = dict "avatar" (printf "https://%v/avatar/%v?s=32&d=%v" + (path.Clean .Host | default "www.gravatar.com") + (md5 $author.email) + (.Style | default "")) + | merge $author + -}} + {{- end -}} +{{- end -}} + +{{- return $author -}} diff --git a/layouts/partials/head/meta.html b/layouts/partials/head/meta.html index fda0a5e2..03c361e2 100644 --- a/layouts/partials/head/meta.html +++ b/layouts/partials/head/meta.html @@ -1,9 +1,7 @@ -{{- $params := partial "function/params.html" -}} -{{- $author := .Param "author" -}} +{{- $author := partial "function/get-author-map.html" .Params.author -}} - - + {{- $keywords := .Keywords -}} {{- if not $keywords -}} @@ -14,12 +12,15 @@ {{- end -}} {{- end -}} {{- with $keywords -}} - + {{- end -}} {{- template "_internal/schema.html" . -}} {{- template "_internal/opengraph.html" . -}} {{- template "_internal/twitter_cards.html" . -}} +{{- with .Site.Params.social.Twitter -}} + +{{- end -}} diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 71846768..c1249d6f 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.10-cf42e4ea" -}} +{{- .Scratch.Set "version" "v0.3.10-3581ee1c" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/partials/single/post-author.html b/layouts/partials/single/post-author.html index 61d0d246..d81308c7 100644 --- a/layouts/partials/single/post-author.html +++ b/layouts/partials/single/post-author.html @@ -1,39 +1,11 @@ {{- $params := .Params | merge .Site.Params.page -}} - -{{- /* Author data patch */ -}} -{{- $authorDefault := dict "name" "" "link" "" "email" "" "avatar" "" -}} -{{- $author := .Site.Params.author | merge $authorDefault -}} -{{- $authorPost := dict -}} -{{- if reflect.IsMap $params.author -}} - {{- $authorPost = $params.author -}} -{{- else if isset $params "author" -}} - {{- warnf "检测到你的 author 参数格式错误,请参考主题文档设置为正常的格式。" -}} - {{- $authorPost = dict "name" $params.author -}} -{{- end -}} -{{- if isset $authorPost "name" | and (ne $authorPost.name .Site.Params.author.name) -}} - {{- $author = $authorPost | merge $authorDefault | merge $author -}} -{{- else -}} - {{- with $authorPost.link -}}{{ $author = dict "link" . | merge $author }}{{- end -}} - {{- with $authorPost.email -}}{{ $author = dict "email" . | merge $author }}{{- end -}} - {{- with $authorPost.avatar -}}{{ $author = dict "avatar" . | merge $author }}{{- end -}} -{{- end -}} - -{{- $gravatar := .Site.Params.gravatar -}} -{{- if $gravatar.enable | and $author.email -}} - {{- with $gravatar -}} - {{- $author = dict "avatar" (printf "https://%v/avatar/%v?s=32&d=%v" - (path.Clean .Host | default "www.gravatar.com") - (md5 $author.email) - (.Style | default "")) - | merge $author - -}} - {{- end -}} -{{- end -}} +{{- $author := partial "function/get-author-map.html" .Params.author -}} {{- .Store.Set "author" $author -}}