From 2e5396d9f259c07723b8ee6478041dfc2884fe60 Mon Sep 17 00:00:00 2001 From: Razon Yang Date: Fri, 28 Jul 2023 13:05:00 +0800 Subject: [PATCH] style: show the description if set (#964) BREAKING CHANGE: remove the post.excerpt parameter --- exampleSite/content/docs/configuration/site-params/index.md | 2 +- .../content/docs/configuration/site-params/index.zh-hans.md | 2 +- .../content/docs/configuration/site-params/index.zh-hant.md | 2 +- exampleSite/content/docs/content/index.md | 3 +-- exampleSite/content/docs/content/index.zh-hans.md | 3 +-- exampleSite/content/docs/content/index.zh-hant.md | 3 +-- .../content/docs/getting-started/introduction/index.md | 6 +----- exampleSite/content/posts/markdown-syntax/index.md | 4 +--- layouts/partials/docs/post.html | 3 +++ layouts/partials/post.html | 3 +++ layouts/partials/post/excerpt.html | 4 +--- 11 files changed, 15 insertions(+), 20 deletions(-) diff --git a/exampleSite/content/docs/configuration/site-params/index.md b/exampleSite/content/docs/configuration/site-params/index.md index b372ce638..a47df2f43 100644 --- a/exampleSite/content/docs/configuration/site-params/index.md +++ b/exampleSite/content/docs/configuration/site-params/index.md @@ -120,7 +120,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 | `Summary` | Options: `description` +| ~~`post.excerpt`~~ | String | `Description` | Deleted since `v1.2.1`, the description will be used as the excerpt if not empty. | `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 fff280b66..bdd2b7ecf 100644 --- a/exampleSite/content/docs/configuration/site-params/index.zh-hans.md +++ b/exampleSite/content/docs/configuration/site-params/index.zh-hans.md @@ -123,7 +123,7 @@ authors = ["RazonYang"] | `codeBlock.lineNos` | Boolean | `true` | `true`/`false` 表示默认情况下显示/隐藏行号。 | **Post** | `post` | Object | - | -| `post.excerpt` | String | `Summary` | 可选项:`description` +| ~~`post.excerpt`~~ | String | `Description` | 自 `v1.2.1` 删除,若 Description 不为空则作为摘要。 | `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 d7a2804c8..ceccb2e91 100644 --- a/exampleSite/content/docs/configuration/site-params/index.zh-hant.md +++ b/exampleSite/content/docs/configuration/site-params/index.zh-hant.md @@ -123,7 +123,7 @@ authors = ["RazonYang"] | `codeBlock.lineNos` | Boolean | `true` | `true`/`false` 表示默認情況下顯示/隱藏行號。 | **Post** | `post` | Object | - | -| `post.excerpt` | String | `Summary` | 可選項:`description` +| ~~`post.excerpt`~~ | String | `Description` | 自 `v1.2.1` 刪除,若 Description 不為空則作為摘要。 | `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 a30e51522..4e2f4a2e7 100644 --- a/exampleSite/content/docs/content/index.md +++ b/exampleSite/content/docs/content/index.md @@ -107,14 +107,13 @@ $ hugo new posts/new-post/index.zh-cn.md ## Summaries Selection Order -1. If `post.excerpt = "description"` and `description` is not empty, then it'll be used. +1. If the `description` is not empty, then it'll be used. 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`. ```toml {title="config/_default/params.toml"} [post] - # excerpt = "description" # 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/content/index.zh-hans.md b/exampleSite/content/docs/content/index.zh-hans.md index e9e014301..b40bcd445 100644 --- a/exampleSite/content/docs/content/index.zh-hans.md +++ b/exampleSite/content/docs/content/index.zh-hans.md @@ -105,14 +105,13 @@ $ hugo new posts/new-post/index.zh-cn.md ## 摘要选择顺序 -1. If `post.excerpt = "description"` and `description` is not empty, then it'll be used. +1. If the `description` is not empty, then it'll be used. 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`. ```toml {title="config/_default/params.toml"} [post] - # excerpt = "description" # 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/content/index.zh-hant.md b/exampleSite/content/docs/content/index.zh-hant.md index 23dd15365..de00f29c5 100644 --- a/exampleSite/content/docs/content/index.zh-hant.md +++ b/exampleSite/content/docs/content/index.zh-hant.md @@ -105,14 +105,13 @@ $ hugo new posts/new-post/index.zh-tw.md ## 摘要選擇順序 -1. If `post.excerpt = "description"` and `description` is not empty, then it'll be used. +1. If the `description` is not empty, then it'll be used. 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`. ```toml {title="config/_default/params.toml"} [post] - # excerpt = "description" # 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/getting-started/introduction/index.md b/exampleSite/content/docs/getting-started/introduction/index.md index 0c2a99181..5c31486ac 100644 --- a/exampleSite/content/docs/getting-started/introduction/index.md +++ b/exampleSite/content/docs/getting-started/introduction/index.md @@ -2,7 +2,7 @@ # type = "docs" title = "Introduction" date = 2022-06-13T16:32:09+08:00 -# description = "" # Used by description meta tag, summary will be used instead if not set or empty. +description = "Hugo Bootstrap Theme(HBS) is a fast, responsive, multipurpose and feature-rich Hugo theme. It is used for blog and document sites typically." featured = false draft = false comment = true @@ -19,10 +19,6 @@ navWeight = 100 authors = ["RazonYang"] +++ -Hugo Bootstrap Theme(HBS) is a fast, responsive, multipurpose and feature-rich Hugo theme. It is used for blog and document sites typically. - - - ## Goals - Performance diff --git a/exampleSite/content/posts/markdown-syntax/index.md b/exampleSite/content/posts/markdown-syntax/index.md index 76ed2e5a6..97e0cba85 100644 --- a/exampleSite/content/posts/markdown-syntax/index.md +++ b/exampleSite/content/posts/markdown-syntax/index.md @@ -2,7 +2,7 @@ author = "Hugo Authors" title = "Markdown Syntax Guide" date = "2020-11-09" -description = "Sample article showcasing basic Markdown syntax and formatting for HTML elements." +description = "This article offers a sample of basic Markdown syntax that can be used in Hugo content files, also it shows whether basic HTML elements are decorated with CSS in a Hugo theme." featured = true carousel = true categories = [ @@ -28,8 +28,6 @@ authors = ["Hugo"] icon = '' +++ -This article offers a sample of basic Markdown syntax that can be used in Hugo content files, also it shows whether basic HTML elements are decorated with CSS in a Hugo theme. - ## Headings diff --git a/layouts/partials/docs/post.html b/layouts/partials/docs/post.html index 890d9b70d..ef257adfd 100644 --- a/layouts/partials/docs/post.html +++ b/layouts/partials/docs/post.html @@ -6,6 +6,9 @@

{{ partial "helpers/title" . }}

{{- partial "post/meta" . -}} {{- partial "post/featured-image" . -}} + {{- with .Description }} +

{{ . }}

+ {{- end }} {{- partial "hooks/content-begin" . -}} {{- partial "post/toc-wrapper" . -}} {{- partial "post/content" . -}} diff --git a/layouts/partials/post.html b/layouts/partials/post.html index 86fc82c73..112c0427b 100644 --- a/layouts/partials/post.html +++ b/layouts/partials/post.html @@ -6,6 +6,9 @@

{{ partial "helpers/title" . }}

{{- partial "post/meta" . -}} {{- partial "post/featured-image" . -}} + {{- with .Description }} +

{{ . }}

+ {{- end }} {{- partial "hooks/content-begin" . -}} {{- if eq "content" .Site.Params.tocPosition -}} {{- partial "post/toc" . -}} diff --git a/layouts/partials/post/excerpt.html b/layouts/partials/post/excerpt.html index 48c16c91b..23b72e70e 100644 --- a/layouts/partials/post/excerpt.html +++ b/layouts/partials/post/excerpt.html @@ -1,11 +1,9 @@ -{{- $key := $.Site.Params.post.excerpt }} -{{- $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 $useDescription }} +{{- if .Description }} {{- $content = printf "

%s

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