Skip to content
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

[8.x] Improve linkability of docs by adding named anchors to h4 tags #6506

Merged
merged 3 commits into from
Oct 20, 2020

Conversation

jessarcher
Copy link
Member

Some h4 tags already had named anchors, but the majority didn't. This made it hard to link to specific subsections of the documentation in blog posts, peer reviews, chats, etc. I have often found myself linking to a h3 tag and then telling the recipient to "scroll until you reach X". This PR aims to fix that by:

  • Adding named anchors to the h4 tags that were missing them.
  • Adding named anchors to the handful of h3 tags that were also missing them.
  • Fixing an existing duplicate anchor name.

This PR does not change the TOC or visual appearance. The only UX change is that the h4 tags are now focusable and have a pointer cursor as they are links, but they do not have the red "#" that the other headings have (I can PR this to the website repo if that is a welcome addition though).

I have also only done this for the 8.x branch.

The process

I mostly automated this by writing a script that searched for lines beginning with #### that weren't already preceded by a named anchor, and then automatically prepended a named anchor with a slugified version of the heading text. Thanks Str::slug()!

This created a few duplicate anchor names within the same page, so I wrote another script to find any duplicates within the same file so that I could manually add some extra context to uniquely distinguish them. In doing so I found one preexisting duplicate that I also fixed.

It's not a perfect process, but given there ended up being 674 new anchors, it was too much to do by hand. I have had a quick glance over every added anchor and they all seem good to me.

A selection of h4 tags already had anchor tags so this is really just
filling in the gaps (of which there is many!)

This makes it much easier to share a specific subsection of the docs in
blog posts, PRs, chat, etc.
@timacdonald
Copy link
Member

I have wanted this sooooooo many times. Thank you 🙌

Comment on lines -131 to +134
<a name="fluent-strings"></a>
<a name="fluent-strings-method-list"></a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we worried that this will break existing links to this header in existing blog posts and what not

Copy link
Member Author

@jessarcher jessarcher Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an existing duplicate anchor name, so it will have already been broken to some extent, depending on which of the two "Fluent Strings" headings they were attempting to link to.

One was a h2 and one was a h3, so I changed the h3, because the h2 outranked it 🤣. However, this h3 comes first in the document, and it seems like that one "wins" when there are duplicates on the page, at least with Firefox. So I may have been better off changing the h2, although to what I'm not sure.

The TOC on this page is also missing a lot of the h3 links and could probably do with a bit of attention.

Copy link
Member

@driesvints driesvints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lgtm. Thanks Jess!

Copy link

@midnightcipher midnightcipher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely going to help me link sections to other team mates! Thanks Jess

@taylorotwell taylorotwell merged commit 6823f65 into laravel:8.x Oct 20, 2020
@taylorotwell
Copy link
Member

Nice work!

@HiroKws
Copy link
Contributor

HiroKws commented Oct 20, 2020

To be honest, I wonder if these are manually maintained. It makes more sense to leave it to the converter that converts markdown to HTML, or generate them on load with JavaScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants