feat: add article.headingAnchor parameter and use CSS pseudo-element to display # symbol of heading anchor (#1016)

* feat: add `article.headingAnchor` parameter

* feat: use CSS pseudo-element to display `#` symbol of heading anchor

This prevents RSS feed readers and screen readers from seeing an extra `#`.

* Deactivate `article.headingAnchor` by default
This commit is contained in:
Jimmy Cai 2024-05-02 23:27:17 +02:00 committed by GitHub
parent 130e2f6607
commit f3783856ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 1 deletions

View File

@ -232,6 +232,10 @@
width: var(--card-padding);
text-align: center;
color: var(--accent-color);
&:before {
content: "#";
}
}
&:hover,

View File

@ -28,6 +28,7 @@ params:
src: img/avatar.png
article:
headingAnchor: false
math: false
toc: true
readingTime: true

View File

@ -1,4 +1,6 @@
<h{{ .Level }} id="{{ .Anchor }}">
<a href="#{{ .Anchor }}" class="header-anchor">#</a>
{{- if site.Params.Article.HeadingAnchor -}}
<a href="#{{ .Anchor }}" class="header-anchor"></a>
{{- end -}}
{{ .Text | safeHTML }}
</h{{ .Level }}>