You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Javascript can't cross origins, but Ruby sure can.
Populating a[title] at build-time with the titles of the link targets would significantly help with accessibility. Bonus points if it updates the Markdown (only in dev?) so the results can be committed.
This infrastructure could also be a good foundation for validating external links in our neverending battle against bit rot.
The text was updated successfully, but these errors were encountered:
Doing this on every Jekyll build might be a bit much, especially if it also checks external links for liveness; maybe this is a good candidate for a script? Then it could:
Run incrementally against only external links in dirtied files
Be invoked in a targeted way by Jekyll when it comes across a link without a title
Run on every build to check all internal links for liveness
Restricting to Jekyll.env == "development" (which is read from JEKYLL_ENV) is probably good enough.
Possible starting point:
require'nokogiri'require'open-uri'Jekyll::Hooks.register:site,:after_resetdo |site|
returnunlessJekyll.env == "development"# Run only in development environmentsite.pages.eachdo |page|
nextunlesspage.path.end_with?(".md")filename=File.join(site.source,page.path)content=File.read(filename)updated_content=content.gsub(/\[([^\]]+)\]\((http[^)"\s]+)\)/)do |match|
text= $1
url= $2
title=fetch_title(url)title ? "[#{text}](#{url}\"#{title}\")" : matchend# Write changes back to the disk only if there were changesFile.write(filename,updated_content)ifcontent != updated_contentendenddeffetch_title(url)doc=Nokogiri::HTML(URI.open(url))doc.at('title')&.text.striprescuenilend
Javascript can't cross origins, but Ruby sure can.
Populating
a[title]
at build-time with the titles of the link targets would significantly help with accessibility. Bonus points if it updates the Markdown (only in dev?) so the results can be committed.This infrastructure could also be a good foundation for validating external links in our neverending battle against bit rot.
The text was updated successfully, but these errors were encountered: