From 639fece16245dac8c24277cc1ce2f1321f683920 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 24 Jan 2025 21:53:46 +0100 Subject: clean up ruby code --- _plugins/toc.rb | 92 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 45 insertions(+), 47 deletions(-) (limited to '_plugins/toc.rb') diff --git a/_plugins/toc.rb b/_plugins/toc.rb index 80acc82..09ef946 100644 --- a/_plugins/toc.rb +++ b/_plugins/toc.rb @@ -1,64 +1,62 @@ require 'nokogiri' -module Jekyll - class TOC < Liquid::Tag - def render context - # load HTML into nokogiri - html = context.registers[:page]['content'] - doc = Nokogiri::HTML(html) - - # enumerate over all h1-4 headings - @els = doc.css("h1, h2, h3, h4") - toc = output_toc() - return '' if toc.empty? - return '' % [ toc ] - end - - def output_toc - # empty toc (this check prevents crash) - return "" if @els.length == 0 +class TOC < Liquid::Tag + def render context + # load HTML into nokogiri + html = context.registers[:page]['content'] + doc = Nokogiri::HTML(html) + + # enumerate over all h1-4 headings + @els = doc.css("h1, h2, h3, h4") + toc = output_toc() + return '' if toc.empty? + return '' % [ toc ] + end - output = '' + + return output + end + + def el_level el + return Integer(el.name[1..]) end end -Liquid::Template.register_tag('toc', Jekyll::TOC) +Liquid::Template.register_tag('toc', TOC) -- cgit v1.2.3