Skip to content

Commit

Permalink
Feat: refactor summary and headings render, add summaryPlainify par…
Browse files Browse the repository at this point in the history
…am and front matter
  • Loading branch information
Lruihao committed Oct 12, 2024
1 parent 5f91c21 commit 84ac193
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
3 changes: 3 additions & 0 deletions config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ titleDelimiter = "|"
# FixIt 0.3.0 | 新增 是否在主页标题中添加网站副标题
# 请记得通过 `params.header.subtitle.name` 设置网站副标题
indexWithSubtitle = true
# FixIt 0.3.13 | NEW whether to show summary in plain text
# FixIt 0.3.13 | 新增 是否显示纯文本摘要
summaryPlainify = false
# FixIt 0.2.14 | NEW FixIt will, by default, inject a theme meta tag in the HTML head on the home page only.
# You can turn it off, but we would really appreciate if you don’t, as this is a good way to watch FixIt's popularity on the rise.
# FixIt 0.2.14 | 新增 默认情况下,FixIt 只会在主页的 HTML 头中注入主题元标记。
Expand Down
19 changes: 10 additions & 9 deletions content/en/documentation/content-management/introduction/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ hugo new --kind post-bundle posts/bar/
- **keywords**: the keywords for the content.
- **license**: the special lisence for this content.
- **images**: page images for Open Graph and Twitter Cards.
- **summary**: the summary for the content.
- **summaryPlainify**: {{< version 0.3.13 >}} whether to show summary in plain text, default: `false`. The same as the `params.summaryPlainify` in the [theme configuration][theme-config].

- **tags**: the tags for the content.
- **categories**: the categories for the content.
Expand Down Expand Up @@ -308,22 +310,21 @@ You may add the `<!--more-->` summary divider at the start of the article. Keep

### Comparison

Because there are multiple ways in which a summary can be specified it is useful to understand the order. It is as follows:
Each summary type has different characteristics:

| Type | Precedence | Renders markdown | Renders shortcodes | Strips HTML tags | Wraps single lines with `<p>` |
| :---------------- | :--------: | :--------------: | :----------------: | :--------------: | :---------------------------: |
| Manual | 1 | ✔️ | ✔️ | ❌ | ✔️ |
| Front&nbsp;matter | 2 | ✔️ | ❌ | ❌ | ❌ |
| Automatic | 3 | ✔️ | ✔️ | ✔️ | ❌ |
| Type | Precedence | Renders markdown | Renders shortcodes | Wraps single lines with `<p>` |
| :---------------- | :--------: | :--------------: | :----------------: | :---------------------------: |
| Manual | 1 | ✔️ | ✔️ | ✔️ |
| Front&nbsp;matter | 2 | ✔️ | ❌ | ❌ |
| Automatic | 3 | ✔️ | ✔️ | ❌ |

1. If there is a `<!--more-->` summary divider present in the article but no content is before the divider, the description will be used as the summary.
2. If there is a `<!--more-->` summary divider present in the article the text up to the divider will be provided as per the manual summary split method.
3. If there is a summary variable in the article front matter the value of the variable will be provided as per the front matter summary method.
4. The text at the start of the article will be provided as per the automatic summary split method.

{{< admonition >}}
It is not recommended to include rich text block elements in the summary, which will cause typographic errors. Such as code blocks, pictures, tables, etc.
{{< /admonition >}}
> [!TIP]
> If you want plain text summaries, you can set `params.summaryPlainify` or Front matter `summaryPlainify`.

## Markdown Syntax

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ auto

`bool` Whether to add site subtitle to the title of index page. Default is `false`. Remember to set up your site subtitle by `params.header.subtitle.name`.

### summaryPlainify

{{< version 0.3.13 >}}

`bool` Whether to show summary in plain text. Default is `false`.

### disableThemeInject

{{< version 0.2.14 >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ hugo new friends/index.md
{{< /admonition >}}

{{< admonition tip "" false >}}
**FixIt** 主题内嵌了一些 [原型 (Archetypes)](https://gohugo.io/content-management/archetypes/),使用以下命令创建新内容时会自动带入常用的 Front matter:
**FixIt** 主题内嵌了一些 [原型 (Archetype)](https://gohugo.io/content-management/archetypes/),使用以下命令创建新内容时会自动带入常用的 Front matter:

```bash
hugo new posts/foo.md
Expand Down Expand Up @@ -134,6 +134,8 @@ hugo new --kind post-bundle posts/bar/
- **keywords**: 文章内容的关键词
- **license**: 这篇文章特殊的许可
- **images**: 页面图片,用于 Open Graph 和 Twitter Cards
- **summary**: 文章的摘要
- **summaryPlainify**: {{< version 0.3.13 >}} 是否显示纯文本摘要,默认:`false`。和 [主题配置][theme-config] 中的 `params.summaryPlainify` 相同

- **tags**: 文章的标签
- **categories**: 文章所属的类别
Expand Down Expand Up @@ -310,22 +312,21 @@ seo:

### 比较

由于可以通过多种方式指定摘要,因此了解顺序很有用。如下
每种摘要类型都有不同的特点

| 类型 | 优先级 | 渲染 Markdown | 渲染 Shortcodes | 删除 HTML 标签 | 使用 `<p>` 换行 |
| :----------- | :----: | :-----------: | :-------------: | :------------: | :-------------: |
| 手动摘要 | 1 | ✔️ | ✔️ | ❌ | ✔️ |
| Front&nbsp;matter | 2 | ✔️ | ❌ | ❌ | ❌ |
| 自动摘要 | 3 | ✔️ | ✔️ | ✔️ | ❌ |
| 类型 | 优先级 | 渲染 Markdown | 渲染 Shortcodes | 使用 `<p>` 换行 |
| :---------------- | :----: | :-----------: | :-------------: | :-------------: |
| 手动摘要 | 1 | ✔️ | ✔️ | ✔️ |
| Front&nbsp;matter | 2 | ✔️ | ❌ | ❌ |
| 自动摘要 | 3 | ✔️ | ✔️ | ✔️ |

1. 如果文章中有 `<!--more-->` 摘要分隔符,但分隔符之前没有内容,则使用描述作为摘要。
2. 如果文章中有 `<!--more-->` 摘要分隔符,则将按照手动摘要拆分的方法获得摘要。
3. 如果文章 Front matter 中有摘要变量,那么将以该值作为摘要。
4. 按照自动摘要拆分方法。

{{< admonition warning >}}
不建议在摘要内容中包含富文本块元素,这会导致渲染错误。例如代码块,图片,表格等。
{{< /admonition >}}
> [!TIP]
> 如果你想要纯文本摘要,可以设置 `params.summaryPlainify` 或者 Front matter `summaryPlainify`。

## Markdown 语法

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ auto

`bool` 是否在主页标题中添加网站副标题,默认:`false`。请记得通过 `params.header.subtitle.name` 设置网站副标题。

### summaryPlainify

{{< version 0.3.13 >}}

`bool` 是否显示纯文本摘要,默认:`false`

### disableThemeInject

{{< version 0.2.14 >}}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/hugo-fixit/docs
go 1.20

require (
github.com/hugo-fixit/FixIt v0.3.13-0.20241011055707-c974c905e524 // indirect
github.com/hugo-fixit/FixIt v0.3.13-0.20241012095907-581466fd25c9 // indirect
github.com/hugo-fixit/component-projects v1.3.4 // indirect
github.com/hugo-fixit/shortcode-caniuse v1.1.3 // indirect
github.com/hugo-fixit/shortcode-rewards v1.0.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/hugo-fixit/FixIt v0.3.13-0.20241011055707-c974c905e524 h1:hvHWzuqZ+78cIW4mo/ZJ3gqGTnrgHlZrnHQYPE/G8Bg=
github.com/hugo-fixit/FixIt v0.3.13-0.20241011055707-c974c905e524/go.mod h1:3XIRedrqakO7/a4ZnhE46haMRF8HgsT0N0B5j5D2iRU=
github.com/hugo-fixit/FixIt v0.3.13-0.20241012095907-581466fd25c9 h1:feZjaI9z/VB1IEmDdEfw2jDFIcz4XbN+DDnQuwPkHow=
github.com/hugo-fixit/FixIt v0.3.13-0.20241012095907-581466fd25c9/go.mod h1:3XIRedrqakO7/a4ZnhE46haMRF8HgsT0N0B5j5D2iRU=
github.com/hugo-fixit/component-projects v1.3.4 h1:HXo/CUEJIQaFct4EAkX9u0Hyt1USv+6Tw0yKNS1tKoA=
github.com/hugo-fixit/component-projects v1.3.4/go.mod h1:nXW0R37REwpfwUD1I4RtB5QW71vw66nRyB9uEpYxr+c=
github.com/hugo-fixit/shortcode-caniuse v1.1.3 h1:U1YBJz5SI/d1BBQhHcD0eVgJdCcpzK2usSizPiu+a4w=
Expand Down

0 comments on commit 84ac193

Please sign in to comment.