jekyll-archives-2.3.0/0000755000004100000410000000000014742147671014655 5ustar www-datawww-datajekyll-archives-2.3.0/lib/0000755000004100000410000000000014742147671015423 5ustar www-datawww-datajekyll-archives-2.3.0/lib/jekyll-archives/0000755000004100000410000000000014742147671020517 5ustar www-datawww-datajekyll-archives-2.3.0/lib/jekyll-archives/page_drop.rb0000644000004100000410000000047314742147671023010 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module Archives class PageDrop < Jekyll::Drops::Drop extend Forwardable mutable false def_delegators :@obj, :posts, :type, :title, :date, :name, :path, :url, :permalink private def_delegator :@obj, :data, :fallback_data end end end jekyll-archives-2.3.0/lib/jekyll-archives/archive.rb0000644000004100000410000000745414742147671022477 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"] @slug = slugify_string_title # 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.dig("permalinks", type) end # The layout to use for rendering # # Returns the layout as a String def layout @config.dig("layouts", type) || @config["layout"] 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.inspect} 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 return unless @title.is_a?(Hash) @date ||= begin 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 @relative_path ||= begin path = URL.unescape_path(url).gsub(%r!^/!, "") path = File.join(path, "index.html") if url.end_with?("/") path end end # Returns the object as a debug String. def inspect "#" end # The Liquid representation of this page. def to_liquid @to_liquid ||= Jekyll::Archives::PageDrop.new(self) end private # Generate slug if @title attribute is a string. # # Note: mode other than those expected by Jekyll returns the given string after # downcasing it. def slugify_string_title return unless title.is_a?(String) Utils.slugify(title, :mode => @config["slug_mode"]) end end end end jekyll-archives-2.3.0/lib/jekyll-archives/version.rb0000644000004100000410000000013714742147671022532 0ustar www-datawww-data# frozen_string_literal: true module Jekyll module Archives VERSION = "2.3.0" end end jekyll-archives-2.3.0/lib/jekyll-archives.rb0000644000004100000410000000775214742147671021057 0ustar www-datawww-data# frozen_string_literal: true require "jekyll" module Jekyll module Archives # Internal requires autoload :Archive, "jekyll-archives/archive" autoload :PageDrop, "jekyll-archives/page_drop" 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 = {}) archives_config = config.fetch("jekyll-archives", {}) if archives_config.is_a?(Hash) @config = Utils.deep_merge_hashes(DEFAULTS, archives_config) else @config = nil Jekyll.logger.warn "Archives:", "Expected a hash but got #{archives_config.inspect}" Jekyll.logger.warn "", "Archives will not be generated for this site." end @enabled = @config && @config["enabled"] end def generate(site) return if @config.nil? @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, y_posts| append_enabled_date_type({ :year => year }, "year", y_posts) months(y_posts).each do |month, m_posts| append_enabled_date_type({ :year => year, :month => month }, "month", m_posts) days(m_posts).each do |day, d_posts| append_enabled_date_type({ :year => year, :month => month, :day => day }, "day", d_posts) end end end end # Checks if archive type is enabled in config def enabled?(archive) @enabled == true || @enabled == "all" || (@enabled.is_a?(Array) && @enabled.include?(archive)) end def tags @site.tags end def categories @site.categories end # Custom `post_attr_hash` method for years def years date_attr_hash(@posts.docs, "%Y") end # Custom `post_attr_hash` method for months def months(year_posts) date_attr_hash(year_posts, "%m") end # Custom `post_attr_hash` method for days def days(month_posts) date_attr_hash(month_posts, "%d") end private # Initialize a new Archive page and append to base array if the associated date `type` # has been enabled by configuration. # # meta - A Hash of the year / month / day as applicable for date. # type - The type of date archive. # posts - The array of posts that belong in the date archive. def append_enabled_date_type(meta, type, posts) @archives << Archive.new(@site, meta, type, posts) if enabled?(type) end # Custom `post_attr_hash` for date type archives. # # posts - Array of posts to be considered for archiving. # id - String used to format post date via `Time.strptime` e.g. %Y, %m, etc. def date_attr_hash(posts, id) hash = Hash.new { |hsh, key| hsh[key] = [] } posts.each { |post| hash[post.date.strftime(id)] << post } hash.each_value { |posts_in_hsh| posts_in_hsh.sort!.reverse! } hash end end end end jekyll-archives-2.3.0/jekyll-archives.gemspec0000644000004100000410000000251514742147671021321 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: jekyll-archives 2.3.0 ruby lib Gem::Specification.new do |s| s.name = "jekyll-archives".freeze s.version = "2.3.0" 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 = "2024-12-05" s.description = "Automatically generate post archives by dates, tags, and categories.".freeze s.files = ["LICENSE".freeze, "lib/jekyll-archives.rb".freeze, "lib/jekyll-archives/archive.rb".freeze, "lib/jekyll-archives/page_drop.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.7.0".freeze) s.rubygems_version = "3.3.15".freeze s.summary = "Post archives for Jekyll.".freeze if s.respond_to? :specification_version then s.specification_version = 4 end if s.respond_to? :add_runtime_dependency then s.add_runtime_dependency(%q.freeze, [">= 3.6", "< 5.0"]) else s.add_dependency(%q.freeze, [">= 3.6", "< 5.0"]) end end jekyll-archives-2.3.0/LICENSE0000644000004100000410000000214314742147671015662 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) 2014-present Alfred Xing and the jekyll-archives contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.