Sha256: 1c876beef5ecf9f7f8f94ec82e416f7b24a8b1d3e3cadd3ec2bdbf4cd16d99ed

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

# 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-plugin-gkarchive/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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-plugin-gkarchive-0.5.0 lib/jekyll-plugin-gkarchive.rb