From 2cc276e5f524f9300f99b5ddd6ada5b0c367a1b4 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 20 Dec 2023 10:48:22 +0800 Subject: [PATCH] :tada: Feat: add related content support --- README.md | 2 +- README.zh-cn.md | 2 +- hugo.toml | 49 ++++++++++++++++++++++++++-- i18n/de.toml | 1 + i18n/en.toml | 1 + i18n/es.toml | 1 + i18n/fr.toml | 1 + i18n/it.toml | 1 + i18n/pl.toml | 1 + i18n/pt-BR.toml | 1 + i18n/ro.toml | 1 + i18n/ru.toml | 1 + i18n/sr.toml | 1 + i18n/vi.toml | 1 + i18n/zh-CN.toml | 1 + i18n/zh-TW.toml | 1 + layouts/partials/single/related.html | 27 +++++++++++++++ layouts/posts/single.html | 3 ++ theme.toml | 2 +- 19 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 layouts/partials/single/related.html diff --git a/README.md b/README.md index e1d703e2..1e957bff 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # FixIt Theme | Hugo [![GitHub release (latest by date)](https://img.shields.io/github/v/release/hugo-fixit/FixIt?style=flat)](https://github.com/hugo-fixit/FixIt/releases) -[![Hugo](https://img.shields.io/badge/Hugo-%5E0.110.0-ff4088?style=flat&logo=hugo)](https://gohugo.io/) +[![Hugo](https://img.shields.io/badge/Hugo-%5E0.111.0-ff4088?style=flat&logo=hugo)](https://gohugo.io/) [![License](https://img.shields.io/github/license/hugo-fixit/FixIt?style=flat)](/LICENSE) 👉 English README | [简体中文说明](README.zh-cn.md) diff --git a/README.zh-cn.md b/README.zh-cn.md index 8d33a911..3fe37062 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -1,7 +1,7 @@ # FixIt 主题 | Hugo [![GitHub release (latest by date)](https://img.shields.io/github/v/release/hugo-fixit/FixIt?style=flat)](https://github.com/hugo-fixit/FixIt/releases) -[![Hugo](https://img.shields.io/badge/Hugo-%5E0.110.0-ff4088?style=flat&logo=hugo)](https://gohugo.io/) +[![Hugo](https://img.shields.io/badge/Hugo-%5E0.111.0-ff4088?style=flat&logo=hugo)](https://gohugo.io/) [![License](https://img.shields.io/github/license/hugo-fixit/FixIt?style=flat)](/LICENSE) 👉 [English README](README.md) | 简体中文说明 diff --git a/hugo.toml b/hugo.toml index 22ed03b5..443fd019 100644 --- a/hugo.toml +++ b/hugo.toml @@ -699,6 +699,11 @@ enableEmoji = true name = "" logoUrl = "" + # FixIt 0.3.0 | NEW Related content config + [params.page.related] + enable = false + count = 5 + # FixIt 0.2.5 | NEW TypeIt config [params.typeit] # typing speed between each step (measured in milliseconds) @@ -877,6 +882,45 @@ enableEmoji = true # "vConsole", "eruda" supported type = "vConsole" +# ------------------------------------------------------------------------------------- +# Related content Configuration +# See: https://gohugo.io/content-management/related/ +# ------------------------------------------------------------------------------------- + +[related] + includeNewer = false + threshold = 80 + toLower = false +[[related.indices]] + applyFilter = false + cardinalityThreshold = 0 + name = 'keywords' + pattern = '' + toLower = false + type = 'basic' + weight = 100 +[[related.indices]] + applyFilter = false + cardinalityThreshold = 0 + name = 'date' + pattern = '' + toLower = false + type = 'basic' + weight = 10 +[[related.indices]] + applyFilter = false + cardinalityThreshold = 0 + name = 'tags' + pattern = '' + toLower = false + type = 'basic' + weight = 80 +[[related.indices]] + applyFilter = false + name = 'fragmentrefs' + type = 'fragments' + weight = 80 + # ------------------------------------------------------------------------------------- # Modules Configuration # See: https://gohugo.io/hugo-modules/configuration/#module-config-imports @@ -885,7 +929,7 @@ enableEmoji = true [module] [module.hugoVersion] extended = true - min = "0.110.0" + min = "0.111.0" # ------------------------------------------------------------------------------------- # Markup related configuration in Hugo @@ -1000,7 +1044,6 @@ enableEmoji = true # ------------------------------------------------------------------------------------- [taxonomies] - # series = "series" category = "categories" tag = "tags" - collections = "collections" + collection = "collections" diff --git a/i18n/de.toml b/i18n/de.toml index 1a5e683c..2fdab24f 100644 --- a/i18n/de.toml +++ b/i18n/de.toml @@ -120,6 +120,7 @@ encryptedAbstract = "" encryptedMessage = "" password = "Passwort" encryptyAgain = "" +relatedContent = "Ähnliche Inhalte" [single.includedIn] categories = "enthalten in {{ .Categories }}" diff --git a/i18n/en.toml b/i18n/en.toml index 46eab613..4bb8441e 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -119,6 +119,7 @@ encryptedAbstract = "This article has been encrypted, so its raw content is invi encryptedMessage = "Please enter the password" password = "Password" encryptyAgain = "Encrypt again" +relatedContent = "Related Content" [single.includedIn] categories = "included in {{ .Categories }}" diff --git a/i18n/es.toml b/i18n/es.toml index ebcce785..547a2642 100644 --- a/i18n/es.toml +++ b/i18n/es.toml @@ -120,6 +120,7 @@ encryptedAbstract = "" encryptedMessage = "" password = "Contraseña" encryptyAgain = "" +relatedContent = "Contenido relacionado" [single.includedIn] categories = "incluido en {{ .Categories }}" diff --git a/i18n/fr.toml b/i18n/fr.toml index 65aac9a6..cea2477e 100644 --- a/i18n/fr.toml +++ b/i18n/fr.toml @@ -119,6 +119,7 @@ encryptedAbstract = "Cet article a été chiffré, son contenu n'est donc pas li encryptedMessage = "Entrer le mot de passe" password = "Mot de passe" encryptyAgain = "Chiffrer à nouveau" +relatedContent = "Contenu lié" [single.includedIn] categories = "inclus dans {{ .Categories }}" diff --git a/i18n/it.toml b/i18n/it.toml index ece275ef..8b426881 100644 --- a/i18n/it.toml +++ b/i18n/it.toml @@ -120,6 +120,7 @@ encryptedAbstract = "" encryptedMessage = "" password = "Password" encryptyAgain = "" +relatedContent = "Contenuti correlati" [single.includedIn] categories = "incluso in {{ .Categories }}" diff --git a/i18n/pl.toml b/i18n/pl.toml index 35541a73..cf96afea 100644 --- a/i18n/pl.toml +++ b/i18n/pl.toml @@ -120,6 +120,7 @@ encryptedAbstract = "" encryptedMessage = "" password = "Hasło" encryptyAgain = "" +relatedContent = "Powiązane treści" [single.includedIn] categories = "zawarty w {{ .Categories }}" diff --git a/i18n/pt-BR.toml b/i18n/pt-BR.toml index c2f84b0c..dc169664 100644 --- a/i18n/pt-BR.toml +++ b/i18n/pt-BR.toml @@ -120,6 +120,7 @@ encryptedAbstract = "" encryptedMessage = "" password = "Contrasinha" encryptyAgain = "" +relatedContent = "Conteúdo relacionado" [single.includedIn] categories = "incluido em {{ .Categories }}" diff --git a/i18n/ro.toml b/i18n/ro.toml index 7afc903d..130c4387 100644 --- a/i18n/ro.toml +++ b/i18n/ro.toml @@ -120,6 +120,7 @@ encryptedAbstract = "" encryptedMessage = "" password = "Parolă" encryptyAgain = "" +relatedContent = "Conținut înrudit" [single.includedIn] categories = "inclus în {{ .Categories }}" diff --git a/i18n/ru.toml b/i18n/ru.toml index a8d164b2..8624cfa1 100644 --- a/i18n/ru.toml +++ b/i18n/ru.toml @@ -120,6 +120,7 @@ encryptedAbstract = "" encryptedMessage = "" password = "арготизм" encryptyAgain = "" +relatedContent = "Связанный контент" [single.includedIn] categories = "включен в {{ .Categories }}" diff --git a/i18n/sr.toml b/i18n/sr.toml index f97b8c7e..8c1ceca7 100644 --- a/i18n/sr.toml +++ b/i18n/sr.toml @@ -120,6 +120,7 @@ encryptedAbstract = "" encryptedMessage = "" password = "Паролица" encryptyAgain = "" +relatedContent = "Повезани садржај" [single.includedIn] categories = "укључено {{ .Categories }}" diff --git a/i18n/vi.toml b/i18n/vi.toml index ae04e26b..669855a9 100644 --- a/i18n/vi.toml +++ b/i18n/vi.toml @@ -119,6 +119,7 @@ encryptedAbstract = "" encryptedMessage = "" password = "Mật khẩu" encryptyAgain = "" +relatedContent = "Nội dung liên quan" [single.includedIn] categories = "trong {{ .Categories }}" diff --git a/i18n/zh-CN.toml b/i18n/zh-CN.toml index 271b0871..e3427e81 100644 --- a/i18n/zh-CN.toml +++ b/i18n/zh-CN.toml @@ -118,6 +118,7 @@ encryptedAbstract = "本文已加密,因此其原始内容不可见!" encryptedMessage = "请输入密码" password = "密码" encryptyAgain = "重新加密" +relatedContent = "相关内容" [single.includedIn] categories = "收录于 {{ .Categories }}" diff --git a/i18n/zh-TW.toml b/i18n/zh-TW.toml index 92685876..501c36f9 100644 --- a/i18n/zh-TW.toml +++ b/i18n/zh-TW.toml @@ -118,6 +118,7 @@ encryptedAbstract = "本文已加密,囙此其原始內容不可見!" encryptedMessage = "請輸入密碼" password = "密碼" encryptyAgain = "重新加密" +relatedContent = "相關內容" [single.includedIn] categories = "收錄於 {{ .Categories }}" diff --git a/layouts/partials/single/related.html b/layouts/partials/single/related.html new file mode 100644 index 00000000..68731706 --- /dev/null +++ b/layouts/partials/single/related.html @@ -0,0 +1,27 @@ +{{- /* Related Content */ -}} +{{- /* https://gohugo.io/content-management/related/ */ -}} +{{- $params := .Scratch.Get "params" -}} + +{{- if $params.related.enable -}} + {{- $related := .Site.RegularPages.Related . | first ($params.related.count | default 5) -}} + {{- with $related -}} +

{{ T "single.relatedContent" }}

+ + {{- end -}} +{{- end -}} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 30ab6c60..dbe0856b 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -179,6 +179,9 @@ {{- end -}} + {{- /* Related Content */ -}} + {{- partial "single/related.html" . -}} + {{- /* Reward before Footer */ -}} {{- $reward := .Scratch.Get "reward" -}} {{- if eq $reward.position "before" -}} diff --git a/theme.toml b/theme.toml index b875f341..1fc80d1c 100644 --- a/theme.toml +++ b/theme.toml @@ -7,7 +7,7 @@ licenselink = "https://github.com/hugo-fixit/FixIt/blob/master/LICENSE" description = "A Clean, Elegant but Advanced Hugo Theme for Hugo." homepage = "https://github.com/hugo-fixit/FixIt" demosite = "https://fixit.lruihao.cn" -min_version = "0.110.0" +min_version = "0.111.0" tags = [ "blog",