jekyll-archives-v2 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a627d116dccfd0c16c031b21c4e61817912e414a300f586e103dc9fb84499412
4
- data.tar.gz: b73d608cc75bc0b00e7af2cb525575f7a400d6514c2dc9d9c9ee7dec29e0da31
3
+ metadata.gz: 15b2cbfcb29db985353dfc2cb88a5bd929ddf784c331691063b1fef417df64e0
4
+ data.tar.gz: 63db4dad501c3635617a16454fabffd46f6f224e16c73397f3ef99eb7ec9afef
5
5
  SHA512:
6
- metadata.gz: 706f4b9f3e3bfaf8d381535020b702d044ec34fd449b4b5710cfb2c7f18524ad8c810bcbb1abcfc2f8aa1c75cc49620b09416a31b0b0a64658984cab8f57bad6
7
- data.tar.gz: 33536cb6a931eacbac78123a4d905ec05a8171d884703cf59692fc7cd5196d66f60948fb10f97acc7ec218add4f4918d1f158289e47aacc6d2978e1191e4aaa3
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 - The Site object.
24
- # title - The name of the tag/category or a Hash of the year/month/day in case of date.
25
- # e.g. { :year => 2014, :month => 08 } or "my-category" or "my-tag".
26
- # type - The type of archive. Can be one of "year", "month", "day", "category", or "tag"
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 - The array of documents that belong in this archive.
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module ArchivesV2
5
- VERSION = "0.0.4"
5
+ VERSION = "0.0.5"
6
6
  end
7
7
  end
@@ -19,11 +19,10 @@ module Jekyll
19
19
  "layout" => "archive",
20
20
  "enabled" => [],
21
21
  "permalinks" => {
22
- "year" => "/#{name}/:year/",
23
- "month" => "/#{name}/:year/:month/",
24
- "day" => "/#{name}/:year/:month/:day/",
25
- "tag" => "/#{name}/tag/:name/",
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(collection_name)
61
- if enabled?(collection_name, "tags")
62
- read_tags(collection_name)
63
- end
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
- if enabled?(collection_name, "categories")
66
- read_categories(collection_name)
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
- if enabled?(collection_name, "year") || enabled?(collection_name, "month") || enabled?(collection_name, "day")
70
- read_dates(collection_name)
71
- end
72
- end
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
- def read_tags(collection_name)
75
- tags(@collections[collection_name]).each do |title, documents|
76
- @archives << Archive.new(@site, title, "tag", collection_name, documents)
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 read_categories(collection_name)
81
- categories(@collections[collection_name]).each do |title, documents|
82
- @archives << Archive.new(@site, title, "category", collection_name, documents)
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(collection_name)
87
- years(@collections[collection_name]).each do |year, y_documents|
88
- append_enabled_date_type({ :year => year }, "year", collection_name, y_documents)
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", collection_name, m_documents)
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", collection_name, d_documents)
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?(collection_name, archive)
100
- @config[collection_name]["enabled"] == true || @config[collection_name]["enabled"] == "all" || (@config[collection_name]["enabled"].is_a?(Array) && @config[collection_name]["enabled"].include?(archive))
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 - A Hash of the year / month / day as applicable for date.
132
- # type - The type of date archive.
133
- # collection_name - the name of the collection
134
- # documents - The array of documents that belong in the date archive.
135
- def append_enabled_date_type(meta, type, collection_name, documents)
136
- @archives << Archive.new(@site, meta, type, collection_name, documents) if enabled?(collection_name, 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
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-30 00:00:00.000000000 Z
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