jekyll-uj-powertools 1.4.0 → 1.5.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: bf2e2fcda199ac3fbca2062352312b94e177a99193a85ee3ebfdfae4315063c2
4
- data.tar.gz: 6036a0be11527263de051855fe4015338db44f4c8d6b7227dc64bda174fe7b4a
3
+ metadata.gz: 4e13016489f0630f73c9327a5f2d57732de7fa71aeaf2b62b3a5a74064f09b9e
4
+ data.tar.gz: 137eb99273904dd784739aa126b46ac3d9aa475f5fc874c332be4fe46169e42b
5
5
  SHA512:
6
- metadata.gz: 180f0afccbbe441fbfdc32e1340893de4e0dea5c4adf688eef606bfadd92a7c4515857e699115204f4c62ffce0412e5170cb8187a86d6a14ae88d9abf13d27f7
7
- data.tar.gz: 2f71ba1926df6fde7f6d0f1ebd0cc506a9ec5ccf76fc3350aabbecac25d58c26e720e757122288a7e2aae0a5c84ef4ced76371c89a1abe3a2d70165faade6383
6
+ metadata.gz: 0516d15e7915a3f9f67f869405244ca59d0032f058fc22e9e63f1b7f9cc7e6466988b327b8bcc254a5f45f9c7787af931f5d5f41df4b232c668e6fadf9ff0ea2
7
+ data.tar.gz: 66def45c09200d5791aec723cfa0f4a30d49c42de7c1a8a1dd40002412b4ce6a11bd0c7c7b68be5d87d4d813f0880d02514382bc06f70b041e0445ebb4cbebd9
data/README.md CHANGED
@@ -82,14 +82,48 @@ Use the `site.uj.cache_breaker` variable to append a cache-busting query paramet
82
82
  ### `page.random_id` Variable
83
83
  Generate a random ID for each page, useful for sorting randomly or for unique identifiers.
84
84
 
85
+ ```liquid
86
+ <!-- Sort pages in a random order -->
87
+ {% assign sorted_pages = site.pages | sort: "random_id" %}
88
+ {% for page in sorted_pages %}
89
+ <h2>{{ page.title }}</h2>
90
+ <p>Random ID: {{ page.random_id }}</p>
91
+ <p>{{ page.content }}</p>
92
+ {% endfor %}
93
+ ```
94
+
85
95
  ### `page.extension` Variable
86
96
  Get the file extension of the current page, useful for determining how to process or display the page.
87
97
 
98
+ ```liquid
99
+ <!-- Check the extension of a page -->
100
+ {% if page.extension == "html" %}
101
+ <p>This is an HTML page.</p>
102
+ {% elsif page.extension == "md" %}
103
+ <p>This is a Markdown page.</p>
104
+ {% endif %}
105
+ ```
106
+
88
107
  ### `page.layout_data` Variable
89
- Access the layout data of the current page, which can be useful for debugging or displaying layout-specific information.
108
+ Access the layout data of the page object, which can be useful for accessing layout-specific variables when looping through pages.
90
109
 
91
110
  ```liquid
92
- {{ page.extension }}
111
+ <!-- Loop through pages and access the layout data of each page -->
112
+ {% for page in site.pages %}
113
+ <h2>{{ page.title }}</h2>
114
+ <p>{{ page.layout_data.description }}</p>
115
+ {% endfor %}
116
+ ```
117
+
118
+ ### `page.resolved` Variable
119
+ Resolves the site, layout, and page data into a single object, which can be useful for accessing all the information about the current page in one place.
120
+
121
+ ```liquid
122
+ <!-- New Way -->
123
+ {{ page.resolved.my.variable }}
124
+
125
+ <!-- Old Way -->
126
+ {{ page.my.variable | default: layout.my.variable | default: site.my.variable }}
93
127
  ```
94
128
 
95
129
  These examples show how you can use the features of `jekyll-uj-powertools` in your Jekyll site.
@@ -110,17 +144,11 @@ bundle exec rspec
110
144
 
111
145
  ## 💎 Build + Publish the Gem
112
146
  ```shell
113
- # Ensure dist folder exists
114
- mkdir -p dist
115
-
116
- # Build the gem and push it to RubyGems
117
- gem build jekyll-uj-powertools.gemspec -o dist/jekyll-uj-powertools-latest.gem
118
-
119
- # Publish the latest gem
120
- gem push dist/jekyll-uj-powertools-latest.gem
147
+ # Release
148
+ bundle exec rake release
121
149
 
122
- # Clear the files in the dist folder
123
- rm -rf dist/*
150
+ # Clear the files in the pkg folder
151
+ rm -rf pkg/*
124
152
  ```
125
153
 
126
154
  ## 🗨️ Contributing
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  Gem::Specification.new do |spec|
6
6
  # Gem info
7
7
  spec.name = "jekyll-uj-powertools"
8
- spec.version = "1.4.0"
8
+ spec.version = "1.5.1"
9
9
 
10
10
  # Author info
11
11
  spec.authors = ["ITW Creative Works"]
@@ -26,6 +26,52 @@ module Jekyll
26
26
 
27
27
  private
28
28
 
29
+ def deep_merge(hash1, hash2)
30
+ merger = proc { |_, old_val, new_val|
31
+ if old_val.is_a?(Hash) && new_val.is_a?(Hash)
32
+ old_val.merge(new_val, &merger)
33
+ else
34
+ new_val
35
+ end
36
+ }
37
+ hash1.merge(hash2, &merger)
38
+ end
39
+
40
+ def filter_site_config(config)
41
+ # Get exclusion list from config or use defaults
42
+ exclusions = config['powertools_resolved_exclude'] || default_exclusions
43
+
44
+ # Always exclude the config key itself
45
+ exclusions_with_config_key = exclusions + ['powertools_resolved_exclude']
46
+
47
+ # Create filtered copy
48
+ filtered = {}
49
+ config.each do |key, value|
50
+ next if exclusions_with_config_key.include?(key)
51
+ filtered[key] = value
52
+ end
53
+
54
+ filtered
55
+ end
56
+
57
+ def default_exclusions
58
+ # Exclude Jekyll internal keys and potentially large data
59
+ [
60
+ # Unnecessary Jekyll keys
61
+ 'plugins', 'gems', 'whitelist', 'plugins_dir',
62
+ 'layouts_dir', 'data_dir', 'includes_dir',
63
+ 'collections', 'jekyll-archives', 'scholar',
64
+ 'assets', 'webpack', 'sass', 'keep_files',
65
+ 'include', 'exclude', 'markdown_ext',
66
+
67
+ # Custom exclusions
68
+ 'escapes', 'icons',
69
+
70
+ # Use this to customize exclusions in the Jekyll site
71
+ 'powertools_resolved_exclude',
72
+ ]
73
+ end
74
+
29
75
  def inject_data(item, site)
30
76
  # Inject a random number into the item's data
31
77
  item.data['random_id'] = rand(100) # Random number between 0 and 99
@@ -35,17 +81,34 @@ module Jekyll
35
81
  item.data['extension'] = File.extname(item.path)
36
82
  end
37
83
 
38
- # Skip items without layouts
39
- return unless item.data['layout']
84
+ # Set resolved data for site, layout, and page
85
+ # Create a deep merge of site -> layout -> page data
86
+ # Priority: page (highest) -> layout -> site (lowest)
87
+ resolved = {}
40
88
 
41
- # Find the layout file by its name
42
- layout_name = item.data['layout']
43
- layout = site.layouts[layout_name]
89
+ # Start with site data
90
+ if site.config
91
+ # Filter site config to exclude large/unnecessary keys
92
+ filtered_config = filter_site_config(site.config)
93
+ resolved = deep_merge(resolved, filtered_config)
94
+ end
44
95
 
45
- if layout && layout.data
46
- # Merge layout front matter into item's "layout_data"
47
- item.data['layout_data'] = layout.data
96
+ # Merge layout data if available
97
+ if item.data['layout']
98
+ layout_name = item.data['layout']
99
+ layout = site.layouts[layout_name]
100
+ if layout && layout.data
101
+ resolved = deep_merge(resolved, layout.data)
102
+ # Also add layout_data for backward compatibility
103
+ item.data['layout_data'] = layout.data
104
+ end
48
105
  end
106
+
107
+ # Finally merge page data (highest priority)
108
+ resolved = deep_merge(resolved, item.data)
109
+
110
+ # Add the resolved data to the item
111
+ item.data['resolved'] = resolved
49
112
  end
50
113
  end
51
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-uj-powertools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ITW Creative Works