Class: Jekyll::UJReadtimeTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/tags/readtime.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ UJReadtimeTag

Returns a new instance of UJReadtimeTag.



6
7
8
9
# File 'lib/tags/readtime.rb', line 6

def initialize(tag_name, markup, tokens)
  super
  @markup = markup.strip
end

Instance Method Details

#render(context) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tags/readtime.rb', line 11

def render(context)
  # Get the content to analyze
  content = resolve_content(context)
  return '1' unless content
  
  # Strip HTML tags
  stripped_content = strip_html(content)
  
  # Count words
  words = count_words(stripped_content)
  
  # Calculate readtime (200 words per minute, minimum 1 minute)
  readtime = (words / 200.0).ceil
  readtime = 1 if readtime < 1
  
  readtime.to_s
end