jekyll-archives 2.1.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +21 -0
- data/lib/jekyll-archives/archive.rb +46 -29
- data/lib/jekyll-archives/page_drop.rb +14 -0
- data/lib/jekyll-archives/version.rb +7 -0
- data/lib/jekyll-archives.rb +64 -55
- metadata +14 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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.
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Jekyll
|
2
4
|
module Archives
|
3
5
|
class Archive < Jekyll::Page
|
4
|
-
|
5
6
|
attr_accessor :posts, :type, :slug
|
6
7
|
|
7
8
|
# Attributes for Liquid templates
|
@@ -13,6 +14,7 @@ module Jekyll
|
|
13
14
|
name
|
14
15
|
path
|
15
16
|
url
|
17
|
+
permalink
|
16
18
|
).freeze
|
17
19
|
|
18
20
|
# Initialize a new Archive page
|
@@ -27,12 +29,8 @@ module Jekyll
|
|
27
29
|
@posts = posts
|
28
30
|
@type = type
|
29
31
|
@title = title
|
30
|
-
@config = site.config[
|
31
|
-
|
32
|
-
# Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb)
|
33
|
-
if title.to_s.length
|
34
|
-
@slug = Utils.slugify(title.to_s)
|
35
|
-
end
|
32
|
+
@config = site.config["jekyll-archives"]
|
33
|
+
@slug = slugify_string_title
|
36
34
|
|
37
35
|
# Use ".html" for file extension and url for path
|
38
36
|
@ext = File.extname(relative_path)
|
@@ -40,7 +38,7 @@ module Jekyll
|
|
40
38
|
@name = File.basename(relative_path, @ext)
|
41
39
|
|
42
40
|
@data = {
|
43
|
-
"layout" => layout
|
41
|
+
"layout" => layout,
|
44
42
|
}
|
45
43
|
@content = ""
|
46
44
|
end
|
@@ -49,25 +47,21 @@ module Jekyll
|
|
49
47
|
#
|
50
48
|
# Returns the template String.
|
51
49
|
def template
|
52
|
-
@config
|
50
|
+
@config.dig("permalinks", type)
|
53
51
|
end
|
54
52
|
|
55
53
|
# The layout to use for rendering
|
56
54
|
#
|
57
55
|
# Returns the layout as a String
|
58
56
|
def layout
|
59
|
-
|
60
|
-
@config['layouts'][type]
|
61
|
-
else
|
62
|
-
@config['layout']
|
63
|
-
end
|
57
|
+
@config.dig("layouts", type) || @config["layout"]
|
64
58
|
end
|
65
59
|
|
66
60
|
# Returns a hash of URL placeholder names (as symbols) mapping to the
|
67
61
|
# desired placeholder replacements. For details see "url.rb".
|
68
62
|
def url_placeholders
|
69
63
|
if @title.is_a? Hash
|
70
|
-
@title.merge(
|
64
|
+
@title.merge(:type => @type)
|
71
65
|
else
|
72
66
|
{ :name => @slug, :type => @type }
|
73
67
|
end
|
@@ -77,13 +71,17 @@ module Jekyll
|
|
77
71
|
#
|
78
72
|
# Returns the String url.
|
79
73
|
def url
|
80
|
-
@url ||= URL.new(
|
81
|
-
:template
|
74
|
+
@url ||= URL.new(
|
75
|
+
:template => template,
|
82
76
|
:placeholders => url_placeholders,
|
83
|
-
:permalink
|
84
|
-
|
77
|
+
:permalink => nil
|
78
|
+
).to_s
|
85
79
|
rescue ArgumentError
|
86
|
-
raise ArgumentError
|
80
|
+
raise ArgumentError, "Template #{template.inspect} provided is invalid."
|
81
|
+
end
|
82
|
+
|
83
|
+
def permalink
|
84
|
+
data.is_a?(Hash) && data["permalink"]
|
87
85
|
end
|
88
86
|
|
89
87
|
# Produce a title object suitable for Liquid based on type of archive.
|
@@ -91,17 +89,17 @@ module Jekyll
|
|
91
89
|
# Returns a String (for tag and category archives) and nil for
|
92
90
|
# date-based archives.
|
93
91
|
def title
|
94
|
-
if @title.is_a?
|
95
|
-
@title
|
96
|
-
end
|
92
|
+
@title if @title.is_a?(String)
|
97
93
|
end
|
98
94
|
|
99
95
|
# Produce a date object if a date-based archive
|
100
96
|
#
|
101
97
|
# Returns a Date.
|
102
98
|
def date
|
103
|
-
|
104
|
-
|
99
|
+
return unless @title.is_a?(Hash)
|
100
|
+
|
101
|
+
@date ||= begin
|
102
|
+
args = @title.values.map(&:to_i)
|
105
103
|
Date.new(*args)
|
106
104
|
end
|
107
105
|
end
|
@@ -110,14 +108,33 @@ module Jekyll
|
|
110
108
|
#
|
111
109
|
# Returns the destination relative path String.
|
112
110
|
def relative_path
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
116
116
|
end
|
117
117
|
|
118
118
|
# Returns the object as a debug String.
|
119
119
|
def inspect
|
120
|
-
"#<Jekyll:Archive @type=#{@type
|
120
|
+
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
|
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"])
|
121
138
|
end
|
122
139
|
end
|
123
140
|
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
@@ -1,48 +1,49 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
2
4
|
|
3
5
|
module Jekyll
|
4
6
|
module Archives
|
5
7
|
# Internal requires
|
6
|
-
autoload :Archive,
|
7
|
-
autoload :
|
8
|
-
|
9
|
-
if (Jekyll.const_defined? :Hooks)
|
10
|
-
Jekyll::Hooks.register :site, :after_reset do |site|
|
11
|
-
# We need to disable incremental regen for Archives to generate with the
|
12
|
-
# correct content
|
13
|
-
site.regenerator.instance_variable_set(:@disabled, true)
|
14
|
-
end
|
15
|
-
end
|
8
|
+
autoload :Archive, "jekyll-archives/archive"
|
9
|
+
autoload :PageDrop, "jekyll-archives/page_drop"
|
10
|
+
autoload :VERSION, "jekyll-archives/version"
|
16
11
|
|
17
12
|
class Archives < Jekyll::Generator
|
18
13
|
safe true
|
19
14
|
|
20
15
|
DEFAULTS = {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
def initialize(config =
|
33
|
-
|
34
|
-
|
16
|
+
"layout" => "archive",
|
17
|
+
"enabled" => [],
|
18
|
+
"permalinks" => {
|
19
|
+
"year" => "/:year/",
|
20
|
+
"month" => "/:year/:month/",
|
21
|
+
"day" => "/:year/:month/:day/",
|
22
|
+
"tag" => "/tag/:name/",
|
23
|
+
"category" => "/category/:name/",
|
24
|
+
},
|
25
|
+
}.freeze
|
26
|
+
|
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)
|
35
31
|
else
|
36
|
-
@config =
|
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."
|
37
35
|
end
|
36
|
+
@enabled = @config && @config["enabled"]
|
38
37
|
end
|
39
38
|
|
40
39
|
def generate(site)
|
40
|
+
return if @config.nil?
|
41
|
+
|
41
42
|
@site = site
|
42
43
|
@posts = site.posts
|
43
44
|
@archives = []
|
44
45
|
|
45
|
-
@site.config[
|
46
|
+
@site.config["jekyll-archives"] = @config
|
46
47
|
|
47
48
|
read
|
48
49
|
@site.pages.concat(@archives)
|
@@ -74,12 +75,12 @@ module Jekyll
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def read_dates
|
77
|
-
years.each do |year,
|
78
|
-
|
79
|
-
months(
|
80
|
-
|
81
|
-
days(
|
82
|
-
|
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)
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
@@ -87,44 +88,52 @@ module Jekyll
|
|
87
88
|
|
88
89
|
# Checks if archive type is enabled in config
|
89
90
|
def enabled?(archive)
|
90
|
-
@
|
91
|
-
@config["enabled"].include? archive
|
92
|
-
end
|
91
|
+
@enabled == true || @enabled == "all" || (@enabled.is_a?(Array) && @enabled.include?(archive))
|
93
92
|
end
|
94
93
|
|
95
94
|
def tags
|
96
|
-
@site.
|
95
|
+
@site.tags
|
97
96
|
end
|
98
97
|
|
99
98
|
def categories
|
100
|
-
@site.
|
99
|
+
@site.categories
|
101
100
|
end
|
102
101
|
|
103
102
|
# Custom `post_attr_hash` method for years
|
104
103
|
def years
|
105
|
-
|
106
|
-
|
107
|
-
# In Jekyll 3, Collection#each should be called on the #docs array directly.
|
108
|
-
if Jekyll::VERSION >= '3.0.0'
|
109
|
-
@posts.docs.each { |p| hash[p.date.strftime("%Y")] << p }
|
110
|
-
else
|
111
|
-
@posts.each { |p| hash[p.date.strftime("%Y")] << p }
|
112
|
-
end
|
113
|
-
hash.values.each { |posts| posts.sort!.reverse! }
|
114
|
-
hash
|
104
|
+
date_attr_hash(@posts.docs, "%Y")
|
115
105
|
end
|
116
106
|
|
107
|
+
# Custom `post_attr_hash` method for months
|
117
108
|
def months(year_posts)
|
118
|
-
|
119
|
-
year_posts.each { |p| hash[p.date.strftime("%m")] << p }
|
120
|
-
hash.values.each { |posts| posts.sort!.reverse! }
|
121
|
-
hash
|
109
|
+
date_attr_hash(year_posts, "%m")
|
122
110
|
end
|
123
111
|
|
112
|
+
# Custom `post_attr_hash` method for days
|
124
113
|
def days(month_posts)
|
125
|
-
|
126
|
-
|
127
|
-
|
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! }
|
128
137
|
hash
|
129
138
|
end
|
130
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
|
@@ -16,78 +16,31 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
19
|
+
version: '3.6'
|
20
|
+
- - "<"
|
25
21
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rdoc
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: shoulda
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
63
24
|
prerelease: false
|
64
25
|
version_requirements: !ruby/object:Gem::Requirement
|
65
26
|
requirements:
|
66
27
|
- - ">="
|
67
28
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
-
-
|
70
|
-
name: minitest
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
29
|
+
version: '3.6'
|
30
|
+
- - "<"
|
81
31
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
32
|
+
version: '5.0'
|
83
33
|
description: Automatically generate post archives by dates, tags, and categories.
|
84
34
|
email:
|
85
35
|
executables: []
|
86
36
|
extensions: []
|
87
37
|
extra_rdoc_files: []
|
88
38
|
files:
|
39
|
+
- LICENSE
|
89
40
|
- lib/jekyll-archives.rb
|
90
41
|
- lib/jekyll-archives/archive.rb
|
42
|
+
- lib/jekyll-archives/page_drop.rb
|
43
|
+
- lib/jekyll-archives/version.rb
|
91
44
|
homepage: https://github.com/jekyll/jekyll-archives
|
92
45
|
licenses:
|
93
46
|
- MIT
|
@@ -100,15 +53,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
53
|
requirements:
|
101
54
|
- - ">="
|
102
55
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
56
|
+
version: 2.7.0
|
104
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
58
|
requirements:
|
106
59
|
- - ">="
|
107
60
|
- !ruby/object:Gem::Version
|
108
61
|
version: '0'
|
109
62
|
requirements: []
|
110
|
-
|
111
|
-
rubygems_version: 2.5.1
|
63
|
+
rubygems_version: 3.1.6
|
112
64
|
signing_key:
|
113
65
|
specification_version: 4
|
114
66
|
summary: Post archives for Jekyll.
|