jekyll_dynamic_assets 1.0.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39b2333302ea07b39ecfa9bdf32356bbd4e9c1457bd84b278189d07997e53942
4
- data.tar.gz: e27b36bf7e8841d81c84f02d43a33cc0506f4375ab9bbfb3ea924ffad23d97dc
3
+ metadata.gz: 05cd13c82fadc3c86b4d801b9add765ebf4550be874835c5e72bb3a52af0b2b8
4
+ data.tar.gz: 8481c677ec9ea09c2b13d56ff5fc1c251a7f982725094e4b92c16331578e264a
5
5
  SHA512:
6
- metadata.gz: 5368cb65e7f886ce410b10e1ce434ff1c406750087d83cdb9960e544c477de25e7a756e2a68b2a4dba970c459b67b4822f9b94f0602ca202a097cd6121e324a1
7
- data.tar.gz: a8b8f42968d7d63a4bac0947d639d8ac3377db24305eaa6dcecdca678c84bdfdbfe841314d8e9d206e9296a5b68c03cca5e166326b38db7db6a7aa2412518e14
6
+ metadata.gz: 3e4618cfd1c9a52f8e2628c41f9c5869cfaee9695f2b9d21137d0622688b71dd3d3511faab48bf584997be2ec8b0d81e983fc826a6b073cd1854470922410450
7
+ data.tar.gz: 263130438147471d34412b6a15a6b14b8b645444589c2b68866314ba58b2e532e22554e413eae14599b2f6a84551b686575762cb93aa4009a057ee69691d5a25
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 3.2
3
+ SuggestExtensions: false
3
4
 
4
5
  Style/StringLiterals:
5
6
  EnforcedStyle: double_quotes
data/CHANGELOG.md CHANGED
@@ -8,4 +8,23 @@
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
27
+
28
+ ## [1.2.0] - 2025-06-06
29
+
30
+ - Added option to select formats
data/README.md CHANGED
@@ -1,23 +1,24 @@
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
- - Customizable HTML output for each asset type (CSS, JS, etc.)
8
+ - Pre-defined default formats for common assets, can be overwritten
9
+ - Auto and Manual select formats
9
10
  - Liquid tag `{% assets %}` for easy asset injection in templates and includes
11
+ - Error reporting for missing presets
10
12
 
11
13
  ## Installation
12
14
 
13
- Add this line to your application's Gemfile:
15
+ Add this to your Jekyll site's `Gemfile`:
14
16
 
15
17
  ```ruby
16
18
  source 'https://rubygems.org'
17
19
 
18
20
  gem "jekyll"
19
21
 
20
-
21
22
  group :jekyll_plugins do
22
23
  gem "jekyll_dynamic_assets"
23
24
  # other gems
@@ -31,21 +32,31 @@ plugins:
31
32
  - jekyll_dynamic_assets
32
33
  ```
33
34
 
35
+ Finally, in your terminal run:
36
+
37
+ ```bash
38
+ bundle install
39
+ ```
40
+
34
41
  ## Usage
35
42
 
36
43
  1. **Configure your assets in `config.yml`:**
37
44
 
38
45
  ```yaml
39
46
  assets:
40
- master:
47
+ master: # Master assets
41
48
  - main.css
42
49
  - main.js
43
- formats:
44
- css: "<link rel='stylesheet' href='%s'>"
45
- js: "<script src='%s'></script>"
46
- presets:
50
+ source: "/assets/" # Optional: base path for all assets, skips assets starting with http
51
+
52
+ presets: # Create presets to include multiple assets
47
53
  blog: [blog.css, blog.js]
48
- project: [project.css, project.js]
54
+ project: [project.css, project.js, code-highlight.css, slideshow.js, myApp.js]
55
+
56
+ formats:
57
+ js: <script defer src='%s'></script> # Overwrite defaults
58
+ xyz: <custom> %s </custom> # Define Custom formats
59
+ screen-css: <link rel="stylesheet" href="%s" media="screen">
49
60
  ```
50
61
 
51
62
  2. **Per-page or per-collection configuration:**
@@ -55,20 +66,27 @@ In your page or post front matter:
55
66
  ```yaml
56
67
  assets:
57
68
  files:
58
- - custom.css
69
+ - manual.css # include singular files
70
+ - onscreen.css::screen-css # Use :: to select a format, default format is determined by file extension
59
71
  presets:
60
- - blog
72
+ - blog # Use a preset
61
73
  ```
62
74
 
63
75
  3. **Inject assets in your templates:**
64
76
 
65
- Use the Liquid tag where you want the assets to appear:
77
+ Use the Liquid tag where you want the assets to appear (typically in your `<head>`):
66
78
 
67
79
  ```liquid
68
- {% assets %}
80
+ <head>
81
+ <!-- other tags like meta etc. -->
82
+
83
+ {% assets %}
84
+ </head>
69
85
  ```
70
86
 
71
- This will output the appropriate HTML tags for all configured assets. This tag should generally be used inside your `<head>` tag but can be used anywhere else.
87
+ 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.
88
+
89
+ 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
90
 
73
91
  ## Contributing
74
92
 
@@ -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
@@ -13,8 +13,8 @@ module JekyllDynamicAssets
13
13
  all_assets = combined_assets
14
14
  asset_insertions = []
15
15
  all_assets.each do |asset|
16
- extension = asset.split(".").last
17
- asset_link = format_string(extension) % asset
16
+ link_format = asset.include?("::") ? asset.split("::").last : asset.split(".").last
17
+ asset_link = format_string(link_format) % asset.split("::").first
18
18
  asset_insertions << asset_link
19
19
  end
20
20
  asset_insertions
@@ -22,24 +22,38 @@ module JekyllDynamicAssets
22
22
 
23
23
  private
24
24
 
25
- def format_string(extension)
26
- formats = @config["formats"] || {}
27
- formats[extension] || "%s"
25
+ def format_string(link_format)
26
+ formats ||= formats_merge(DEFAULT_FORMATS, @config["formats"])
27
+ formats[link_format] || "%s"
28
+ end
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
28
34
  end
29
35
 
30
36
  def combined_assets
31
37
  # Container
32
38
  assets = []
33
39
 
34
- # Add master assets and manual assets
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllDynamicAssets
4
- VERSION = "1.0.0"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -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.0.0
4
+ version: 1.2.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-05 00:00:00.000000000 Z
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