Skip to content

Commit

Permalink
fix: bring the post.excerpt parameter back (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Dec 2, 2023
1 parent 4aafd72 commit ed07b2f
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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。
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/docs/content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>&lt;!--more--&gt;</code>.
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`.
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/docs/content/index.zh-hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>&lt;!--more--&gt;</code>.
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`.
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/docs/content/index.zh-hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>&lt;!--more--&gt;</code>.
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`.
Expand Down
7 changes: 6 additions & 1 deletion layouts/partials/post/excerpt.html
Original file line number Diff line number Diff line change
@@ -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 "<div><a class=\"btn btn-sm btn-outline-primary btn-read-more\" href=\"%s%s\">%s</a></div>" .RelPermalink $anchor (i18n "read_more") | safeHTML }}
{{- $content := "" }}
{{- $readMore := true }}
{{- if .Description }}
{{- if $useDescription }}
{{- $content = printf "<p>%s</p>" .Description | safeHTML }}
{{- else if strings.Contains .RawContent "<!--more-->" }}
{{- $content = .Summary }}
Expand Down

0 comments on commit ed07b2f

Please sign in to comment.