class Object
Public Instance Methods
process_content(site_hostname, content, anchor_contents)
click to toggle source
Given hostname and content, updates <hN> tags, adding trailing <a class=“anchor-link”></a>.
# File lib/jekyll-theme-isotc154-helpers/headerlinks.rb, line 5 def process_content(site_hostname, content, anchor_contents) content = Nokogiri::HTML(content) content.css('main h2[id], main h3[id], main h4[id], main h5[id]').each do |el| html_id = el.get_attribute('id') el.inner_html = "#{el.inner_html}<a class='anchor-link' href='./##{html_id}'>#{anchor_contents}</a>" end return content.to_s end
process_doc_or_page(doc)
click to toggle source
Jekyll
hook handler function.
# File lib/jekyll-theme-isotc154-helpers/headerlinks.rb, line 18 def process_doc_or_page(doc) site_hostname = URI(doc.site.config['url']).host # TODO: Read anchor_contents from site config anchor_contents = "<i class='fas fa-link'></i>" unless doc.respond_to?(:asset_file?) and doc.asset_file? if doc.respond_to?(:id) if $processed_urls.include? doc.id return end $processed_urls << doc.id end doc.output = process_content(site_hostname, doc.output, anchor_contents) end end