jekyll-archives 2.2.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/lib/jekyll-archives/archive.rb +31 -17
- data/lib/jekyll-archives/page_drop.rb +14 -0
- data/lib/jekyll-archives/version.rb +1 -1
- data/lib/jekyll-archives.rb +51 -32
- metadata +6 -88
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50b7b8aebac240d8301566358280400e017127a035a5d31ab4e7eea412b17199
|
4
|
+
data.tar.gz: e2443238bbb35443bf37bfce255492ba035ab3d46d54a6be7dcf5cab28548a2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f001b57c44f9ccc6f4664695b7159c0961e2bc4c202343c9ab25e11b1484d529547277937d38023254be55f4dc231b595d4e0ad274c61d189e5607ab2b9d40d5
|
7
|
+
data.tar.gz: 2e49eb77fa4803b0407f23940de2139c0e2929f5fef86d6785a501f5dbbf44837c6bc62a6eddcea22ed6250fa3e501d4a87c55f9d2af0ab8c4dc2a553aff7585
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014-present Alfred Xing and the jekyll-archives contributors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -30,10 +30,7 @@ module Jekyll
|
|
30
30
|
@type = type
|
31
31
|
@title = title
|
32
32
|
@config = site.config["jekyll-archives"]
|
33
|
-
|
34
|
-
# Generate slug if tag or category
|
35
|
-
# (taken from jekyll/jekyll/features/support/env.rb)
|
36
|
-
@slug = Utils.slugify(title) if title.is_a? String
|
33
|
+
@slug = slugify_string_title
|
37
34
|
|
38
35
|
# Use ".html" for file extension and url for path
|
39
36
|
@ext = File.extname(relative_path)
|
@@ -50,18 +47,14 @@ module Jekyll
|
|
50
47
|
#
|
51
48
|
# Returns the template String.
|
52
49
|
def template
|
53
|
-
@config
|
50
|
+
@config.dig("permalinks", type)
|
54
51
|
end
|
55
52
|
|
56
53
|
# The layout to use for rendering
|
57
54
|
#
|
58
55
|
# Returns the layout as a String
|
59
56
|
def layout
|
60
|
-
|
61
|
-
@config["layouts"][type]
|
62
|
-
else
|
63
|
-
@config["layout"]
|
64
|
-
end
|
57
|
+
@config.dig("layouts", type) || @config["layout"]
|
65
58
|
end
|
66
59
|
|
67
60
|
# Returns a hash of URL placeholder names (as symbols) mapping to the
|
@@ -84,11 +77,11 @@ module Jekyll
|
|
84
77
|
:permalink => nil
|
85
78
|
).to_s
|
86
79
|
rescue ArgumentError
|
87
|
-
raise ArgumentError, "Template
|
80
|
+
raise ArgumentError, "Template #{template.inspect} provided is invalid."
|
88
81
|
end
|
89
82
|
|
90
83
|
def permalink
|
91
|
-
data
|
84
|
+
data.is_a?(Hash) && data["permalink"]
|
92
85
|
end
|
93
86
|
|
94
87
|
# Produce a title object suitable for Liquid based on type of archive.
|
@@ -96,14 +89,16 @@ module Jekyll
|
|
96
89
|
# Returns a String (for tag and category archives) and nil for
|
97
90
|
# date-based archives.
|
98
91
|
def title
|
99
|
-
@title if @title.is_a?
|
92
|
+
@title if @title.is_a?(String)
|
100
93
|
end
|
101
94
|
|
102
95
|
# Produce a date object if a date-based archive
|
103
96
|
#
|
104
97
|
# Returns a Date.
|
105
98
|
def date
|
106
|
-
|
99
|
+
return unless @title.is_a?(Hash)
|
100
|
+
|
101
|
+
@date ||= begin
|
107
102
|
args = @title.values.map(&:to_i)
|
108
103
|
Date.new(*args)
|
109
104
|
end
|
@@ -113,15 +108,34 @@ module Jekyll
|
|
113
108
|
#
|
114
109
|
# Returns the destination relative path String.
|
115
110
|
def relative_path
|
116
|
-
|
117
|
-
|
118
|
-
|
111
|
+
@relative_path ||= begin
|
112
|
+
path = URL.unescape_path(url).gsub(%r!^/!, "")
|
113
|
+
path = File.join(path, "index.html") if url.end_with?("/")
|
114
|
+
path
|
115
|
+
end
|
119
116
|
end
|
120
117
|
|
121
118
|
# Returns the object as a debug String.
|
122
119
|
def inspect
|
123
120
|
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
|
124
121
|
end
|
122
|
+
|
123
|
+
# The Liquid representation of this page.
|
124
|
+
def to_liquid
|
125
|
+
@to_liquid ||= Jekyll::Archives::PageDrop.new(self)
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
# Generate slug if @title attribute is a string.
|
131
|
+
#
|
132
|
+
# Note: mode other than those expected by Jekyll returns the given string after
|
133
|
+
# downcasing it.
|
134
|
+
def slugify_string_title
|
135
|
+
return unless title.is_a?(String)
|
136
|
+
|
137
|
+
Utils.slugify(title, :mode => @config["slug_mode"])
|
138
|
+
end
|
125
139
|
end
|
126
140
|
end
|
127
141
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Archives
|
5
|
+
class PageDrop < Jekyll::Drops::Drop
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
mutable false
|
9
|
+
|
10
|
+
def_delegators :@obj, :posts, :type, :title, :date, :name, :path, :url, :permalink
|
11
|
+
private def_delegator :@obj, :data, :fallback_data
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/jekyll-archives.rb
CHANGED
@@ -5,8 +5,9 @@ require "jekyll"
|
|
5
5
|
module Jekyll
|
6
6
|
module Archives
|
7
7
|
# Internal requires
|
8
|
-
autoload :Archive,
|
9
|
-
autoload :
|
8
|
+
autoload :Archive, "jekyll-archives/archive"
|
9
|
+
autoload :PageDrop, "jekyll-archives/page_drop"
|
10
|
+
autoload :VERSION, "jekyll-archives/version"
|
10
11
|
|
11
12
|
class Archives < Jekyll::Generator
|
12
13
|
safe true
|
@@ -23,11 +24,21 @@ module Jekyll
|
|
23
24
|
},
|
24
25
|
}.freeze
|
25
26
|
|
26
|
-
def initialize(config =
|
27
|
-
|
27
|
+
def initialize(config = {})
|
28
|
+
archives_config = config.fetch("jekyll-archives", {})
|
29
|
+
if archives_config.is_a?(Hash)
|
30
|
+
@config = Utils.deep_merge_hashes(DEFAULTS, archives_config)
|
31
|
+
else
|
32
|
+
@config = nil
|
33
|
+
Jekyll.logger.warn "Archives:", "Expected a hash but got #{archives_config.inspect}"
|
34
|
+
Jekyll.logger.warn "", "Archives will not be generated for this site."
|
35
|
+
end
|
36
|
+
@enabled = @config && @config["enabled"]
|
28
37
|
end
|
29
38
|
|
30
39
|
def generate(site)
|
40
|
+
return if @config.nil?
|
41
|
+
|
31
42
|
@site = site
|
32
43
|
@posts = site.posts
|
33
44
|
@archives = []
|
@@ -64,12 +75,12 @@ module Jekyll
|
|
64
75
|
end
|
65
76
|
|
66
77
|
def read_dates
|
67
|
-
years.each do |year,
|
68
|
-
|
69
|
-
months(
|
70
|
-
|
71
|
-
days(
|
72
|
-
|
78
|
+
years.each do |year, y_posts|
|
79
|
+
append_enabled_date_type({ :year => year }, "year", y_posts)
|
80
|
+
months(y_posts).each do |month, m_posts|
|
81
|
+
append_enabled_date_type({ :year => year, :month => month }, "month", m_posts)
|
82
|
+
days(m_posts).each do |day, d_posts|
|
83
|
+
append_enabled_date_type({ :year => year, :month => month, :day => day }, "day", d_posts)
|
73
84
|
end
|
74
85
|
end
|
75
86
|
end
|
@@ -77,44 +88,52 @@ module Jekyll
|
|
77
88
|
|
78
89
|
# Checks if archive type is enabled in config
|
79
90
|
def enabled?(archive)
|
80
|
-
@
|
81
|
-
@config["enabled"].include? archive
|
82
|
-
end
|
91
|
+
@enabled == true || @enabled == "all" || (@enabled.is_a?(Array) && @enabled.include?(archive))
|
83
92
|
end
|
84
93
|
|
85
94
|
def tags
|
86
|
-
@site.
|
95
|
+
@site.tags
|
87
96
|
end
|
88
97
|
|
89
98
|
def categories
|
90
|
-
@site.
|
99
|
+
@site.categories
|
91
100
|
end
|
92
101
|
|
93
102
|
# Custom `post_attr_hash` method for years
|
94
103
|
def years
|
95
|
-
|
96
|
-
|
97
|
-
# In Jekyll 3, Collection#each should be called on the #docs array directly.
|
98
|
-
if Jekyll::VERSION >= "3.0.0"
|
99
|
-
@posts.docs.each { |p| hash[p.date.strftime("%Y")] << p }
|
100
|
-
else
|
101
|
-
@posts.each { |p| hash[p.date.strftime("%Y")] << p }
|
102
|
-
end
|
103
|
-
hash.each_value { |posts| posts.sort!.reverse! }
|
104
|
-
hash
|
104
|
+
date_attr_hash(@posts.docs, "%Y")
|
105
105
|
end
|
106
106
|
|
107
|
+
# Custom `post_attr_hash` method for months
|
107
108
|
def months(year_posts)
|
108
|
-
|
109
|
-
year_posts.each { |p| hash[p.date.strftime("%m")] << p }
|
110
|
-
hash.each_value { |posts| posts.sort!.reverse! }
|
111
|
-
hash
|
109
|
+
date_attr_hash(year_posts, "%m")
|
112
110
|
end
|
113
111
|
|
112
|
+
# Custom `post_attr_hash` method for days
|
114
113
|
def days(month_posts)
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
date_attr_hash(month_posts, "%d")
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
# Initialize a new Archive page and append to base array if the associated date `type`
|
120
|
+
# has been enabled by configuration.
|
121
|
+
#
|
122
|
+
# meta - A Hash of the year / month / day as applicable for date.
|
123
|
+
# type - The type of date archive.
|
124
|
+
# posts - The array of posts that belong in the date archive.
|
125
|
+
def append_enabled_date_type(meta, type, posts)
|
126
|
+
@archives << Archive.new(@site, meta, type, posts) if enabled?(type)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Custom `post_attr_hash` for date type archives.
|
130
|
+
#
|
131
|
+
# posts - Array of posts to be considered for archiving.
|
132
|
+
# id - String used to format post date via `Time.strptime` e.g. %Y, %m, etc.
|
133
|
+
def date_attr_hash(posts, id)
|
134
|
+
hash = Hash.new { |hsh, key| hsh[key] = [] }
|
135
|
+
posts.each { |post| hash[post.date.strftime(id)] << post }
|
136
|
+
hash.each_value { |posts_in_hsh| posts_in_hsh.sort!.reverse! }
|
118
137
|
hash
|
119
138
|
end
|
120
139
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-archives
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alfred Xing
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -30,98 +30,16 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5.0'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: bundler
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - ">="
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '0'
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: minitest
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: rake
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: rdoc
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: rubocop-jekyll
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '0.9'
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '0.9'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: shoulda
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - ">="
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - ">="
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '0'
|
117
33
|
description: Automatically generate post archives by dates, tags, and categories.
|
118
34
|
email:
|
119
35
|
executables: []
|
120
36
|
extensions: []
|
121
37
|
extra_rdoc_files: []
|
122
38
|
files:
|
39
|
+
- LICENSE
|
123
40
|
- lib/jekyll-archives.rb
|
124
41
|
- lib/jekyll-archives/archive.rb
|
42
|
+
- lib/jekyll-archives/page_drop.rb
|
125
43
|
- lib/jekyll-archives/version.rb
|
126
44
|
homepage: https://github.com/jekyll/jekyll-archives
|
127
45
|
licenses:
|
@@ -135,14 +53,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
53
|
requirements:
|
136
54
|
- - ">="
|
137
55
|
- !ruby/object:Gem::Version
|
138
|
-
version: 2.
|
56
|
+
version: 2.7.0
|
139
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
58
|
requirements:
|
141
59
|
- - ">="
|
142
60
|
- !ruby/object:Gem::Version
|
143
61
|
version: '0'
|
144
62
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
63
|
+
rubygems_version: 3.1.6
|
146
64
|
signing_key:
|
147
65
|
specification_version: 4
|
148
66
|
summary: Post archives for Jekyll.
|