From 0e0a68d94cc2e18f09155657158e22d5cdc176c1 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 13 Aug 2020 06:12:39 -0300 Subject: Create Jekyll hook to add header anchors based on the header IDs Impement add-anchor-to-header-from-header-id.rb using regexps, like the "official hooks" do: - https://github.com/jekyll/jekyll-mentions - https://github.com/jekyll/jemoji --- _plugins/add-anchor-to-header-from-header-id.rb | 9 +++++++++ images/link.svg | 5 +++++ styles.css | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 _plugins/add-anchor-to-header-from-header-id.rb create mode 100644 images/link.svg diff --git a/_plugins/add-anchor-to-header-from-header-id.rb b/_plugins/add-anchor-to-header-from-header-id.rb new file mode 100644 index 0000000..8c100b0 --- /dev/null +++ b/_plugins/add-anchor-to-header-from-header-id.rb @@ -0,0 +1,9 @@ +Jekyll::Hooks.register :documents, :post_render do |doc| + if doc.output_ext == ".html" + doc.output = + doc.output.gsub( + /(.*?)<\/h[1-6]>/, + '\5' + ) + end +end diff --git a/images/link.svg b/images/link.svg new file mode 100644 index 0000000..eab23a3 --- /dev/null +++ b/images/link.svg @@ -0,0 +1,5 @@ + + + + diff --git a/styles.css b/styles.css index 7a4d05f..687fa72 100644 --- a/styles.css +++ b/styles.css @@ -80,3 +80,16 @@ section.post-footer, div.footnotes { height: 22px; vertical-align: middle; } + +a.header-anchor { + color: black; + text-decoration: none; +} + +a.header-anchor img { + visibility: hidden; +} + +a.header-anchor:hover img { + visibility: visible; +} -- cgit v1.2.3