Skip to content

Commit df83ef1

Browse files
authored
wg: Fix duplicate ids (#475)
This prepends a prefix to title ids, in order to avoid conflicts when two posts have titles with the same text (eg. consecutive spec round-ups).
1 parent 97cb1b8 commit df83ef1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

wg.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,20 @@ <h3><a href="https://github.com/ircv3/ircv3-specifications/milestone/4">Roadmap<
7878
</div>
7979

8080
{% for post in site.posts limit:10 %}
81+
{% comment %} add a prefix to ids to avoid duplicates within the same page {% endcomment %}
82+
{% assign h3_prefix = '<h3 id="' | append: post.id | append: '-' | replace_first: '/', '' %}
83+
{% assign h4_prefix = '<h4 id="' | append: post.id | append: '-' | replace_first: '/', '' %}
84+
{% assign h5_prefix = '<h5 id="' | append: post.id | append: '-' | replace_first: '/', '' %}
85+
{% assign h6_prefix = '<h6 id="' | append: post.id | append: '-' | replace_first: '/', '' %}
8186
<div class="post">
8287
<h3><a href="{{ post.url }}">{{ post.title | xml_escape }}</a> <span class="meta">{{ post.date | date_to_string }}</span></h3>
8388
<div class="post-content">
84-
{{ post.content }}
89+
{{ post.content
90+
| replace: '<h6 id="', h6_prefix
91+
| replace: '<h5 id="', h5_prefix
92+
| replace: '<h4 id="', h4_prefix
93+
| replace: '<h3 id="', h3_prefix
94+
}}
8595
</div>
8696
</div>
8797
{% endfor %}

0 commit comments

Comments
 (0)