sutty-archives 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/jekyll-archives.rb +179 -0
- data/lib/jekyll-archives/archive.rb +161 -0
- data/lib/jekyll-archives/version.rb +7 -0
- data/lib/sutty-archives.rb +3 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de531ca1b1088e2b311d795bb399e76d4d472c13b146b4c87d711d0ff7f30612
|
4
|
+
data.tar.gz: 465b830b25c64e795503d591012e37268059265a1fb16b0d6d1d289fdf40dfae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4cd9ad72c38bf0a4fccad60781a6d2d161e42754d7e98262d15ca037e8c125ac3cfd3f312b2f58f52a0cb3b3e2a2a1f1cdfccf881180d9dd689238b154ec25ef
|
7
|
+
data.tar.gz: 82dc16f23c07788f6c69e592e3045a3d49f03987a556694825b005a9c0e7b66d3e9a203eeb73baf2d70287ec69dc44097a82b600f004d993a282ebb6cb926a5b
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Archives
|
7
|
+
# Internal requires
|
8
|
+
autoload :Archive, "jekyll-archives/archive"
|
9
|
+
autoload :VERSION, "jekyll-archives/version"
|
10
|
+
|
11
|
+
class Archives < Jekyll::Generator
|
12
|
+
safe true
|
13
|
+
|
14
|
+
DATE_ATTRS = %w[year month day].freeze
|
15
|
+
# Map between the front matter attribute and names used by
|
16
|
+
# jekyll-archive
|
17
|
+
LEGACY_ATTRS = { 'tags' => 'tag', 'categories' => 'category' }.freeze
|
18
|
+
|
19
|
+
DEFAULTS = {
|
20
|
+
"layout" => "archive",
|
21
|
+
"enabled" => [],
|
22
|
+
"permalinks" => {
|
23
|
+
"year" => "/:year/",
|
24
|
+
"month" => "/:year/:month/",
|
25
|
+
"day" => "/:year/:month/:day/",
|
26
|
+
"tag" => "/tag/:name/",
|
27
|
+
"category" => "/category/:name/",
|
28
|
+
"category-tag" => "/category/:category/tag/:tag/"
|
29
|
+
},
|
30
|
+
}.freeze
|
31
|
+
|
32
|
+
def initialize(config = {})
|
33
|
+
archives_config = config.fetch("jekyll-archives", {})
|
34
|
+
if archives_config.is_a?(Hash)
|
35
|
+
@config = Utils.deep_merge_hashes(DEFAULTS, archives_config)
|
36
|
+
else
|
37
|
+
@config = nil
|
38
|
+
Jekyll.logger.warn "Archives:", "Expected a hash but got #{archives_config.inspect}"
|
39
|
+
Jekyll.logger.warn "", "Archives will not be generated for this site."
|
40
|
+
end
|
41
|
+
@enabled = @config && @config["enabled"]
|
42
|
+
@post_attr_hash = {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate(site)
|
46
|
+
return if @config.nil?
|
47
|
+
|
48
|
+
@site = site
|
49
|
+
@posts = site.posts
|
50
|
+
@archives = []
|
51
|
+
|
52
|
+
@site.config["jekyll-archives"] = @config
|
53
|
+
|
54
|
+
read
|
55
|
+
@site.pages.concat(@archives)
|
56
|
+
|
57
|
+
@site.config["archives"] = @archives
|
58
|
+
end
|
59
|
+
|
60
|
+
# Read archive data from posts
|
61
|
+
def read
|
62
|
+
read_attrs
|
63
|
+
read_categories_tags
|
64
|
+
read_dates
|
65
|
+
end
|
66
|
+
|
67
|
+
# Read and group by attributes, using the legacy names when
|
68
|
+
# needed.
|
69
|
+
def read_attrs
|
70
|
+
attrs.each do |attr|
|
71
|
+
post_attr_hash(attr).each do |title, posts|
|
72
|
+
attr = LEGACY_ATTRS[attr] if LEGACY_ATTRS[attr]
|
73
|
+
|
74
|
+
@archives << Archive.new(@site, title, attr, posts)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def read_categories_tags
|
80
|
+
if enabled? "categories-tags"
|
81
|
+
categories.each do |category, posts|
|
82
|
+
posts.map { |post| post.data['tags'] }.flatten.uniq.compact.each do |tag|
|
83
|
+
category_tag_posts = posts.select do |post|
|
84
|
+
post.data['categories'].include?(category) &&
|
85
|
+
post.data['tags'].include?(tag)
|
86
|
+
end
|
87
|
+
|
88
|
+
@archives << Archive.new(@site, { category: category, tag: tag }, "category-tag", category_tag_posts)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def read_dates
|
95
|
+
years.each do |year, y_posts|
|
96
|
+
append_enabled_date_type({ :year => year }, "year", y_posts)
|
97
|
+
months(y_posts).each do |month, m_posts|
|
98
|
+
append_enabled_date_type({ :year => year, :month => month }, "month", m_posts)
|
99
|
+
days(m_posts).each do |day, d_posts|
|
100
|
+
append_enabled_date_type({ :year => year, :month => month, :day => day }, "day", d_posts)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Return the front matter attributes to archive by, using the
|
107
|
+
# legacy names unless specified and leaving out the date
|
108
|
+
# attributes.
|
109
|
+
def attrs
|
110
|
+
return LEGACY_ATTRS.keys unless @enabled.is_a? Array
|
111
|
+
|
112
|
+
@attrs ||= @enabled - DATE_ATTRS
|
113
|
+
end
|
114
|
+
|
115
|
+
# Checks if archive type is enabled in config
|
116
|
+
def enabled?(archive)
|
117
|
+
@enabled == true || @enabled == "all" || (@enabled.is_a?(Array) && @enabled.include?(archive))
|
118
|
+
end
|
119
|
+
|
120
|
+
# Custom `post_attr_hash` method for years
|
121
|
+
def years
|
122
|
+
date_attr_hash(@posts.docs, "%Y")
|
123
|
+
end
|
124
|
+
|
125
|
+
# Custom `post_attr_hash` method for months
|
126
|
+
def months(year_posts)
|
127
|
+
date_attr_hash(year_posts, "%m")
|
128
|
+
end
|
129
|
+
|
130
|
+
# Custom `post_attr_hash` method for days
|
131
|
+
def days(month_posts)
|
132
|
+
date_attr_hash(month_posts, "%d")
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
# Initialize a new Archive page and append to base array if the associated date `type`
|
138
|
+
# has been enabled by configuration.
|
139
|
+
#
|
140
|
+
# meta - A Hash of the year / month / day as applicable for date.
|
141
|
+
# type - The type of date archive.
|
142
|
+
# posts - The array of posts that belong in the date archive.
|
143
|
+
def append_enabled_date_type(meta, type, posts)
|
144
|
+
@archives << Archive.new(@site, meta, type, posts) if enabled?(type)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Custom `post_attr_hash` for date type archives.
|
148
|
+
#
|
149
|
+
# posts - Array of posts to be considered for archiving.
|
150
|
+
# id - String used to format post date via `Time.strptime` e.g. %Y, %m, etc.
|
151
|
+
def date_attr_hash(posts, id)
|
152
|
+
hash = Hash.new { |hsh, key| hsh[key] = [] }
|
153
|
+
posts.each { |post| hash[post.date.strftime(id)] << post }
|
154
|
+
hash.each_value { |posts| posts.sort!.reverse! }
|
155
|
+
hash
|
156
|
+
end
|
157
|
+
|
158
|
+
# Custom `post_attr_hash` to group by any attribute
|
159
|
+
def post_attr_hash(post_attr)
|
160
|
+
@post_attr_hash[post_attr] ||= begin
|
161
|
+
hash = Hash.new { |h, key| h[key] = [] }
|
162
|
+
@site.posts.docs.each do |p|
|
163
|
+
d = p.data[post_attr]
|
164
|
+
|
165
|
+
next if d.nil?
|
166
|
+
|
167
|
+
if d.respond_to? :each
|
168
|
+
d.each { |t| hash[t] << p }
|
169
|
+
else
|
170
|
+
hash[d.to_s] << p
|
171
|
+
end
|
172
|
+
end
|
173
|
+
hash.each_value { |posts| posts.sort!.reverse! }
|
174
|
+
hash
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Archives
|
5
|
+
class Archive < Jekyll::Page
|
6
|
+
attr_accessor :posts, :type, :slug
|
7
|
+
|
8
|
+
# Attributes for Liquid templates
|
9
|
+
ATTRIBUTES_FOR_LIQUID = %w(
|
10
|
+
posts
|
11
|
+
type
|
12
|
+
title
|
13
|
+
date
|
14
|
+
name
|
15
|
+
path
|
16
|
+
url
|
17
|
+
permalink
|
18
|
+
slug
|
19
|
+
category
|
20
|
+
tag
|
21
|
+
).freeze
|
22
|
+
|
23
|
+
# Initialize a new Archive page
|
24
|
+
#
|
25
|
+
# site - The Site object.
|
26
|
+
# title - The name of the tag/category or a Hash of the year/month/day in case of date.
|
27
|
+
# e.g. { :year => 2014, :month => 08 } or "my-category" or "my-tag".
|
28
|
+
# type - The type of archive. Can be one of "year", "month", "day", "category", or "tag"
|
29
|
+
# posts - The array of posts that belong in this archive.
|
30
|
+
def initialize(site, title, type, posts)
|
31
|
+
@site = site
|
32
|
+
@posts = posts
|
33
|
+
@type = type
|
34
|
+
@title = title
|
35
|
+
@config = site.config["jekyll-archives"]
|
36
|
+
@slug = slugify_string_title
|
37
|
+
|
38
|
+
# Use ".html" for file extension and url for path
|
39
|
+
@ext = File.extname(relative_path)
|
40
|
+
@path = relative_path
|
41
|
+
@name = File.basename(relative_path, @ext)
|
42
|
+
|
43
|
+
@data = {
|
44
|
+
"layout" => layout,
|
45
|
+
}
|
46
|
+
@content = ""
|
47
|
+
end
|
48
|
+
|
49
|
+
# The template of the permalink.
|
50
|
+
#
|
51
|
+
# Returns the template String.
|
52
|
+
def template
|
53
|
+
@config.dig("permalinks", type) || "/#{type}/:name/"
|
54
|
+
end
|
55
|
+
|
56
|
+
# The layout to use for rendering
|
57
|
+
#
|
58
|
+
# Returns the layout as a String
|
59
|
+
def layout
|
60
|
+
@config.dig("layouts", type) || @config["layout"]
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns a hash of URL placeholder names (as symbols) mapping to the
|
64
|
+
# desired placeholder replacements. For details see "url.rb".
|
65
|
+
def url_placeholders
|
66
|
+
if @title.is_a? Hash
|
67
|
+
placeholders = @title.merge(:type => @type)
|
68
|
+
|
69
|
+
if @type == 'category-tag'
|
70
|
+
%i[category tag].each do |k|
|
71
|
+
placeholders[k] = Utils.slugify(@title[k], mode: @config.dig('slug'))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
placeholders
|
76
|
+
else
|
77
|
+
{ :name => @slug, :type => @type }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# The generated relative url of this page. e.g. /about.html.
|
82
|
+
#
|
83
|
+
# Returns the String url.
|
84
|
+
def url
|
85
|
+
@url ||= URL.new(
|
86
|
+
:template => template,
|
87
|
+
:placeholders => url_placeholders,
|
88
|
+
:permalink => nil
|
89
|
+
).to_s
|
90
|
+
rescue ArgumentError
|
91
|
+
raise ArgumentError, "Template \"#{template}\" provided is invalid."
|
92
|
+
end
|
93
|
+
|
94
|
+
def permalink
|
95
|
+
data&.is_a?(Hash) && data["permalink"]
|
96
|
+
end
|
97
|
+
|
98
|
+
# Produce a title object suitable for Liquid based on type of archive.
|
99
|
+
#
|
100
|
+
# Returns a String (for tag and category archives) and nil for
|
101
|
+
# date-based archives.
|
102
|
+
def title
|
103
|
+
if @title.is_a? String
|
104
|
+
@title
|
105
|
+
elsif @type == 'category-tag'
|
106
|
+
@title.values.join(@config.fetch('separator', ' / '))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Produce a date object if a date-based archive
|
111
|
+
#
|
112
|
+
# Returns a Date.
|
113
|
+
def date
|
114
|
+
return unless @title.is_a?(Hash)
|
115
|
+
|
116
|
+
@date ||= begin
|
117
|
+
args = @title.values.map(&:to_i)
|
118
|
+
Date.new(*args)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def category
|
123
|
+
@title[:category] if @title.is_a? Hash
|
124
|
+
end
|
125
|
+
|
126
|
+
def tag
|
127
|
+
@title[:tag] if @title.is_a? Hash
|
128
|
+
end
|
129
|
+
|
130
|
+
# Obtain the write path relative to the destination directory
|
131
|
+
#
|
132
|
+
# Returns the destination relative path String.
|
133
|
+
def relative_path
|
134
|
+
@relative_path ||= begin
|
135
|
+
path = URL.unescape_path(url).gsub(%r!^/!, "")
|
136
|
+
path = File.join(path, "index.html") if url.end_with?("/")
|
137
|
+
path
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Returns the object as a debug String.
|
142
|
+
def inspect
|
143
|
+
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
# Generate slug if @title attribute is a string.
|
149
|
+
#
|
150
|
+
# Note: mode other than those expected by Jekyll returns the given string after
|
151
|
+
# downcasing it.
|
152
|
+
def slugify_string_title
|
153
|
+
return unless title.is_a?(String)
|
154
|
+
|
155
|
+
mode = @config["slug_mode"] || @config["slug"]
|
156
|
+
|
157
|
+
Utils.slugify(title, :mode => mode)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sutty-archives
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alfred Xing
|
8
|
+
- f
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jekyll
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.6'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '5.0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '3.6'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bundler
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: minitest
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rdoc
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: rubocop-jekyll
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.9'
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: shoulda
|
106
|
+
requirement: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
description: Automatically generate post archives by dates, and any front matter attribute.
|
119
|
+
email:
|
120
|
+
executables: []
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- lib/jekyll-archives.rb
|
125
|
+
- lib/jekyll-archives/archive.rb
|
126
|
+
- lib/jekyll-archives/version.rb
|
127
|
+
- lib/sutty-archives.rb
|
128
|
+
homepage: https://0xacab.org/sutty/jekyll/sutty-archives
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 2.3.0
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubygems_version: 3.0.3
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Post archives for Jekyll. Fork of jekyll-archives.
|
151
|
+
test_files: []
|