Class: CategoryIndexGenerator::CategoryGenerator
- Inherits:
-
Jekyll::Generator
- Object
- Jekyll::Generator
- CategoryIndexGenerator::CategoryGenerator
- Defined in:
- lib/category_index_generator.rb
Overview
Creates an index page for each catagory, plus a main index, all within a directory called _site/categories.
Instance Method Summary collapse
-
#generate(site) ⇒ Object
Only generates content in development mode rubocop:disable Style/StringConcatenation, Metrics/AbcSize.
Instance Method Details
#generate(site) ⇒ Object
Only generates content in development mode rubocop:disable Style/StringConcatenation, Metrics/AbcSize
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/category_index_generator.rb', line 9 def generate(site) # This plugin is disabled unless _config.yml contains an entry for category_generator_enable and the value is not false return if site.config['category_generator_enable'] return if site.config['env']['JEKYLL_ENV'] == 'production' index = Jekyll::PageWithoutAFile.new(site, site.source, 'categories', 'index.html') index.data['layout'] = 'default' index.data['title'] = 'Post Categories' index.content = '<p>' site.categories.each do |category, posts| new_page = Jekyll::PageWithoutAFile.new(site, site.source, 'categories', "#{category}.html") new_page.data['layout'] = 'default' new_page.data['title'] = "Category #{category} Posts" new_page.content = '<p>' + posts.map do |post| "<a href='#{post.url}'>#{post.data['title']}</a><br>" end.join("\n") + "</p>\n" site.pages << new_page index.content += "<a href='#{category}.html'>#{category}</a><br>\n" end index.content += '</p>' site.pages << index end |