Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autogenerate heading anchors #30825
Autogenerate heading anchors #30825
Changes from 56 commits
5cb5c9a
ca2f664
556f82b
4a6acd4
042a1aa
8c4be85
766ef32
3296651
3e6928c
1e5d3d7
2d20135
69efbab
e5af9c8
15e04db
635eca9
4c03e1b
abeaaaf
9f728c2
4579a72
93b0d4d
a9f6381
762af2c
c3ccf1c
47014dd
cc34994
4b9e037
a1263d9
370409e
951480c
9953f70
694180e
34d1721
50141d7
7e0f1d9
f1ad7c2
c61d9a7
7d8c3ea
00006fe
7b8b783
516c400
842449d
3ec7e1e
171f228
577feb6
5706771
60114f1
0dbefeb
2a021a6
716b5a9
4f5c06e
88cf66c
8c0e353
234abfc
6535526
8f39085
43cc150
db12f78
5bb9302
bbabee8
98d29dc
b5cb1f9
2b1f215
79f49ff
b5b34a8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say I save a page with three headings that map to the same anchor. Then here we get
plants
,plants-1
,plants-2
. Let's say I remove the initial paragraph from that page, and add a new one that is also titledplants
. I think this code would assign it the freshly freed anchorplants
, which means that all the links to that anchor would now lead to a wrong heading.I would love to make these headings persistent in some way. A naive approach would involve always
+1
-ing the largest related number, so even ifplants
is free and we only haveplants-1
andplants-2
, we would still assignplants-3
.The problem with that approach is that it is possible to remove just
plants-2
or even bothplants-1
andplants-2
so now there is no information we could use to avoid assigning new headings with the same anchors. For that, we would need to store the list of the "largest" anchors for each slug somewhere (["plants-4", "doors-4", "potatoes"]
). Maybe in page meta...?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think think that this is required or even desired. Because normally you want to avoid duplicated headings. It makes no sense in most cases and might be bad for SEO anyways.
Now imagine I am currently scribbling my post together. I duplicate blocks to try things out, and I remove them afterwards. I end up having id anchor of
anchor-2
etc everywhere. But in the end I just want to have a "just working" TOC and a clean link for my users. Thatswhy I would prefer to always fall back to normal headings.Another note:
What if I have
heading
andheading-1
and I deleteheading
. Willheading-1
becomeheading
afterwards. My 2cents are, that it should. Correct me if I am wrong with that idea.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NicoHood you are right, it does make sense for the writing and drafting phase. What I am worried about is the post-publish phase once the URLs are out there in the wild. Permalinks, cool urls don't change, that kind of stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel That is correct, but it is not an url, it is an anchor. Meaning the website will still function, but not scroll.
Lets say you have a heading called: "Red cars" which you rename to "Blue bike". Then the anchor (aka "url") will be "broken" too.
If someone wants a fixed anchor, he should enter his own id from the block settings. I am not sure if that is still possible with this PR, but that's what I'd expect the editor to do.
BTW: That is also how all other CMS work, Github and the Arch Linux Wiki as well. Just be careful in renaming the headings if you are refering to their autogenerated anchor. As easy as it is. I guess there is no "better" or perfect solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no perfect solution here... There are pros and cons in all cases.
I don't think the
-1
etc suffixes will be used that often... If they do get used often it's indicative of a messy page structure, since having multiple headings with the same text is sub-optimal for screen-readers. The suffixes are there to avoid issues, but they are an edge-case and not the norm.Manually-edited anchors are persistent, so if after publishing a page an author edits a page and changes the structure of headings, they can manually edit the anchors and make them whatever they want.