Copy over the plugins

This commit is contained in:
2026-08-08 19:53:22 -04:00
parent 3a2ae757c0
commit ea77e8f02a
7 changed files with 196 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
# If the configuration sets `open_external_links_in_new_tab` to a truthy value,
# add 'target=_blank' to anchor tags that don't have `internal-link` class
# frozen_string_literal: true
require 'nokogiri'
Jekyll::Hooks.register [:notes], :post_convert do |doc|
convert_links(doc)
end
Jekyll::Hooks.register [:pages], :post_convert do |doc|
# jekyll considers anything at the root as a page,
# we only want to consider actual pages
next unless doc.path.start_with?('_pages/')
convert_links(doc)
end
def convert_links(doc)
open_external_links_in_new_tab = !!doc.site.config["open_external_links_in_new_tab"]
if open_external_links_in_new_tab
parsed_doc = Nokogiri::HTML::DocumentFragment.parse(doc.content)
parsed_doc.css("a:not(.internal-link):not(.footnote):not(.reversefootnote)").each do |link|
link.set_attribute('target', '_blank')
end
doc.content = parsed_doc.inner_html
end
end