From ed07b2f47478446b9d9474db44761c253b9b62dc Mon Sep 17 00:00:00 2001 From: Razon Yang Date: Sat, 2 Dec 2023 13:53:10 +0800 Subject: [PATCH] fix: bring the post.excerpt parameter back (#1009) --- exampleSite/config/_default/params.toml | 2 +- .../content/docs/configuration/site-params/index.md | 2 +- .../docs/configuration/site-params/index.zh-hans.md | 2 +- .../docs/configuration/site-params/index.zh-hant.md | 2 +- exampleSite/content/docs/content/index.md | 2 +- exampleSite/content/docs/content/index.zh-hans.md | 2 +- exampleSite/content/docs/content/index.zh-hant.md | 2 +- layouts/partials/post/excerpt.html | 7 ++++++- 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 47c816af..27d64241 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -91,7 +91,7 @@ viewer = true # Image Viewer lineNos = false # true/false represents that show/hide the line numbers by default. [post] -# excerpt = "description" +# excerpt = "" # uncomment to use summaries as excerpts. # excerptMaxLength = 120 # copyright = false # Whether to display copyright section on each post. # plainifyExcerpt = false # Format excerpt in HTML if false. diff --git a/exampleSite/content/docs/configuration/site-params/index.md b/exampleSite/content/docs/configuration/site-params/index.md index a47b2df3..d3b4ccf0 100644 --- a/exampleSite/content/docs/configuration/site-params/index.md +++ b/exampleSite/content/docs/configuration/site-params/index.md @@ -122,7 +122,7 @@ The site parameters are located in `config/_default/params.toml` by default. | `codeBlock.lineNos` | Boolean | `true` | `true`/`false` represents that show/hide the line numbers by default. | **Post** | `post` | Object | - | -| ~~`post.excerpt`~~ | String | `Description` | Deleted since `v1.2.1`, the description will be used as the excerpt if not empty. +| `post.excerpt` | String | `Description` | The description will be used as the excerpt if not empty, to use summaries as excerpt, you'll need to set it as _empty string_ explicitly. | `post.excerptMaxLength` | Integer | `320` | | `post.copyright` | Boolean | `true` | Whether to display copyright section on each post. | `post.plainifyExcerpt` | Boolean | `true` | Format excerpt in HTML if `false`. diff --git a/exampleSite/content/docs/configuration/site-params/index.zh-hans.md b/exampleSite/content/docs/configuration/site-params/index.zh-hans.md index fdceaf58..340d20d1 100644 --- a/exampleSite/content/docs/configuration/site-params/index.zh-hans.md +++ b/exampleSite/content/docs/configuration/site-params/index.zh-hans.md @@ -125,7 +125,7 @@ authors = ["RazonYang"] | `codeBlock.lineNos` | Boolean | `true` | `true`/`false` 表示默认情况下显示/隐藏行号。 | **Post** | `post` | Object | - | -| ~~`post.excerpt`~~ | String | `Description` | 自 `v1.2.1` 删除,若 Description 不为空则作为摘要。 +| `post.excerpt` | String | `Description` | 若 Description 不为空则作为摘要,若需要使用 Summaries 作为摘要,你需要显式地将其设为**空字符串**。 | `post.excerptMaxLength` | Integer | `320` | | `post.copyright` | Boolean | `true` | 是否在每个帖子上显示版权部分 | `post.plainifyExcerpt` | Boolean | `true` | `false` 则格式化摘要为 HTML。 diff --git a/exampleSite/content/docs/configuration/site-params/index.zh-hant.md b/exampleSite/content/docs/configuration/site-params/index.zh-hant.md index 7b3d497d..c6f584ab 100644 --- a/exampleSite/content/docs/configuration/site-params/index.zh-hant.md +++ b/exampleSite/content/docs/configuration/site-params/index.zh-hant.md @@ -125,7 +125,7 @@ authors = ["RazonYang"] | `codeBlock.lineNos` | Boolean | `true` | `true`/`false` 表示默認情況下顯示/隱藏行號。 | **Post** | `post` | Object | - | -| ~~`post.excerpt`~~ | String | `Description` | 自 `v1.2.1` 刪除,若 Description 不為空則作為摘要。 +| `post.excerpt` | String | `Description` | 如果 Description 不為空則作為摘要,若需要使用 Summaries 作為摘要,你需要明確地將其設為**空字串**。 | `post.excerptMaxLength` | Integer | `320` | | `post.copyright` | Boolean | `true` | 是否在每個帖子上顯示版權部分 | `post.plainifyExcerpt` | Boolean | `true` | `false` 則格式化摘要為 HTML。 diff --git a/exampleSite/content/docs/content/index.md b/exampleSite/content/docs/content/index.md index 4e2f4a2e..a9fa2094 100644 --- a/exampleSite/content/docs/content/index.md +++ b/exampleSite/content/docs/content/index.md @@ -107,7 +107,7 @@ $ hugo new posts/new-post/index.zh-cn.md ## Summaries Selection Order -1. If the `description` is not empty, then it'll be used. +1. If the `description` is not empty, then it'll be used, to use summaries all the time, you should set the `post.excerpt` as _empty string_ explicitly. 1. Manual splitting via <!--more-->. 1. If `summary` on front matter isn't empty, then `summary` will be selected. 1. The text of content will be cut off by `post.excerptMaxLength` and formatted in plain text or HTML when `post.plainifyExcerpt = true`. diff --git a/exampleSite/content/docs/content/index.zh-hans.md b/exampleSite/content/docs/content/index.zh-hans.md index b40bcd44..cab19ee3 100644 --- a/exampleSite/content/docs/content/index.zh-hans.md +++ b/exampleSite/content/docs/content/index.zh-hans.md @@ -105,7 +105,7 @@ $ hugo new posts/new-post/index.zh-cn.md ## 摘要选择顺序 -1. If the `description` is not empty, then it'll be used. +1. If the `description` is not empty, then it'll be used, to use summaries all the time, you should set the `post.excerpt` as _empty string_ explicitly. 1. Manual splitting via <!--more-->. 1. If `summary` on front matter isn't empty, then `summary` will be selected. 1. The text of content will be cut off by `post.excerptMaxLength` and formatted in plain text or HTML when `post.plainifyExcerpt = true`. diff --git a/exampleSite/content/docs/content/index.zh-hant.md b/exampleSite/content/docs/content/index.zh-hant.md index de00f29c..b95565b7 100644 --- a/exampleSite/content/docs/content/index.zh-hant.md +++ b/exampleSite/content/docs/content/index.zh-hant.md @@ -105,7 +105,7 @@ $ hugo new posts/new-post/index.zh-tw.md ## 摘要選擇順序 -1. If the `description` is not empty, then it'll be used. +1. If the `description` is not empty, then it'll be used, to use summaries all the time, you should set the `post.excerpt` as _empty string_ explicitly. 1. Manual splitting via <!--more-->. 1. If `summary` on front matter isn't empty, then `summary` will be selected. 1. The text of content will be cut off by `post.excerptMaxLength` and formatted in plain text or HTML when `post.plainifyExcerpt = true`. diff --git a/layouts/partials/post/excerpt.html b/layouts/partials/post/excerpt.html index 23b72e70..deb10c7d 100644 --- a/layouts/partials/post/excerpt.html +++ b/layouts/partials/post/excerpt.html @@ -1,9 +1,14 @@ +{{- $key := "description" }} +{{- if isset site.Params.post "excerpt" }} + {{- $key = site.Params.post.excerpt }} +{{- end }} +{{- $useDescription := and (eq $key "description") .Description }} {{- $anchor := "" }} {{- if default false $.Site.Params.post.readMoreFromContent }}{{ $anchor = "#post-content-body" }}{{ end }} {{- $readMoreButton := printf "
%s
" .RelPermalink $anchor (i18n "read_more") | safeHTML }} {{- $content := "" }} {{- $readMore := true }} -{{- if .Description }} +{{- if $useDescription }} {{- $content = printf "

%s

" .Description | safeHTML }} {{- else if strings.Contains .RawContent "" }} {{- $content = .Summary }}