~xdavidwu/xdavidwu.link

b3c855d4f9294cc480d57c74baa7bc4982ba8e08 — xdavidwu 4 years ago 2b0b873
ruby-based anchor
2 files changed, 5 insertions(+), 13 deletions(-)

A _plugins/anchor.rb
M assets/js/_main.js
A _plugins/anchor.rb => _plugins/anchor.rb +5 -0
@@ 0,0 1,5 @@
class Jekyll::MarkdownHeader < Jekyll::Converters::Markdown
    def convert(content)
        super.gsub(/<h(\d) id="(.*?)">(.*)<\/h(\d)>/, '<h\1 id="\2">\3<a class="header-link" href="#\2"><span class="sr-only">Permalink</span><i class="fas fa-link"></i></a></h\1>')
    end
end

M assets/js/_main.js => assets/js/_main.js +0 -13
@@ 117,17 117,4 @@ $(document).ready(function() {
    closeOnContentClick: true,
    midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
  })*/;

  // Add anchors for headings
  $('.page__content').find('h1, h2, h3, h4, h5, h6').each(function() {
    var id = $(this).attr('id');
    if (id) {
      var anchor = document.createElement("a");
      anchor.className = 'header-link';
      anchor.href = '#' + id;
      anchor.innerHTML = '<span class=\"sr-only\">Permalink</span><i class=\"fas fa-link\"></i>';
      anchor.title = "Permalink";
      $(this).append(anchor);
    }
  });
});