jekyll-archives-v2 0.0.4 → 0.0.5
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 +4 -4
- data/lib/jekyll-archives-v2/archive.rb +10 -9
- data/lib/jekyll-archives-v2/version.rb +1 -1
- data/lib/jekyll-archives-v2.rb +41 -43
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15b2cbfcb29db985353dfc2cb88a5bd929ddf784c331691063b1fef417df64e0
|
4
|
+
data.tar.gz: 63db4dad501c3635617a16454fabffd46f6f224e16c73397f3ef99eb7ec9afef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3d2057979dd61d811f0ee56781c1738d7e358dea5ac330aad36ccfe18aa12d3d422f4aafbc5dab0c09a3b9a9a0b39108cd93b4e9a280a597ede206aa15f0e6d
|
7
|
+
data.tar.gz: 173ed82625589a008da46fb43d5613a0422b8817f275966e9017bcfd1d3b2ee7ecc3204135a5e19ef850dbbeb025711763bb28b8a8d7eebd5bd8dc3194fa34f4
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'active_support/inflector'
|
2
3
|
|
3
4
|
module Jekyll
|
4
5
|
module ArchivesV2
|
@@ -20,12 +21,12 @@ module Jekyll
|
|
20
21
|
|
21
22
|
# Initialize a new Archive page
|
22
23
|
#
|
23
|
-
# site
|
24
|
-
# title
|
25
|
-
#
|
26
|
-
# type
|
24
|
+
# site - The Site object.
|
25
|
+
# title - The name of the tag/category or a Hash of the year/month/day in case of date.
|
26
|
+
# e.g. { :year => 2014, :month => 08 } or "my-category" or "my-tag".
|
27
|
+
# type - The type of archive. Can be one of "year", "month", "day", "category", or "tag"
|
27
28
|
# collection_name - The name of the collection.
|
28
|
-
# documents
|
29
|
+
# documents - The array of documents that belong in this archive.
|
29
30
|
def initialize(site, title, type, collection_name, documents)
|
30
31
|
@site = site
|
31
32
|
@documents = documents
|
@@ -48,9 +49,9 @@ module Jekyll
|
|
48
49
|
|
49
50
|
# The template of the permalink.
|
50
51
|
#
|
51
|
-
# Returns the template String.
|
52
|
+
# Returns the template String as defined in config, else returns default template.
|
52
53
|
def template
|
53
|
-
@config.dig("permalinks", type)
|
54
|
+
@config.dig("permalinks", type) || "/:collection/:type/:name/"
|
54
55
|
end
|
55
56
|
|
56
57
|
# The layout to use for rendering
|
@@ -64,9 +65,9 @@ module Jekyll
|
|
64
65
|
# desired placeholder replacements. For details see "url.rb".
|
65
66
|
def url_placeholders
|
66
67
|
if @title.is_a? Hash
|
67
|
-
@title.merge(:collection => @collection_name, :type => @type)
|
68
|
+
@title.merge(:collection => @collection_name, :type => @type.singularize)
|
68
69
|
else
|
69
|
-
{ :collection => @collection_name, :name => @slug, :type => @type }
|
70
|
+
{ :collection => @collection_name, :name => @slug, :type => @type.singularize }
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
data/lib/jekyll-archives-v2.rb
CHANGED
@@ -19,11 +19,10 @@ module Jekyll
|
|
19
19
|
"layout" => "archive",
|
20
20
|
"enabled" => [],
|
21
21
|
"permalinks" => {
|
22
|
-
"year" => "
|
23
|
-
"month" => "
|
24
|
-
"day" => "
|
25
|
-
"
|
26
|
-
"category" => "/#{name}/category/:name/",
|
22
|
+
"year" => "/:collection/:year/",
|
23
|
+
"month" => "/:collection/:year/:month/",
|
24
|
+
"day" => "/:collection/:year/:month/:day/",
|
25
|
+
"tags" => "/:collection/:type/:name/",
|
27
26
|
},
|
28
27
|
}
|
29
28
|
end
|
@@ -57,55 +56,54 @@ module Jekyll
|
|
57
56
|
end
|
58
57
|
|
59
58
|
# Read archive data from collection
|
60
|
-
def read(
|
61
|
-
if enabled?(
|
62
|
-
|
63
|
-
|
59
|
+
def read(collection)
|
60
|
+
if @config[collection]["enabled"].is_a?(Array)
|
61
|
+
if enabled?(collection, "year") || enabled?(collection, "month") || enabled?(collection, "day")
|
62
|
+
read_dates(collection)
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
end
|
65
|
+
# read all attributes that are not year, month, or day
|
66
|
+
attributes = @config[collection]["enabled"].select { |attr| !["year", "month", "day"].include?(attr) }
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
attributes.each do |attr|
|
69
|
+
read_attrs(collection, attr)
|
70
|
+
end
|
71
|
+
|
72
|
+
elsif @config[collection]["enabled"] == true || @config[collection]["enabled"] == "all"
|
73
|
+
read_dates(collection)
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
# create a list of all attributes
|
76
|
+
attributes = @collections[collection].docs.flat_map { |doc| doc.data.keys }.uniq
|
77
|
+
# discard any attribute that is not an array
|
78
|
+
attributes.reject! { |attr| @collections[collection].docs.all? { |doc| !doc.data[attr].is_a?(Array) } }
|
79
|
+
|
80
|
+
attributes.each do |attr|
|
81
|
+
read_attrs(collection, attr)
|
82
|
+
end
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
80
|
-
def
|
81
|
-
|
82
|
-
@archives << Archive.new(@site, title,
|
86
|
+
def read_attrs(collection, attr)
|
87
|
+
doc_attr_hash(@collections[collection], attr).each do |title, documents|
|
88
|
+
@archives << Archive.new(@site, title, attr, collection, documents)
|
83
89
|
end
|
84
90
|
end
|
85
91
|
|
86
|
-
def read_dates(
|
87
|
-
years(@collections[
|
88
|
-
append_enabled_date_type({ :year => year }, "year",
|
92
|
+
def read_dates(collection)
|
93
|
+
years(@collections[collection]).each do |year, y_documents|
|
94
|
+
append_enabled_date_type({ :year => year }, "year", collection, y_documents)
|
89
95
|
months(y_documents).each do |month, m_documents|
|
90
|
-
append_enabled_date_type({ :year => year, :month => month }, "month",
|
96
|
+
append_enabled_date_type({ :year => year, :month => month }, "month", collection, m_documents)
|
91
97
|
days(m_documents).each do |day, d_documents|
|
92
|
-
append_enabled_date_type({ :year => year, :month => month, :day => day }, "day",
|
98
|
+
append_enabled_date_type({ :year => year, :month => month, :day => day }, "day", collection, d_documents)
|
93
99
|
end
|
94
100
|
end
|
95
101
|
end
|
96
102
|
end
|
97
103
|
|
98
104
|
# Checks if archive type is enabled in config
|
99
|
-
def enabled?(
|
100
|
-
@config[
|
101
|
-
end
|
102
|
-
|
103
|
-
def tags(documents)
|
104
|
-
doc_attr_hash(documents, "tags")
|
105
|
-
end
|
106
|
-
|
107
|
-
def categories(documents)
|
108
|
-
doc_attr_hash(documents, "categories")
|
105
|
+
def enabled?(collection, archive)
|
106
|
+
@config[collection]["enabled"] == true || @config[collection]["enabled"] == "all" || (@config[collection]["enabled"].is_a?(Array) && @config[collection]["enabled"].include?(archive))
|
109
107
|
end
|
110
108
|
|
111
109
|
# Custom `post_attr_hash` method for years
|
@@ -128,12 +126,12 @@ module Jekyll
|
|
128
126
|
# Initialize a new Archive page and append to base array if the associated date `type`
|
129
127
|
# has been enabled by configuration.
|
130
128
|
#
|
131
|
-
# meta
|
132
|
-
# type
|
133
|
-
#
|
134
|
-
# documents
|
135
|
-
def append_enabled_date_type(meta, type,
|
136
|
-
@archives << Archive.new(@site, meta, type,
|
129
|
+
# meta - A Hash of the year / month / day as applicable for date.
|
130
|
+
# type - The type of date archive.
|
131
|
+
# collection - the name of the collection
|
132
|
+
# documents - The array of documents that belong in the date archive.
|
133
|
+
def append_enabled_date_type(meta, type, collection, documents)
|
134
|
+
@archives << Archive.new(@site, meta, type, collection, documents) if enabled?(collection, type)
|
137
135
|
end
|
138
136
|
|
139
137
|
# Custom `post_attr_hash` for date type archives.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-archives-v2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Corrêa de Araújo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: bundler
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|