2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-03 23:54:20 +08:00
discourse/db/migrate/20251125202538_rebake_posts_with_heading_anchors.rb
Kris 27854ac8e7
A11Y: add aria-label to automatically generated heading anchor links in posts (#36232)
Currently our automatically generated anchor links for headings in posts
are pretty awful to listen to in screenreaders, because screenreaders
are reading the `name` attribute.

Here's an example from a [Meta
post](https://meta.discourse.org/t/a-new-review-queue-layout-with-all-new-features/388194)...
this "A refreshed layout" heading reads like:

 "p-1888119-a-refreshed-layout-1" 

This PR adds `aria-label="heading link"` so now this would read like:

"Heading link, same page link, A Refreshed Layout, heading level 1"

I've added a migration so posts with headings will rebake with the
improved markup.

---------

Co-authored-by: Yuriy Kurant <yuriy@discourse.org>
2025-11-25 18:29:20 -05:00

13 lines
294 B
Ruby

# frozen_string_literal: true
class RebakePostsWithHeadingAnchors < ActiveRecord::Migration[8.0]
def up
execute <<~SQL
UPDATE posts SET baked_version = NULL
WHERE cooked LIKE '%class="anchor"%'
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end