Styling the external links on this site
One nice side-effect of doing this #WeblogPoMo2024 challenge is that I’m forced to look at my website every day, and I’m inspired to make little changes to it. I decided I wanted to add some visual distinction between external links and internal links.
I figured I’d have to put some “middleware” in the markdown-to-HTML processing that Astro uses. I was researching rehype plugins, trying to figure out what exactly to do before I found an Astro docs page explaining how to achieve almost exactly what I wanted. Another high-five to the Astro docs maintainers!
In their example, they insert HTML content to the link, but I just wanted to add a class to the external links, so I could add an icon with a Pseudo-element. I worked out how to add the className property using the rehype-external-links plugin. Then I added some css so the external links show a little arrow on them.
Here’s the commit with the changes to the site.
Now I’ve styled the external links, I’m thinking about adding a “peek” functionality to the internal links. The idea is that when you hover on the internal links you get a little preview to the content of the note that is linked. You can see an example of this sort of hover effect at Andy Matuschak’s notes.
What do you think about that feature? Would it be cool? Or annoying? Sound off in the comments/my inbox/on Mastodon.
This has been post no. 18 for #WeblogPoMo2024 and it is what I was interested in today.
Comments
Bob Monsour
May 18, 2024 at 4:29 PM
I like the idea. I would like to do it for externl links on one of my sites. I know that it's doable, but haven't undertaken the effort. My only thought on restricting this to internal links is that unless you style those links somewhat differently, visitors to the site might have an expectation that external links would operate similarly and perhaps experience some frustration when they don't. Anyway, that's my 2 cents.
Reilly Spitzfaden
May 19, 2024 at 1:23 AM
I was just reading Maggie Appleton's discussion of Project Xanadu, and that got me thinking of including hover previews on my own site someday. I think it would be nice here!
Leave a Comment
💯 Thanks for submitting your comment! It will appear here after it has been approved.