Skip to content

Commit

Permalink
feat: add the numberifyHeadings page parameter (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Dec 2, 2023
1 parent ed07b2f commit 9947857
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Expand Up @@ -57,3 +57,4 @@ Page parameters are located in page's [Front Matter](https://gohugo.io/content-m
| `recentPostCount` | Integer/Boolean | `5` | The number of recent posts shown in sidebar. Turn off by setting it to `false`.
| `relatedPostCount` | Integer/Boolean | `5` | The number of related posts. Turn off by setting it to `false`.
| `featuredImageAlt` | String | - | The alternative text for featured images, fallback to page title if not present.
| `numberifyHeadings` | Boolean | `true` | When `false`, headings won't be numebrified.
Expand Up @@ -56,3 +56,4 @@ authors = ["RazonYang"]
| `recentPostCount` | Integer/Boolean | `5` | 最近文章数,`false` 则隐藏。
| `relatedPostCount` | Integer/Boolean | `5` | 相关文章数,`false` 则隐藏。
| `featuredImageAlt` | String | - | 封面的可选文本,若未指定则使用页面标题。
| `numberifyHeadings` | Boolean | `true` | 为 `false` 时,不对标题进行编号。
Expand Up @@ -56,3 +56,4 @@ authors = ["RazonYang"]
| `recentPostCount` | Integer/Boolean | `5` | 最近文章數,`false` 則隱藏。
| `relatedPostCount` | Integer/Boolean | `5` | 相關文章數,`false` 則隱藏。
| `featuredImageAlt` | String | - | 封面的可選文字,若未指定則使用頁面標題。
| `numberifyHeadings` | Boolean | `true` | 為 `false` 時,不對標題進行編號。
13 changes: 12 additions & 1 deletion layouts/_default/_markup/render-heading.html
@@ -1,2 +1,13 @@
{{- $anchor := printf "<a class=\"anchor ms-1\" href=\"#%s\"></a>" .Anchor | safeHTML -}}
{{ printf "<h%d id=\"%s\" data-numberify>%s%s</h%d>" .Level .Anchor .PlainText $anchor .Level | safeHTML }}
{{- $numberifyHeadings := true }}
{{- if isset .Page.Params "numberifyheadings" }}
{{- $numberifyHeadings = .Page.Params.numberifyHeadings }}
{{- end }}
{{ printf "<h%d id=\"%s\"%s>%s%s</h%d>"
.Level
.Anchor
(cond $numberifyHeadings ` data-numberify` ``)
.PlainText
$anchor
.Level | safeHTML
}}

0 comments on commit 9947857

Please sign in to comment.