jekyll_plugin_support 3.0.0 → 3.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74f595dc019d923dbbad9e84b1eacdaa15808b36d54fc692044e30f26e0767f1
4
- data.tar.gz: 5632b03e8d9d29080ae0c43428d5c9a13243c4df529255013d63951d669a670d
3
+ metadata.gz: 89c80e46269ce8e9476f0758550b2d0acb48bd9462ffe0e6d957c436d1c98d2d
4
+ data.tar.gz: 920e92f0c86d0884193650af1039790df087edc158b529537d37c1fa1d04e680
5
5
  SHA512:
6
- metadata.gz: b5839393146e5d1ab2317f004a563bad4144467e506fd41516f489b065fa52d00bfcea4eedc7d8d06028afd35cba34b3360b19f4d968ec6a456e429f6a2af542
7
- data.tar.gz: 203f6111c4127b4909534d4dcc6b7dcb7f3f5d7bbf9fa60016920558a6eb9faed7cd736212b8c3f25cb52514e21b75035dd00ea55928525127b9ca662ede224d
6
+ metadata.gz: 1d0045d9f09b3b76c8306073d50c06b1f93fd4c7914a08ce24a826d75ffa033c84660710d8822ea25f18e5585cb94232e7634d68f7b4822aee311865768fc028
7
+ data.tar.gz: 779da912b97c957c69f8829265c7ad2ad213c6ccf286acae65d87e13a03c24d23e32eea85d22edd9c93aa4084f07732178325f9e7cb7bbb5484859b8e2f8ca79
data/.rubocop.yml CHANGED
@@ -48,9 +48,10 @@ Metrics/BlockLength:
48
48
  Metrics/ClassLength:
49
49
  Exclude:
50
50
  - "**/all_collections_tag.rb"
51
+ Max: 150
51
52
 
52
53
  Metrics/CyclomaticComplexity:
53
- Max: 25
54
+ Max: 35
54
55
 
55
56
  Metrics/MethodLength:
56
57
  Max: 50
@@ -60,7 +61,7 @@ Metrics/ModuleLength:
60
61
  - "**/jekyll_plugin_support_class.rb"
61
62
 
62
63
  Metrics/PerceivedComplexity:
63
- Max: 25
64
+ Max: 35
64
65
 
65
66
  Naming/FileName:
66
67
  Exclude:
@@ -70,6 +71,9 @@ Naming/FileName:
70
71
  RSpec/ExampleLength:
71
72
  Max: 30
72
73
 
74
+ RSpec/MultipleMemoizedHelpers:
75
+ Enabled: false
76
+
73
77
  RSpec/SpecFilePathFormat:
74
78
  Enabled: false
75
79
  IgnoreMethods: true
@@ -83,6 +87,13 @@ RSpec/IndexedLet:
83
87
  RSpec/MultipleExpectations:
84
88
  Max: 15
85
89
 
90
+ RSpec/MultipleDescribes:
91
+ Enabled: false
92
+
93
+ Security/Eval:
94
+ Exclude:
95
+ - spec/all_collections_tag/all_collections_tag_sort_spec.rb
96
+
86
97
  Style/ClassVars:
87
98
  Enabled: false
88
99
 
@@ -92,8 +103,16 @@ Style/Documentation:
92
103
  Style/FrozenStringLiteralComment:
93
104
  Enabled: false
94
105
 
106
+ Style/GlobalVars:
107
+ Exclude:
108
+ - spec/mslinn_binary_search_spec.rb
109
+
95
110
  Style/StringConcatenation:
96
111
  Enabled: false
97
112
 
113
+ Style/StringLiterals:
114
+ Exclude:
115
+ - spec/all_collections_tag/all_collections_tag_sort_spec.rb
116
+
98
117
  Style/TrailingCommaInHashLiteral:
99
118
  EnforcedStyleForMultiline: comma
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.1.1 / 2025-09-13
4
+
5
+ * Now looks up Windows environment variables (surrounded by `%` characters).
6
+ An error is generated for undefined variables.
7
+
8
+
9
+ ## 3.1.0 / 2025-06-10
10
+
11
+ * Added attribute `order` and method `field` to support `jekyll_outline`.
12
+ * Added another constructor for `AllCollectionsHooks::APage`, called `apage_from`.
13
+ * Added new method `new_attribute` to module `JekyllSupport`.
14
+ * The displayed date field (`:date` or `:last_modified`) now defaults to the primary sort field.
15
+ * Modified specs tests.
16
+ * Jekyll tag `AllCollectionsTag` now accepts an optional parameter called
17
+ `collection_name`, which filters the selected data source. A warning is logged
18
+ if the data source is anything but `all_collections`.
19
+ * Moved `APage` and its constructors to the `JekyllCollections` module.
20
+
21
+
3
22
  ## 3.0.0 / 2025-02-09
4
23
 
5
24
  * Numbered as v3.0.0 because `jekyll_draft` was at v2.1.0 and the two projects should have similar version numbers.
data/README.md CHANGED
@@ -64,9 +64,31 @@ Jekyll plugin tags created from `jekyll_plugin_support` framework automatically
64
64
 
65
65
  d. `sorted_lru_files` is used by a new binary search lookup for matching page suffixes.
66
66
  The `jekyll_href` and `jekyll_draft` plugins use this feature.
67
+ 17. A new Ruby class, `APage`, which abstracts all URL-addressable entities in a Jekyll website.
68
+ An `APage` can be constructed from a Jekyll `Document` or `Page`, a static file, and a Ruby hash.
69
+
70
+ `APage` instances can help immensely when automating content generation and reporting tasks.
67
71
 
68
72
  ## Installation
69
73
 
74
+ ### If You Need Windows Environment Variable Expansion
75
+
76
+ This only works if Jekyll is running on a Windows / WSL machine.
77
+ If you have a Mac, ignore the rest of this section, however be sure
78
+ not to try to include a file whose name contains two percent characters.
79
+
80
+ If a %WindowsStyleEnvironmentVariable% is detected in the `url` parameter,
81
+ `wslvar` is called.
82
+ If your WSL installation is old it might not have the `wslvar` command
83
+
84
+ The wslvar utility is part of the wslu package, a collection of useful utilities that come with WSL.
85
+ The most straightforward fix is to reinstall it.
86
+
87
+ ```shell
88
+ $ sudo apt update
89
+ $ sudo apt install wslu
90
+ ```
91
+
70
92
  ### For A Jekyll Website
71
93
 
72
94
  `Jekyll_plugin_support` is packaged as a Ruby gem.
@@ -76,7 +98,7 @@ add the following line to your Jekyll plugin’s `Gemfile`.
76
98
  ```ruby
77
99
  group :jekyll_plugins do
78
100
  # ...
79
- gem 'jekyll_plugin_support', '>= 1.1.0'
101
+ gem 'jekyll_plugin_support', '>= 3.1.0'
80
102
  # ...
81
103
  end
82
104
  ```
@@ -95,7 +117,7 @@ If your custom plugin will be packaged into a gem, add the following to your plu
95
117
  ```ruby
96
118
  Gem::Specification.new do |spec|
97
119
  # ...
98
- spec.add_dependency 'jekyll_plugin_support', '>= 1.1.0'
120
+ spec.add_dependency 'jekyll_plugin_support', '>= 3.1.0'
99
121
  # ...
100
122
  end
101
123
  ```
@@ -235,13 +257,28 @@ The general form of the Jekyll tag, including all options, is:
235
257
 
236
258
  ```html
237
259
  {% all_collections
260
+ collection_name='posts'
261
+ data_selector='all_collections'
238
262
  date_column='date|last_modified'
239
263
  heading='All Posts'
240
- id='asdf'
264
+ id='post_outline'
241
265
  sort_by='SORT_KEYS'
242
266
  %}
243
267
  ```
244
268
 
269
+ Each of these attributes are explained below.
270
+
271
+
272
+ #### `collection_name` Attribute
273
+
274
+ Name of the collection that this `APage` belongs to, or `nil`.
275
+
276
+
277
+ ##### `data_selector` Attribute
278
+
279
+ Name of the data collection to work from, defaults to `all_collections`.
280
+ Other allowable values are `all_documents` and `everything`.
281
+
245
282
 
246
283
  ##### `date_column` Attribute
247
284
 
@@ -1005,17 +1042,35 @@ The `site.all_collections`, `site.all_documents` and `site.everything` attribute
1005
1042
  consist of arrays of [`APage`](lib/hooks/a_page.rb) instances.
1006
1043
 
1007
1044
  The `APage` class has the following attributes:
1008
- `content` (HTML or Markdown), `data` (array), `date` (Ruby Date), `description`, `destination`,
1009
- `draft` (Boolean), `ext`, `href`, `label`, `last_modified` or `last_modified_at` (Ruby Date),
1010
- `layout`, `origin`, `path`, `relative_path`, `tags`, `title`, `type`, and `url`.
1011
1045
 
1046
+ * `content` (HTML or Markdown)
1047
+ * `collection_name`
1048
+ * `content` (HTML or Markdown)
1049
+ * `data` (array)
1050
+ * `date` (Ruby Date)
1051
+ * `description`
1052
+ * `destination`,
1053
+ * `draft` (Boolean)
1054
+ * `ext` / `extname`
1012
1055
  * `href` always starts with a slash.
1013
- This value is consistent with `a href` values in website HTML.
1056
+ This value is consistent with a `href` values in website HTML.
1014
1057
  Paths ending with a slash (`/`) have `index.html` appended so the path specifies an actual file.
1015
-
1058
+ * `label`
1059
+ * `last_modified` (Ruby Date)
1060
+ * `last_modified_field` indicates the name of the field that originally contained the value for
1061
+ `last_modified` (`last_modified` or `last_modified_at`)
1062
+ * `layout`
1063
+ * `logger` helpful for error handling
1064
+ * `name`
1016
1065
  * `origin` indicates the original source of the item.
1017
1066
  Possible values are `collection`, `individual_page` and `static_file`.
1018
1067
  Knowing the origin of each item allows code to process each type of item appropriately.
1068
+ * `path`
1069
+ * `relative_path`
1070
+ * `tags`
1071
+ * `title`
1072
+ * `type`
1073
+ * `url`
1019
1074
 
1020
1075
 
1021
1076
  ## `all_collections` Block Tag
@@ -1025,6 +1080,11 @@ The ordering is configurable; by default, the listing is sorted by `date`, newes
1025
1080
  The `all_collections` tag has a `data_source` parameter that specifies which new property to report on
1026
1081
  (`all_collections`, `all_documents`, or `everything`).
1027
1082
 
1083
+ For an example of how to use this Jekyll tag in conjunction with the
1084
+ [jekyll_outline](http://localhost:4001/jekyll_plugins/jekyll_outline.html) tag,
1085
+ see the [outline_tabs](http://localhost:4001/jekyll_plugins/jekyll_outline.html#outline_tabs)
1086
+ section of the jekyll_outline documentation.
1087
+
1028
1088
 
1029
1089
  ## Requirements
1030
1090
 
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.test_files = spec.files.grep %r{^(test|spec|features)/}
30
30
  spec.version = JekyllPluginSupportVersion::VERSION
31
31
 
32
+ spec.add_dependency 'bigdecimal'
32
33
  spec.add_dependency 'facets'
33
34
  spec.add_dependency 'jekyll', '>= 4.4.1'
34
35
  spec.add_dependency 'jekyll_plugin_logger'
@@ -45,7 +45,7 @@ module JekyllSupport
45
45
  # Method prescribed by the Jekyll plugin lifecycle.
46
46
  # Defines @config, @envs, @mode, @page and @site
47
47
  # @return [String]
48
- def render(liquid_context)
48
+ def render(liquid_context) # rubocop: disable Metrics/AbcSize
49
49
  @helper.liquid_context = ::JekyllSupport.inject_config_vars liquid_context # modifies liquid_context
50
50
  text = super # Liquid variable values in content are looked up and substituted
51
51
 
@@ -82,10 +82,11 @@ module JekyllSupport
82
82
  render_impl(text)
83
83
  rescue StandardError => e
84
84
  e.shorten_backtrace
85
+ @logger.error e.full_message
85
86
  file_name = e.backtrace[0]&.split(':')&.first
86
87
  in_file_name = "in '#{file_name}' " if file_name
87
88
  of_page = "of '#{@page['path']}'" if @page
88
- @logger.error { "#{e.class} on line #{@line_number} #{of_page} while processing #{tag_name} #{in_file_name}- #{e.message}" }
89
+ @logger.error { "While processing line #{@line_number} #{of_page} for #{tag_name} #{in_file_name}- #{e.message}" }
89
90
  binding.pry if @pry_on_standard_error # rubocop:disable Lint/Debugger
90
91
  raise e if @die_on_standard_error
91
92
 
@@ -12,7 +12,7 @@ module JekyllSupport
12
12
  rescue StandardError => e
13
13
  e.shorten_backtrace
14
14
  @logger.error { e.full_message }
15
- JekyllSupport.error_short_trace(@logger, e)
15
+ ::JekyllSupport.error_short_trace(@logger, e)
16
16
  end
17
17
 
18
18
  # Liquid::Block subclasses do not render if there is no content within the tag
@@ -42,11 +42,12 @@ module JekyllSupport
42
42
  END_MSG
43
43
  end
44
44
 
45
- def shorten_backtrace(backtrace_element_count = 3)
46
- b = backtrace[0..backtrace_element_count - 1].map do |x|
47
- x.gsub(Dir.pwd + '/', './')
48
- end
49
- set_backtrace b
45
+ def shorten_backtrace(backtrace_element_count = 6)
46
+ set_backtrace backtrace[0..backtrace_element_count]
47
+ # b = backtrace[0..backtrace_element_count - 1].map do |x|
48
+ # x.gsub(Dir.pwd + '/', './')
49
+ # end
50
+ # set_backtrace b
50
51
  end
51
52
  end
52
53
  end
@@ -5,10 +5,10 @@ require 'yaml'
5
5
  module JekyllSupport
6
6
  # Class methods for JekyllPluginHelper
7
7
  class JekyllPluginHelper
8
- # Expand an environment variable reference
8
+ # Expand an environment variable reference; first expand bash environment variables, then expand windows environment vars
9
9
  def self.expand_env(str, logger = nil, die_if_undefined: false)
10
- str&.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}/) do
11
- envar = Regexp.last_match(1)
10
+ x = str&.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}/) do
11
+ envar = Regexp.last_match 1
12
12
  unless ENV.key? envar
13
13
  msg = "jekyll_plugin_support error: environment variable #{envar} is undefined"
14
14
  raise JekyllPluginSupportError, msg.red, [] if die_if_undefined
@@ -21,6 +21,26 @@ module JekyllSupport
21
21
  end
22
22
  ENV.fetch(envar, nil)
23
23
  end
24
+ # Only expand %VAR% if x is not nil and contains a %
25
+ if x&.include?('%')
26
+ x.gsub(/%([a-zA-Z_][a-zA-Z0-9_]*)%|{\g<1>}/) do
27
+ envar = Regexp.last_match 1
28
+ value = `wslvar #{envar} &2> /dev/null`.chomp
29
+ unless value
30
+ msg = "jekyll_plugin_support error: Windows environment variable %#{envar}% is undefined"
31
+ raise JekyllPluginSupportError, msg.red, [] if die_if_undefined
32
+
33
+ if logger
34
+ logger.warn msg
35
+ else
36
+ puts msg.red
37
+ end
38
+ end
39
+ value
40
+ end
41
+ else
42
+ x
43
+ end
24
44
  end
25
45
 
26
46
  def self.generate_message(klass, tag_name, version)
data/lib/hooks/a_page.rb CHANGED
@@ -1,27 +1,138 @@
1
- module AllCollectionsHooks
1
+ require 'date'
2
+ require 'jekyll_draft'
3
+ require 'time'
4
+
5
+ module JekyllSupport
6
+ # Contructor for testing and jekyll_outline
7
+ def self.apage_from( # rubocop:disable Metrics/ParameterLists
8
+ collection_name: nil,
9
+ date: nil,
10
+ description: nil,
11
+ draft: false,
12
+ last_modified: nil,
13
+ logger: nil,
14
+ order: nil,
15
+ title: nil,
16
+ url: nil
17
+ )
18
+ # Jekyll documents have inconsistent date and last_modified property types.
19
+ date = Time.parse(date) if date.instance_of?(String)
20
+ unless date.instance_of? Time
21
+ logger.error { "date is not an instance of Time, it is an instance of #{date.class}" }
22
+ exit 2
23
+ end
24
+
25
+ last_modified = Date.parse(last_modified) if last_modified.instance_of?(String)
26
+ last_modified = Date.parse(date.strftime('%Y-%m-%d')) if last_modified.nil?
27
+ unless last_modified.instance_of? Date
28
+ logger.error { "last_modified is not an instance of Date, it is an instance of #{last_modified.class}" }
29
+ exit 3
30
+ end
31
+ last_modified = Date.parse(date._to_s) if last_modified.nil?
32
+ data = {
33
+ collection: { label: collection_name },
34
+ draft: draft,
35
+ last_modified: last_modified,
36
+ order: order,
37
+ title: title,
38
+ }
39
+ obj = {}
40
+ JekyllSupport.new_attribute obj, :data, data
41
+ JekyllSupport.new_attribute obj, :date, date
42
+ JekyllSupport.new_attribute obj, :description, description
43
+ JekyllSupport.new_attribute obj, :draft, draft
44
+ JekyllSupport.new_attribute obj, :extname, '.html'
45
+ JekyllSupport.new_attribute obj, :last_modified, last_modified
46
+ JekyllSupport.new_attribute obj, :logger, PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
47
+ JekyllSupport.new_attribute obj, :title, title
48
+ JekyllSupport.new_attribute obj, :url, url
49
+
50
+ JekyllSupport::APage.new obj, nil
51
+ rescue StandardError => e
52
+ puts e.full_message
53
+ end
54
+
55
+ # Create Array of JekyllSupport::APage from objects
56
+ # @param objects [Array] An array of Jekyll::Document, Jekyll::Page or file names
57
+ # @param origin [String] Indicates type of objects being passed
58
+ def self.apages_from_objects(objects, origin)
59
+ pages = []
60
+ objects.each do |object|
61
+ unless object.respond_to?(:logger)
62
+ JekyllSupport.new_attribute(object,
63
+ :logger,
64
+ PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config))
65
+ end
66
+ page = APage.new(object, origin)
67
+ pages << page unless page.data['exclude_from_all'] || page.path == 'redirect.html'
68
+ end
69
+ pages
70
+ end
71
+
72
+ # Defines a new attribute called `prop_name` in object `obj` and sets it to `prop_value`
73
+ def self.new_attribute(obj, prop_name, prop_value)
74
+ obj.class.module_eval { attr_accessor prop_name }
75
+ obj.instance_variable_set :"@#{prop_name}", prop_value
76
+ end
77
+
78
+ FIXNUM_MAX = (2**((0.size * 8) - 2)) - 1 unless defined? FIXNUM_MAX
79
+ END_OF_DAYS = 1_000_000_000_000 unless defined? END_OF_DAYS # One trillion years in the future
80
+ # Time.new is -4712-01-01
81
+
2
82
  class APage
3
- attr_reader :content, :data, :date, :description, :destination, :draft, :excerpt, :ext, :extname, :href,
4
- :label, :last_modified, :layout, :origin, :path, :relative_path, :tags, :title, :type, :url
83
+ attr_reader :categories, :collection_name, :content, :data, :date, :description, :destination, :draft,
84
+ :excerpt, :ext, :extname, :href, :label, :last_modified, :last_modified_field,
85
+ :layout, :logger, :name, :origin, :path, :relative_path, :tags, :title, :type, :url
5
86
 
87
+ # @param obj can be a `Jekyll::Document` or a Hash with properties
88
+ # @param origin values: 'collection', 'individual_page', and 'static_file'
89
+ # (See method JekyllSupport.apages_from_objects)
6
90
  def initialize(obj, origin)
91
+ @logger = obj.logger
7
92
  @origin = origin
8
- data_field_init obj
9
- obj_field_init obj
10
- @draft = Jekyll::Draft.draft? obj
11
- @href = @url if @href.nil?
12
- # @href = "/#{@href}" if @origin == 'individual_page'
13
- @href = "#{@href}index.html" if @href.end_with? '/'
14
- @name = File.basename(@href)
15
- @title = if @data&.key?('title')
16
- @data['title']
17
- elsif obj.respond_to?(:title)
18
- obj.title
19
- else
20
- "<code>#{@href}</code>"
21
- end
93
+ build obj
22
94
  rescue StandardError => e
23
- JekyllSupport.error_short_trace(@logger, e)
24
- # JekyllSupport.warn_short_trace(@logger, e)
95
+ ::JekyllSupport.error_short_trace(@logger, e)
96
+ end
97
+
98
+ # @param name can be either a String or a Symbol
99
+ def field(name, use_default: true)
100
+ default_value = case name
101
+ when :date, :last_modified, :last_modified_at
102
+ END_OF_DAYS
103
+ else
104
+ ''
105
+ end
106
+
107
+ result = data[name.to_sym] || data[name.to_s] if data.key?(name.to_sym) || data.key?(name.to_s)
108
+ return result if result
109
+
110
+ default_value if use_default
111
+ end
112
+
113
+ # Look within @data (if the property exists), then self for the given key as a symbol or a string
114
+ # @param key must be a symbol
115
+ # @return value of data[key] if key exists as a string or a symbol, else nil
116
+ def obj_field(obj, key)
117
+ if obj.respond_to? :data
118
+ return obj.data[key] if obj.data.key? key
119
+
120
+ return obj.data[key.to_s] if obj.data.key? key.to_s
121
+ end
122
+ return obj.send(key) if obj.respond_to?(key)
123
+
124
+ return unless obj.respond_to?(:key?)
125
+ return obj[key] if obj.key?(key)
126
+
127
+ obj[key.to_s] if obj.key?(key.to_s)
128
+ end
129
+
130
+ def order
131
+ if data.key?('order') || data.key?(:order)
132
+ data['order'] || data[:order]
133
+ else
134
+ FIXNUM_MAX
135
+ end
25
136
  end
26
137
 
27
138
  def to_s
@@ -30,40 +141,63 @@ module AllCollectionsHooks
30
141
 
31
142
  private
32
143
 
33
- def data_field_init(obj)
34
- return unless obj.respond_to? :data
35
-
36
- @data = obj.data
37
-
38
- @categories = @data['categories'] if @data.key? 'categories'
39
- @date = (@data['date'].to_date if @data&.key?('date')) || Date.today
40
- @description = @data['description'] if @data.key? 'description'
41
- @excerpt = @data['excerpt'] if @data.key? 'excerpt'
42
- @ext ||= @data['ext'] if @data.key? 'ext'
43
- @last_modified = @data['last_modified'] || @data['last_modified_at'] || @date
44
- @last_modified_field = case @data
45
- when @data.key?('last_modified')
46
- 'last_modified'
47
- when @data.key?('last_modified_at')
48
- 'last_modified_at'
49
- end
50
- @layout = @data['layout'] if @data.key? 'layout'
51
- @tags = @data['tags'] if @data.key? 'tags'
52
- end
144
+ # Sets the following uninitialized instance attributes in APage from selected key/value pairs in `obj.data`:
145
+ # `categories`, `date`, `description`, `excerpt`, `ext`, `last_modified` or `last_modified_at`,
146
+ # `layout`, and `tags`.
147
+ # Sets the following instance attributes in APage from selected attributes in `obj` (when present):
148
+ # `content`, `destination`, `ext` and `extname`, `label` from `collection.label`,
149
+ # `path`, `relative_path`, `type`, and `url`.
150
+ def build(obj) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
151
+ @categories ||= obj_field(obj, :categories)
53
152
 
54
- def obj_field_init(obj)
55
- @content = obj.content if obj.respond_to? :content
153
+ collection_value = obj_field(obj, :collection)
154
+ @collection_name = if collection_value
155
+ if collection_value.respond_to?(:label)
156
+ collection_value.label
157
+ elsif collection_value.key? :label
158
+ collection_value[:label]
159
+ end
160
+ end
56
161
 
162
+ @content ||= obj.content if obj.respond_to? :content
163
+ @data ||= obj.respond_to?(:data) ? obj.data : {}
164
+ @date ||= obj_field(obj, :date) || Time.now # Jekyll doc.date property is a Time
165
+ @description ||= obj_field(obj, :description)
57
166
  # TODO: What _config.yml setting should be passed to destination()?
58
- @destination = obj.destination('') if obj.respond_to? :destination
59
- @ext = obj.extname
60
- @extname = @ext # For compatibility with previous versions of all_collections
61
- @label = obj.collection.label if obj.respond_to?(:collection) && obj.collection.respond_to?(:label)
62
- @path = obj.path if obj.respond_to? :path
63
- @relative_path = obj.relative_path if obj.respond_to? :relative_path
64
- @type = obj.type if obj.respond_to? :type
65
- @url = obj.url
66
- @url = "#{@url}index.html" if @url.end_with? '/'
167
+ @destination ||= obj.destination('') if obj.respond_to? :destination
168
+ @draft ||= Jekyll::Draft.draft? obj
169
+ @excerpt ||= obj_field(obj, :excerpt)
170
+ @ext ||= obj_field(obj, :ext) || obj_field(obj, :extname)
171
+ @extname ||= @ext # For compatibility with previous versions of all_collections
172
+ @label ||= obj.collection.label if obj.respond_to?(:collection) && obj.collection.respond_to?(:label)
173
+
174
+ @last_modified ||= obj_field(obj, :last_modified) ||
175
+ obj_field(obj, :last_modified_at) ||
176
+ Date.parse(@date.to_s) # Jekyll doc.last_modified property is a Date
177
+
178
+ @last_modified_field ||= if obj_field(obj, :last_modified)
179
+ :last_modified
180
+ elsif obj_field(obj, :last_modified_at)
181
+ :last_modified_at
182
+ end
183
+
184
+ @layout ||= obj_field(obj, :layout)
185
+ @path ||= obj_field(obj, :path)
186
+ @relative_path ||= obj_field(obj, :relative_path)
187
+ @tags ||= obj_field(obj, :tags)
188
+ @type ||= obj_field(obj, :type)
189
+
190
+ @url ||= obj.url
191
+ if @url
192
+ @url = "#{@url}index.html" if @url&.end_with? '/'
193
+ else
194
+ @url = '/index.html'
195
+ end
196
+
197
+ # @href = "/#{@href}" if @origin == 'individual_page'
198
+ @href ||= @url
199
+ @name ||= File.basename(@href)
200
+ @title ||= obj_field(obj, :title) || "<code>#{@href}</code>"
67
201
  end
68
202
  end
69
203
  end
@@ -22,8 +22,8 @@ module JekyllAllCollections
22
22
  ::AllCollectionsHooks.compute(site) if !@site.class.method_defined?(:all_documents) || @site.all_documents.nil?
23
23
  end
24
24
  rescue StandardError => e
25
- JekyllSupport.error_short_trace(@logger, e)
26
- # JekyllSupport.warn_short_trace(@logger, e)
25
+ ::JekyllSupport.error_short_trace(@logger, e)
26
+ # ::JekyllSupport.warn_short_trace(@logger, e)
27
27
  end
28
28
 
29
29
  # Yes, all_collections is defined for this hook
@@ -31,8 +31,8 @@ module JekyllAllCollections
31
31
  # defined_msg = ::AllCollectionsHooks.all_collections_defined?(site)
32
32
  # @logger.debug { "Jekyll::Hooks.register(:site, :post_read, :low: #{defined_msg}" }
33
33
  # rescue StandardError => e
34
- # JekyllSupport.error_short_trace(@logger, e)
35
- # # JekyllSupport.warn_short_trace(@logger, e)
34
+ # ::JekyllSupport.error_short_trace(@logger, e)
35
+ # # ::JekyllSupport.warn_short_trace(@logger, e)
36
36
  # end
37
37
 
38
38
  # Yes, all_collections is defined for this hook
@@ -40,8 +40,8 @@ module JekyllAllCollections
40
40
  # defined_msg = ::AllCollectionsHooks.all_collections_defined?(site)
41
41
  # @logger.debug { "Jekyll::Hooks.register(:site, :post_read, :normal: #{defined_msg}" }
42
42
  # rescue StandardError => e
43
- # JekyllSupport.error_short_trace(@logger, e)
44
- # # JekyllSupport.warn_short_trace(@logger, e)
43
+ # ::JekyllSupport.error_short_trace(@logger, e)
44
+ # # ::JekyllSupport.warn_short_trace(@logger, e)
45
45
  # end
46
46
 
47
47
  # Yes, all_collections is defined for this hook
@@ -49,8 +49,8 @@ module JekyllAllCollections
49
49
  # defined_msg = ::AllCollectionsHooks.all_collections_defined?(site)
50
50
  # @logger.debug { "Jekyll::Hooks.register(:site, :pre_render: #{defined_msg}" }
51
51
  # rescue StandardError => e
52
- # JekyllSupport.error_short_trace(@logger, e)
53
- # # JekyllSupport.warn_short_trace(@logger, e)
52
+ # ::JekyllSupport.error_short_trace(@logger, e)
53
+ # # ::JekyllSupport.warn_short_trace(@logger, e)
54
54
  # end
55
55
  end
56
56
  end
@@ -10,18 +10,6 @@ module AllCollectionsHooks
10
10
  "site.all_collections #{site.class.method_defined?(:all_collections) ? 'IS' : 'IS NOT'} defined"
11
11
  end
12
12
 
13
- # Create Array of AllCollectionsHooks::APage from objects
14
- # @param objects [Array] An array of Jekyll::Document, Jekyll::Page or file names
15
- # @param origin [String] Indicates type of objects being passed
16
- def self.apages_from_objects(objects, origin)
17
- pages = []
18
- objects.each do |object|
19
- page = APage.new(object, origin)
20
- pages << page unless page.data['exclude_from_all'] || page.path == 'redirect.html'
21
- end
22
- pages
23
- end
24
-
25
13
  # Called by early, high-priority hook.
26
14
  # Computes site.all_collections, site.all_documents, site.everything, and site.sorted_lru_files
27
15
  def self.compute(site)
@@ -32,11 +20,11 @@ module AllCollectionsHooks
32
20
  .map { |x| x.class.method_defined?(:docs) ? x.docs : x }
33
21
  .flatten
34
22
  .compact
35
- @all_collections = AllCollectionsHooks.apages_from_objects(documents, 'collection')
23
+ @all_collections = JekyllSupport.apages_from_objects(documents, 'collection')
36
24
  @all_documents = @all_collections +
37
- AllCollectionsHooks.apages_from_objects(site.pages, 'individual_page')
25
+ JekyllSupport.apages_from_objects(site.pages, 'individual_page')
38
26
  @everything = @all_documents +
39
- AllCollectionsHooks.apages_from_objects(site.static_files, 'static_file')
27
+ JekyllSupport.apages_from_objects(site.static_files, 'static_file')
40
28
  @sorted_lru_files = SortedLruFiles.new.add_pages @everything
41
29
 
42
30
  site.all_collections = @all_collections
@@ -44,7 +32,7 @@ module AllCollectionsHooks
44
32
  site.everything = @everything
45
33
  site.sorted_lru_files = @sorted_lru_files
46
34
  rescue StandardError => e
47
- JekyllSupport.error_short_trace(::JekyllAllCollections::AllCollectionsHooks.logger, e)
48
- # JekyllSupport.warn_short_trace(::JekyllAllCollections::AllCollectionsHooks.logger, e)
35
+ ::JekyllSupport.error_short_trace(::JekyllAllCollections::AllCollectionsHooks.logger, e)
36
+ # ::JekyllSupport.warn_short_trace(::JekyllAllCollections::AllCollectionsHooks.logger, e)
49
37
  end
50
38
  end