Class: JekyllShorts::Generator
- Inherits:
-
Jekyll::Generator
- Object
- Jekyll::Generator
- JekyllShorts::Generator
- Defined in:
- lib/jekyll-shorts/generator.rb
Overview
Pages generator.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Defined Under Namespace
Classes: ShortFile
Instance Method Summary collapse
-
#generate(site) ⇒ Object
Main plugin action, called by Jekyll-core.
Instance Method Details
#generate(site) ⇒ Object
Main plugin action, called by Jekyll-core
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/jekyll-shorts/generator.rb', line 42 def generate(site) Jekyll.logger.info("jekyll-shorts #{JekyllShorts::VERSION} starting...") config ||= site.config['shorts'] || {} permalink ||= config['permalink'] || ':year:month:day' start = Time.now total = 0 site.posts.docs.sort_by(&:url).each_with_index do |doc, pos| long = doc.url short = Jekyll::URL.new( template: permalink, placeholders: { 'Y' => doc.date.year.to_s, 'y' => doc.date.year.to_s[2..], 'm' => doc.date.month.to_s.rjust(2, '0'), 'd' => doc.date.day.to_s.rjust(2, '0'), 'pos' => pos.to_s } ).to_s site.static_files << ShortFile.new(site, short, long) doc.data['short-url'] = short total += 1 end Jekyll.logger.info("jekyll-shorts #{JekyllShorts::VERSION}: \ #{total} link(s) generated in #{(Time.now - start).round(2)}s") end |