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 +4 -4
- data/README.md +40 -12
- data/jekyll-uj-powertools.gemspec +1 -1
- data/lib/generators/inject-properties.rb +71 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e13016489f0630f73c9327a5f2d57732de7fa71aeaf2b62b3a5a74064f09b9e
|
4
|
+
data.tar.gz: 137eb99273904dd784739aa126b46ac3d9aa475f5fc874c332be4fe46169e42b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
-
#
|
114
|
-
|
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
|
123
|
-
rm -rf
|
150
|
+
# Clear the files in the pkg folder
|
151
|
+
rm -rf pkg/*
|
124
152
|
```
|
125
153
|
|
126
154
|
## 🗨️ Contributing
|
@@ -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
|
-
#
|
39
|
-
|
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
|
-
#
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
item.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
|