Back to list

Jekyll - Custom Plugin

Lv.51048@mukitaro7 playsDec 31, 2025

Jekyll plugin with custom Liquid tag and page generator for static site customization.

preview.ruby
Ruby
1module Jekyll
2 class ReadingTimeTag < Liquid::Tag
3 WORDS_PER_MINUTE = 200
4
5 def initialize(tag_name, text, tokens)
6 super
7 @text = text.strip
8 end
9
10 def render(context)
11 content = context[@text] || context.registers[:page]['content']
12 words = content.split.size
13 minutes = (words / WORDS_PER_MINUTE.to_f).ceil
14 "#{minutes} min read"
15 end
16 end
17
18 class CategoryPageGenerator < Generator
19 safe true
20 priority :low
21
22 def generate(site)
23 site.categories.each do |category, posts|
24 site.pages << CategoryPage.new(site, category, posts)
25 end
26 end
27 end
28
29 class CategoryPage < Page
30 def initialize(site, category, posts)
31 @site = site
32 @base = site.source
33 @dir = "categories/#{category.downcase}"
34 @name = 'index.html'
35
36 process(@name)
37 read_yaml(File.join(@base, '_layouts'), 'category.html')
38 data['category'] = category
39 data['posts'] = posts
40 end
41 end
42end
43
44Liquid::Template.register_tag('reading_time', Jekyll::ReadingTimeTag)

Custom problems are not included in rankings