# Title: Jekyll Archive Page // changed by GK # Downloaded 2018-02-08 last changed DirtyF committed on Feb 01, 2018 # Original Authors: DirtyF : @DirtyF # # Description: Automatically generate post archives by dates, tags, and categories. # # Download: https://github.com/jekyll/jekyll-archives # # Sample Config # jekyll-archives: # layout: hc-archive # category: # - account-settings # - deployment # permalinks: # category: '/hc-category/:name/' # # See the documentation for full configuration and usage instructions. # frozen_string_literal: true require "jekyll" module Jekyll module Archives # Internal requires # autoload :Archive, "jekyll-archives/archive" # autoload :VERSION, "jekyll-plugin-gkarchive/version" class Archives < Jekyll::Generator safe true DEFAULTS = { "layout" => "archive", "categories" => [], "permalinks" => { "category" => "/category/:name/", }, }.freeze def initialize(config = nil) @config = Utils.deep_merge_hashes(DEFAULTS, config.fetch("jekyll-archives", {})) end def generate(site) @site = site #@posts = site.posts site.collections.each do |coll_name, coll_data| if( !coll_data.nil? && coll_name == 'articles') @posts = coll_data end end @archives = [] @site.config["jekyll-archives"] = @config read_categories @site.pages.concat(@archives) @site.config["archives"] = @archives end def read_categories posts = [] @posts.docs.each do |key, value| posts << key end @config["category"].each { |cat| @archives << Archive.new(@site, cat, "category", posts) } end end end end