Skip to content

Commit

Permalink
fix!: generate unique properties anchor (#457)
Browse files Browse the repository at this point in the history
The way anchors are generated for `properties` of a `propertylist` has changed to be unique, even if the shortcode is used multiple times on a page.
  • Loading branch information
xoxys authored Oct 27, 2023
1 parent 72c23c9 commit aef6f59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion exampleSite/content/posts/advanced/shortcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ The supported attributes can be taken from the following example:

<!-- prettier-ignore-start -->
<!-- spellchecker-disable -->
{{< propertylist name=shortcode-buttons sort=name order=asc >}}
{{< propertylist name=shortcode-propertylist sort=name order=asc >}}
<!-- spellchecker-enable -->
<!-- prettier-ignore-end -->

Expand Down
5 changes: 3 additions & 2 deletions layouts/shortcodes/propertylist.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
{{- $properties = (sort $properties . $order) }}
{{- end }}
{{- range $properties }}
<dt class="flex flex-wrap align-center gblog-props__meta"{{ if $showAnchor }} id="{{ anchorize .name }}"{{ end }}>
{{- $uniqueAnchor := anchorize (printf "%s-%s" $name .name) | safeHTML }}
<dt class="flex flex-wrap align-center gblog-props__meta"{{ if $showAnchor }} id="{{ $uniqueAnchor }}"{{ end }}>
<span class="gblog-props__title">{{ .name }}</span>
{{- if .required }}
<span class="gblog-props__tag warning">required</span>
Expand All @@ -28,7 +29,7 @@
{{- end }}
{{- end }}
{{- if $showAnchor }}
<a data-clipboard-text="{{ .Page.Permalink }}#{{ anchorize .name | safeHTML }}" class="gblog-post__anchor clip flex align-center" title="{{ i18n "title_anchor_prefix" }} {{ .name | safeHTML }}" aria-label="{{ i18n "title_anchor_prefix" }} {{ .name | safeHTML }}" href="#{{ anchorize .name | safeHTML }}">
<a data-clipboard-text="{{ .Page.Permalink }}#{{ $uniqueAnchor }}" class="gblog-post__anchor clip flex align-center" title="Anchor to: {{ .name | safeHTML }}" aria-label="Anchor to: {{ .name | safeHTML }}" href="#{{ $uniqueAnchor | safeHTML }}">
<svg class="gblog-icon gblog_link"><use xlink:href="#gblog_link"></use></svg>
</a>
{{- end }}
Expand Down

0 comments on commit aef6f59

Please sign in to comment.