Back to listRuby
Jekyll - Custom Plugin
Lv.51048@mukitaro7 playsDec 31, 2025
Jekyll plugin with custom Liquid tag and page generator for static site customization.
preview.ruby
1module Jekyll2 class ReadingTimeTag < Liquid::Tag3 WORDS_PER_MINUTE = 2004 5 def initialize(tag_name, text, tokens)6 super7 @text = text.strip8 end9 10 def render(context)11 content = context[@text] || context.registers[:page]['content']12 words = content.split.size13 minutes = (words / WORDS_PER_MINUTE.to_f).ceil14 "#{minutes} min read"15 end16 end17 18 class CategoryPageGenerator < Generator19 safe true20 priority :low21 22 def generate(site)23 site.categories.each do |category, posts|24 site.pages << CategoryPage.new(site, category, posts)25 end26 end27 end28 29 class CategoryPage < Page30 def initialize(site, category, posts)31 @site = site32 @base = site.source33 @dir = "categories/#{category.downcase}"34 @name = 'index.html'35 36 process(@name)37 read_yaml(File.join(@base, '_layouts'), 'category.html')38 data['category'] = category39 data['posts'] = posts40 end41 end42end43 44Liquid::Template.register_tag('reading_time', Jekyll::ReadingTimeTag)Custom problems are not included in rankings