jekyll-archives-2.2.1/0000755000004100000410000000000013567316764014662 5ustar www-datawww-datajekyll-archives-2.2.1/jekyll-archives.gemspec0000644000004100000410000000456713567316764021337 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: jekyll-archives 2.2.1 ruby lib Gem::Specification.new do |s| s.name = "jekyll-archives".freeze s.version = "2.2.1" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Alfred Xing".freeze] s.date = "2019-03-23" s.description = "Automatically generate post archives by dates, tags, and categories.".freeze s.files = ["lib/jekyll-archives.rb".freeze, "lib/jekyll-archives/archive.rb".freeze, "lib/jekyll-archives/version.rb".freeze] s.homepage = "https://github.com/jekyll/jekyll-archives".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 2.3.0".freeze) s.rubygems_version = "2.5.2.1".freeze s.summary = "Post archives for Jekyll.".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q.freeze, [">= 0"]) s.add_runtime_dependency(%q.freeze, ["< 5.0", ">= 3.6"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, ["~> 0.9"]) s.add_development_dependency(%q.freeze, [">= 0"]) else s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["< 5.0", ">= 3.6"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["~> 0.9"]) s.add_dependency(%q.freeze, [">= 0"]) end else s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["< 5.0", ">= 3.6"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["~> 0.9"]) s.add_dependency(%q.freeze, [">= 0"]) end end jekyll-archives-2.2.1/lib/0000755000004100000410000000000013567316764015430 5ustar www-datawww-datajekyll-archives-2.2.1/lib/jekyll-archives.rb0000644000004100000410000000666313567316764021064 0ustar www-datawww-data# frozen_string_literal: true require "jekyll" module Jekyll module Archives # Internal requires autoload :Archive, "jekyll-archives/archive" autoload :VERSION, "jekyll-archives/version" class Archives < Jekyll::Generator safe true DEFAULTS = { "layout" => "archive", "enabled" => [], "permalinks" => { "year" => "/:year/", "month" => "/:year/:month/", "day" => "/:year/:month/:day/", "tag" => "/tag/:name/", "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 @archives = [] @site.config["jekyll-archives"] = @config read @site.pages.concat(@archives) @site.config["archives"] = @archives end # Read archive data from posts def read read_tags read_categories read_dates end def read_tags if enabled? "tags" tags.each do |title, posts| @archives << Archive.new(@site, title, "tag", posts) end end end def read_categories if enabled? "categories" categories.each do |title, posts| @archives << Archive.new(@site, title, "category", posts) end end end def read_dates years.each do |year, posts| @archives << Archive.new(@site, { :year => year }, "year", posts) if enabled? "year" months(posts).each do |month, posts| @archives << Archive.new(@site, { :year => year, :month => month }, "month", posts) if enabled? "month" days(posts).each do |day, posts| @archives << Archive.new(@site, { :year => year, :month => month, :day => day }, "day", posts) if enabled? "day" end end end end # Checks if archive type is enabled in config def enabled?(archive) @config["enabled"] == true || @config["enabled"] == "all" || if @config["enabled"].is_a? Array @config["enabled"].include? archive end end def tags @site.post_attr_hash("tags") end def categories @site.post_attr_hash("categories") end # Custom `post_attr_hash` method for years def years hash = Hash.new { |h, key| h[key] = [] } # In Jekyll 3, Collection#each should be called on the #docs array directly. if Jekyll::VERSION >= "3.0.0" @posts.docs.each { |p| hash[p.date.strftime("%Y")] << p } else @posts.each { |p| hash[p.date.strftime("%Y")] << p } end hash.each_value { |posts| posts.sort!.reverse! } hash end def months(year_posts) hash = Hash.new { |h, key| h[key] = [] } year_posts.each { |p| hash[p.date.strftime("%m")] << p } hash.each_value { |posts| posts.sort!.reverse! } hash end def days(month_posts) hash = Hash.new { |h, key| h[key] = [] } month_posts.each { |p| hash[p.date.strftime("%d")] << p } hash.each_value { |posts| posts.sort!.reverse! } hash end end end end jekyll-archives-2.2.1/lib/jekyll-archives/0000755000004100000410000000000013567316764020524 5ustar www-datawww-datajekyll-archives-2.2.1/lib/jekyll-archives/version.rb0000644000004100000410000000013713567316764022537 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module Archives VERSION = "2.2.1" end end jekyll-archives-2.2.1/lib/jekyll-archives/archive.rb0000644000004100000410000000670713567316764022504 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module Archives class Archive < Jekyll::Page attr_accessor :posts, :type, :slug # Attributes for Liquid templates ATTRIBUTES_FOR_LIQUID = %w( posts type title date name path url permalink ).freeze # Initialize a new Archive page # # site - The Site object. # title - The name of the tag/category or a Hash of the year/month/day in case of date. # e.g. { :year => 2014, :month => 08 } or "my-category" or "my-tag". # type - The type of archive. Can be one of "year", "month", "day", "category", or "tag" # posts - The array of posts that belong in this archive. def initialize(site, title, type, posts) @site = site @posts = posts @type = type @title = title @config = site.config["jekyll-archives"] # Generate slug if tag or category # (taken from jekyll/jekyll/features/support/env.rb) @slug = Utils.slugify(title) if title.is_a? String # Use ".html" for file extension and url for path @ext = File.extname(relative_path) @path = relative_path @name = File.basename(relative_path, @ext) @data = { "layout" => layout, } @content = "" end # The template of the permalink. # # Returns the template String. def template @config["permalinks"][type] end # The layout to use for rendering # # Returns the layout as a String def layout if @config["layouts"] && @config["layouts"][type] @config["layouts"][type] else @config["layout"] end end # Returns a hash of URL placeholder names (as symbols) mapping to the # desired placeholder replacements. For details see "url.rb". def url_placeholders if @title.is_a? Hash @title.merge(:type => @type) else { :name => @slug, :type => @type } end end # The generated relative url of this page. e.g. /about.html. # # Returns the String url. def url @url ||= URL.new( :template => template, :placeholders => url_placeholders, :permalink => nil ).to_s rescue ArgumentError raise ArgumentError, "Template \"#{template}\" provided is invalid." end def permalink data&.is_a?(Hash) && data["permalink"] end # Produce a title object suitable for Liquid based on type of archive. # # Returns a String (for tag and category archives) and nil for # date-based archives. def title @title if @title.is_a? String end # Produce a date object if a date-based archive # # Returns a Date. def date if @title.is_a? Hash args = @title.values.map(&:to_i) Date.new(*args) end end # Obtain the write path relative to the destination directory # # Returns the destination relative path String. def relative_path path = URL.unescape_path(url).gsub(%r!^\/!, "") path = File.join(path, "index.html") if url =~ %r!\/$! path end # Returns the object as a debug String. def inspect "#" end end end end