jekyll_dynamic_assets 1.0.0 → 1.1.0
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/CHANGELOG.md +16 -1
- data/README.md +27 -14
- data/lib/jekyll_dynamic_assets/defaults/formats.rb +16 -0
- data/lib/jekyll_dynamic_assets/processor.rb +18 -4
- data/lib/jekyll_dynamic_assets/version.rb +1 -1
- data/lib/jekyll_dynamic_assets.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce45ad23c704195b61891db09c7f3d5e49c8152d5203d3ef1fb777eb82fa5c64
|
4
|
+
data.tar.gz: acdc459add9164deac556f9a018ae473f9393a1c93a1c42176f9a8c783210079
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61e538c18026d13670756d41339abf91e41665e726ecf35f4a5aa9eff9f611febe9d3db84cb3686942bc414e23608d4baadc66fd84ef9445ab9439d2802301ba
|
7
|
+
data.tar.gz: e83ebbe0089fc6b435d40e40d7512e5ee3836f511d4765333b1282ff94651ccb11bd776c72e674707d700f80ebdd758504f213f02d52caea7a268ae417a725fb
|
data/CHANGELOG.md
CHANGED
@@ -8,4 +8,19 @@
|
|
8
8
|
|
9
9
|
## [1.0.0] - 2025-06-05
|
10
10
|
|
11
|
-
- Initial release
|
11
|
+
- Initial release
|
12
|
+
|
13
|
+
## [1.1.0] - 2025-06-06
|
14
|
+
|
15
|
+
- Added Default Formats for the following:
|
16
|
+
- css
|
17
|
+
- js
|
18
|
+
- mjs
|
19
|
+
- ts
|
20
|
+
- json
|
21
|
+
- ico
|
22
|
+
- woff
|
23
|
+
- woff2
|
24
|
+
- ttf
|
25
|
+
- otf
|
26
|
+
- Added Source selection
|
data/README.md
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
# JekyllDynamicAssets
|
2
2
|
|
3
|
-
JekyllDynamicAssets is a Jekyll plugin that allows you to dynamically manage and inject CSS, JS and other assets into your site using presets, per-page configuration, and flexible formatting.
|
3
|
+
JekyllDynamicAssets is a Jekyll plugin that allows you to dynamically manage and inject CSS, JS, and other head assets into your site using presets, per-page configuration, and flexible formatting.
|
4
4
|
|
5
5
|
## Features
|
6
6
|
- Define global (master) assets and per-page assets
|
7
7
|
- Use asset presets for reusable asset groups
|
8
|
-
-
|
8
|
+
- Pre-defined default formats for common assets, can be overwritten
|
9
9
|
- Liquid tag `{% assets %}` for easy asset injection in templates and includes
|
10
|
+
- Error reporting for missing presets
|
10
11
|
|
11
12
|
## Installation
|
12
13
|
|
13
|
-
Add this
|
14
|
+
Add this to your Jekyll site's `Gemfile`:
|
14
15
|
|
15
16
|
```ruby
|
16
17
|
source 'https://rubygems.org'
|
17
18
|
|
18
19
|
gem "jekyll"
|
19
20
|
|
20
|
-
|
21
21
|
group :jekyll_plugins do
|
22
22
|
gem "jekyll_dynamic_assets"
|
23
23
|
# other gems
|
@@ -31,21 +31,28 @@ plugins:
|
|
31
31
|
- jekyll_dynamic_assets
|
32
32
|
```
|
33
33
|
|
34
|
+
Finally, in your terminal run:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
bundle install
|
38
|
+
```
|
39
|
+
|
34
40
|
## Usage
|
35
41
|
|
36
42
|
1. **Configure your assets in `config.yml`:**
|
37
43
|
|
38
44
|
```yaml
|
39
45
|
assets:
|
40
|
-
master:
|
46
|
+
master: # Master assets
|
41
47
|
- main.css
|
42
48
|
- main.js
|
49
|
+
source: "/assets/" # Optional: base path for all assets
|
43
50
|
formats:
|
44
|
-
|
45
|
-
|
46
|
-
presets:
|
51
|
+
js: "<script defer src='%s'></script>" # Overwrite defaults
|
52
|
+
xyz: "<custom> %s </custom>" # Define Custom formats
|
53
|
+
presets: # Create presets to include multiple assets
|
47
54
|
blog: [blog.css, blog.js]
|
48
|
-
project: [project.css, project.js]
|
55
|
+
project: [project.css, project.js, code-highlight.css, slideshow.js, myApp.js]
|
49
56
|
```
|
50
57
|
|
51
58
|
2. **Per-page or per-collection configuration:**
|
@@ -55,20 +62,26 @@ In your page or post front matter:
|
|
55
62
|
```yaml
|
56
63
|
assets:
|
57
64
|
files:
|
58
|
-
-
|
65
|
+
- manual.css # include singular files
|
59
66
|
presets:
|
60
|
-
- blog
|
67
|
+
- blog # Use a preset
|
61
68
|
```
|
62
69
|
|
63
70
|
3. **Inject assets in your templates:**
|
64
71
|
|
65
|
-
Use the Liquid tag where you want the assets to appear:
|
72
|
+
Use the Liquid tag where you want the assets to appear (typically in your `<head>`):
|
66
73
|
|
67
74
|
```liquid
|
68
|
-
|
75
|
+
<head>
|
76
|
+
<!-- other tags like meta etc. -->
|
77
|
+
|
78
|
+
{% assets %}
|
79
|
+
</head>
|
69
80
|
```
|
70
81
|
|
71
|
-
This will output the appropriate HTML tags for all configured assets.
|
82
|
+
This will output the appropriate HTML tags for all configured assets. The tag should generally be used inside your `<head>` tag but can be used anywhere else.
|
83
|
+
|
84
|
+
For assets which you haven't defined any format and there isn't any default for it either, the code will simply write the name of that asset.
|
72
85
|
|
73
86
|
## Contributing
|
74
87
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JekyllDynamicAssets
|
4
|
+
DEFAULT_FORMATS = {
|
5
|
+
"css" => '<link rel="stylesheet" href="%s">',
|
6
|
+
"js" => '<script src="%s"></script>',
|
7
|
+
"mjs" => '<script type="module" src="%s"></script>',
|
8
|
+
"ts" => '<script type="module" src="%s"></script>',
|
9
|
+
"json" => '<link rel="alternate" type="application/json" href="%s">',
|
10
|
+
"ico" => '<link rel="icon" href="%s">',
|
11
|
+
"woff" => '<link rel="preload" href="%s" as="font" type="font/woff" crossorigin>',
|
12
|
+
"woff2" => '<link rel="preload" href="%s" as="font" type="font/woff2" crossorigin>',
|
13
|
+
"ttf" => '<link rel="preload" href="%s" as="font" type="font/ttf" crossorigin>',
|
14
|
+
"otf" => '<link rel="preload" href="%s" as="font" type="font/otf" crossorigin>'
|
15
|
+
}.freeze
|
16
|
+
end
|
@@ -23,23 +23,37 @@ module JekyllDynamicAssets
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def format_string(extension)
|
26
|
-
formats
|
26
|
+
formats ||= formats_merge(DEFAULT_FORMATS, @config["formats"])
|
27
27
|
formats[extension] || "%s"
|
28
28
|
end
|
29
29
|
|
30
|
+
def formats_merge(default, custom)
|
31
|
+
custom.merge default do |_key, custom_setting, default_setting|
|
32
|
+
custom_setting unless default_setting.respond_to? :merge
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
30
36
|
def combined_assets
|
31
37
|
# Container
|
32
38
|
assets = []
|
33
39
|
|
34
|
-
# Add
|
40
|
+
# Add assets
|
35
41
|
assets.concat(Array(@config["master"]))
|
36
42
|
assets.concat(Array(preset_files))
|
37
43
|
assets.concat(Array(@page_config["files"]))
|
38
44
|
|
39
|
-
assets.uniq
|
45
|
+
append_base(assets.uniq)
|
46
|
+
end
|
47
|
+
|
48
|
+
def append_base(assets)
|
49
|
+
base = @config["source"].to_s
|
50
|
+
base += "/" unless base.end_with?("/") || base.empty?
|
51
|
+
|
52
|
+
assets.map { |asset| asset.start_with?("http") ? asset : base + asset }
|
40
53
|
end
|
41
54
|
|
42
55
|
def preset_files
|
56
|
+
# Collect assets from presets
|
43
57
|
preset_assets = []
|
44
58
|
bad_presets = []
|
45
59
|
selected_presets = Array(@page_config["presets"])
|
@@ -51,7 +65,7 @@ module JekyllDynamicAssets
|
|
51
65
|
bad_presets << preset
|
52
66
|
end
|
53
67
|
end
|
54
|
-
remaining?(bad_presets)
|
68
|
+
remaining?(bad_presets) # Raise error for undefined errors
|
55
69
|
preset_assets
|
56
70
|
end
|
57
71
|
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative "jekyll_dynamic_assets/version"
|
4
4
|
require_relative "jekyll_dynamic_assets/processor"
|
5
5
|
require_relative "jekyll_dynamic_assets/assets_tag"
|
6
|
+
require_relative "jekyll_dynamic_assets/defaults/formats"
|
6
7
|
|
7
8
|
module JekyllDynamicAssets
|
8
9
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_dynamic_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- M. Umar Shahbaz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-06-
|
11
|
+
date: 2025-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- lib/jekyll_dynamic_assets.rb
|
68
68
|
- lib/jekyll_dynamic_assets/assets_tag.rb
|
69
|
+
- lib/jekyll_dynamic_assets/defaults/formats.rb
|
69
70
|
- lib/jekyll_dynamic_assets/processor.rb
|
70
71
|
- lib/jekyll_dynamic_assets/version.rb
|
71
72
|
- sig/jekyll_dynamic_assets.rbs
|