Skip to content

Commit

Permalink
style: show the description if set (#964)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: remove the post.excerpt parameter
  • Loading branch information
razonyang committed Jul 28, 2023
1 parent 0b0212c commit 2e5396d
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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。
Expand Down
3 changes: 1 addition & 2 deletions exampleSite/content/docs/content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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`.

```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.
Expand Down
3 changes: 1 addition & 2 deletions exampleSite/content/docs/content/index.zh-hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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`.

```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.
Expand Down
3 changes: 1 addition & 2 deletions exampleSite/content/docs/content/index.zh-hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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`.

```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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

<!--more-->

## Goals

- Performance
Expand Down
4 changes: 1 addition & 3 deletions exampleSite/content/posts/markdown-syntax/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -28,8 +28,6 @@ authors = ["Hugo"]
icon = '<i class="fab fa-markdown fa-fw text-success"></i>'
+++

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.
<!--more-->

## Headings

Expand Down
3 changes: 3 additions & 0 deletions layouts/partials/docs/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ <h1 class="card-title post-title my-2">{{ partial "helpers/title" . }}</h1>
<div class="card-body">
{{- partial "post/meta" . -}}
{{- partial "post/featured-image" . -}}
{{- with .Description }}
<p class="lead mb-3 text-body-emphasis">{{ . }}</p>
{{- end }}
{{- partial "hooks/content-begin" . -}}
{{- partial "post/toc-wrapper" . -}}
{{- partial "post/content" . -}}
Expand Down
3 changes: 3 additions & 0 deletions layouts/partials/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ <h1 class="card-title post-title my-2">{{ partial "helpers/title" . }}</h1>
<div class="card-body">
{{- partial "post/meta" . -}}
{{- partial "post/featured-image" . -}}
{{- with .Description }}
<p class="lead mb-3 text-body-emphasis">{{ . }}</p>
{{- end }}
{{- partial "hooks/content-begin" . -}}
{{- if eq "content" .Site.Params.tocPosition -}}
{{- partial "post/toc" . -}}
Expand Down
4 changes: 1 addition & 3 deletions layouts/partials/post/excerpt.html
Original file line number Diff line number Diff line change
@@ -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 "<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 $useDescription }}
{{- if .Description }}
{{- $content = printf "<p>%s</p>" .Description | safeHTML }}
{{- else if strings.Contains .RawContent "<!--more-->" }}
{{- $content = .Summary }}
Expand Down

0 comments on commit 2e5396d

Please sign in to comment.