jekyll-kw-sri 0.0.5 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21baed53f8e36155187629181d0d0db471bb7e8c5002e7121998d6a2e8009a0b
4
- data.tar.gz: fcce7592fcaa7901d35c418ee53f36e84747924ab3f5600749a185d8719a610d
3
+ metadata.gz: c7902eadb45a7e5c28e0cb825b28b5248562e4588f120fbd1c8a492980af2263
4
+ data.tar.gz: 4c6dd43a581261a40f70febc28a461fc96a8126bcf3e9cb6d69f3371b4e1567f
5
5
  SHA512:
6
- metadata.gz: 6c50c84167e0febc7402d51df4bc66c040fb048899e9e58024847439319202fbcf89e59f8c7a9771b44f0b8f01fab290a76614728b0a094dc4a498b19c415062
7
- data.tar.gz: e29ed92a20699f71a692141c25faf0b6eb79cab9e8c20d96cf4b18981a092d149211c9f80fdb493930c4d85203d979b324bcc77aa2cfbc27f7231420b2aaaa88
6
+ metadata.gz: 47d65b93ea5e06d7d697a039564479059e31d28c1b5029cea17ae986401b37420da5035042e31316d97d6ce4ca3feb37d98c1da8981930169ada34510f4a1b12
7
+ data.tar.gz: e36bc6e08b94ac4a315805ef6244ae19de00fdd987d113da9bf30c43a006e895295f236cd33a93d1efff11191310646d02655d095910a248ea541dc2cfe840a5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 n13.org
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,14 +1,70 @@
1
1
  # jekyll-kw-sri
2
2
 
3
+ ![CI](https://github.com/n13org/jekyll-kw-sri/workflows/CI/badge.svg)
4
+ ![Coverage](https://github.com/n13org/jekyll-kw-sri/workflows/Coverage/badge.svg)
5
+ ![RuboCop](https://github.com/n13org/jekyll-kw-sri/workflows/RuboCop/badge.svg)
6
+
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a82f10c3cd9fea769a0b/maintainability)](https://codeclimate.com/github/n13org/jekyll-kw-sri/maintainability)
8
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/a82f10c3cd9fea769a0b/test_coverage)](https://codeclimate.com/github/n13org/jekyll-kw-sri/test_coverage)
9
+
3
10
  [![Gem Version](https://badge.fury.io/rb/jekyll-kw-sri.svg)](https://badge.fury.io/rb/jekyll-kw-sri)
4
11
 
5
- A plugin for jekyll to calculate [Subresource Integrity][Wikipedia SRI] (SRI) hashes for CSS (even SCSS and SASS) and JS files during build time.
12
+ A plugin for [jekyll][Jekyll Website] to calculate [Subresource Integrity][Wikipedia SRI] (SRI) hashes for CSS (even SCSS and SASS) and JS files during build time.
6
13
 
7
14
  > **Subresource Integrity** (SRI) is a security feature that enables browsers to verify that resources they fetch (for example, from a CDN) are delivered without unexpected manipulation. It works by allowing you to provide a cryptographic hash that a fetched resource must match.
8
15
 
9
16
  from [Mozilla docs][Mozilla Subresource Integrity]
10
17
 
11
- ## Configuration
18
+ ## 🔥 Usage
19
+
20
+ ### Usage for version `>= v0.1.0`
21
+
22
+ Use the [Jekyll Includes] `kw-integrity-css.html` for css, scss and sass; and the `kw-integrity-js.html` for js.
23
+
24
+ > For static, non-rendered `css` files the hash values have to me calculated and stored in a file. See `Action Items / Shell commands` section about SRI! All the hash-files should be stored in `./_includes/integrity` so they can easy used.
25
+
26
+ The markdown syntax shows the include file with one paramter "the filename".
27
+
28
+ ```markdown
29
+ {% include kw-integrity-css.html file='style.scss' %}
30
+ ```
31
+
32
+ The rendered html will use the default path, the css file and the calculated hash.
33
+
34
+ ```html
35
+ <link rel="stylesheet" href="/assets/css/style.css" integrity="sha384-cl6CK1yzEvoM3Sw3dL8YAm/P2VpQiD+mAFVkkb6Bh+23PP1ow2gXXGw4WnQlzO0B" crossorigin="anonymous">
36
+ ```
37
+
38
+ The markdown syntax shows the include file with all paramters. All parameter can be omit. The **default values** are file = "main.scss", path = "assets/css/" and hash = "sha384".
39
+
40
+ ```markdown
41
+ {% include kw-integrity-css.html file='style.scss' path='my/folder/to/css/' hash='sha512' %}
42
+ ```
43
+
44
+ ### Usage for version `< v0.1.0`
45
+
46
+ Use the [custom tag][Jekyll Liquid] `sri_scss_hash`.
47
+
48
+ > This approach was inspired by [vcsjones.dev Blog] and [vcsjones.dev GitHub].
49
+
50
+ The `html` inside the post or page markdown file, shows a usage of a `scss` file which will be compiled to a `css`. The hash of the integrity will be generated during the build time.
51
+
52
+ ```html
53
+ <link rel="stylesheet" href="{{ '/assets/css/kargware.css' | relative_url }}" integrity="{% sri_scss_hash /assets/css/kargware.scss %}" crossorigin="anonymous">
54
+ ```
55
+
56
+ The result of the html inside the markdown is the `href` and the `integrity`.
57
+
58
+ ```html
59
+ <link rel="stylesheet" href="/assets/css/kargware.css" integrity="sha384-cl6CK1yzEvoM3Sw3dL8YAm/P2VpQiD+mAFVkkb6Bh+23PP1ow2gXXGw4WnQlzO0B" crossorigin="anonymous">
60
+ ```
61
+
62
+ ## Changelog
63
+
64
+ * 0.1.0 Add html include files to use them with `{% include kw-integrity-css.html %}` or `{% include kw-integrity-js.html %}`
65
+ * 0.0.x Add the custom tag `{% sri_scss_hash %}`
66
+
67
+ ## ⚙️ Configuration
12
68
 
13
69
  Add `kw-sri` section to `_config.yml` configure the plugin globally. If you want to use defauls you can ommit the config-section.
14
70
 
@@ -27,7 +83,7 @@ kw-sri:
27
83
  | hash_type | Which kind of integrity hash | sha256, **sha384**, sha512 |
28
84
  | write_source_mapping_url | Add the map-file like to the css | false, **true** |
29
85
 
30
- ## Action Items / Shell commands
86
+ ## 🚀 Action Items / Shell commands
31
87
 
32
88
  Run linting and tests
33
89
 
@@ -65,7 +121,7 @@ calc-integrity-files:
65
121
  done
66
122
  ```
67
123
 
68
- ## Notes / Hints
124
+ ## 📝 Notes / Hints
69
125
 
70
126
  ### Appraisal - Gemfile Generator
71
127
 
@@ -118,7 +174,7 @@ converter = if defined? site.find_converter_instance
118
174
  end
119
175
  ```
120
176
 
121
- ## Setup Steps
177
+ ### Setup Steps
122
178
 
123
179
  ```sh
124
180
  bundle init
@@ -133,5 +189,26 @@ bundle add redcarpet
133
189
  bundle add shoulda
134
190
  ```
135
191
 
192
+ ## 👋 Big Thanks to my inspiration sources
193
+
194
+ * `SRI with Jekyll` [vcsjones.dev Blog] and [vcsjones.dev GitHub]
195
+ * [GitHub Project jekyll/jekyll]
196
+ * [GitHub Project Shopify/liquid]
197
+ * [Medium wrap-your-assets-in-a-gem]
198
+ * `Use jekyll filter scssify` [andreaverlicchi blog scssify]
199
+ * [Blog How to create customizable Liquid tags in Jekyll]
200
+ * [Ruby Module Digest]
201
+
202
+ [Jekyll Website]: https://jekyllrb.com/
203
+ [Jekyll Liquid]: https://jekyllrb.com/docs/liquid/
204
+ [Jekyll Includes]: https://jekyllrb.com/docs/includes/
136
205
  [Wikipedia SRI]: https://en.wikipedia.org/wiki/Subresource_Integrity
137
- [Mozilla Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
206
+ [Mozilla Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
207
+ [vcsjones.dev Blog]: https://vcsjones.dev/2016/11/02/sri-with-jekyll/
208
+ [vcsjones.dev GitHub]: https://github.com/vcsjones/vcsjones.dev/tree/main
209
+ [GitHub Project jekyll/jekyll]: https://github.com/jekyll/jekyll
210
+ [GitHub Project Shopify/liquid]: https://github.com/Shopify/liquid
211
+ [andreaverlicchi blog scssify]: https://www.andreaverlicchi.eu/critical-css-jekyll-sass-github-pages/
212
+ [Ruby Module Digest]: https://ruby-doc.com/stdlib/libdoc/digest/rdoc/Digest.html
213
+ [Blog How to create customizable Liquid tags in Jekyll]: https://blog.sverrirs.com/2016/04/custom-jekyll-tags.html
214
+ [Medium wrap-your-assets-in-a-gem]: https://medium.com/@paulfarino/wrap-your-assets-in-a-gem-3ad7ecf5b075
@@ -0,0 +1,42 @@
1
+ {% assign para_file = include.file | default: "main.scss" %}
2
+ {% assign para_path = include.path | default: "assets/css/" %}
3
+ {% assign para_hash = include.hash | default: "sha384" %}
4
+
5
+ {% assign filename_no_path = para_file | split: "/" | last %}
6
+ {% assign source_file = "/" | append: para_path | append: para_file %}
7
+ {% assign source_file_ex = para_file | split: "." | last %}
8
+ {% assign path_no_filename = para_file | remove: filename_no_path %}
9
+ {% assign target_file_ex = para_file | replace: ".scss", ".css" %}
10
+ {% assign target_file = para_path | append: target_file_ex %}
11
+ {% assign integrity_file = "/integrity/" | append: para_file | append: "." | append: para_hash %}
12
+
13
+ {% comment %}{% raw %}
14
+ <!-- DEBUG BEGINN
15
+ {{ para_file }}
16
+ {{ para_path }}
17
+ {{ para_hash }}
18
+ {{ filename_no_path }}
19
+ {{ source_file }}
20
+ {{ source_file_ex }}
21
+ {{ path_no_filename }}
22
+ {{ target_file }}
23
+ {{ integrity_file }}
24
+ DEBUG END -->
25
+ {% endraw %}{% endcomment %}
26
+
27
+ {% case source_file_ex %}
28
+ {% when "css" %}
29
+ <link rel="stylesheet" href="{{ target_file }}" integrity="{{ para_hash }}-{% include {{ integrity_file }} %}" crossorigin="anonymous">
30
+ {% when "scss" %}
31
+ <link rel="stylesheet" href="{{ target_file }}" integrity="{% sri_scss_hash {{ source_file }} %}" crossorigin="anonymous">
32
+ {% else %}
33
+ <link rel="stylesheet" href="{{ target_file }}">
34
+ {% endcase %}
35
+
36
+ {% comment %}{% raw %}
37
+
38
+ <!-- Trailing Slash Handling ? -->
39
+ {% assign trainling_slash = para_path | slice: -1, 1 %}
40
+ {% if trainling_slash = "/" %}
41
+
42
+ {% endraw %}{% endcomment %}
@@ -0,0 +1,18 @@
1
+ {% assign para_file = include.file | default: "script.js" %}
2
+ {% assign para_path = include.path | default: "assets/js/" %}
3
+ {% assign para_hash = include.hash | default: "sha384" %}
4
+
5
+ {% assign target_file = para_path | append: para_file %}
6
+ {% assign integrity_file = "/integrity/" | append: para_file | append: "." | append: para_hash %}
7
+
8
+ {% comment %}{% raw %}
9
+ <!-- DEBUG BEGINN
10
+ {{ para_file }}
11
+ {{ para_path }}
12
+ {{ para_hash }}
13
+ {{ target_file }}
14
+ {{ integrity_file }}
15
+ DEBUG END -->
16
+ {% endraw %}{% endcomment %}
17
+
18
+ <script src="{{ target_file }}" integrity="{{ para_hash }}-{% include {{ integrity_file }} %}" crossorigin="anonymous"></script>
@@ -9,10 +9,6 @@ module Jekyll
9
9
  module KargWare
10
10
  # jekyll-kw-sri custom tag
11
11
  class SriScssHashTag < Jekyll::Tags::IncludeRelativeTag
12
- # class SriScssHashTag < Liquid::Tag
13
-
14
- # alias super_render render
15
-
16
12
  def initialize(tag_name, input, tokens)
17
13
  super
18
14
 
@@ -20,10 +16,6 @@ module Jekyll
20
16
  # File.exists? is file?
21
17
  end
22
18
 
23
- # def syntax_example
24
- # "{% #{@tag_name} css/main.scss %}"
25
- # end
26
-
27
19
  def render(context)
28
20
  cache_compiled_scss(@file, context, lambda {
29
21
  if context.nil? || context.registers[:site].nil?
@@ -55,13 +47,6 @@ module Jekyll
55
47
  end
56
48
 
57
49
  def cache_compiled_scss(path, _context, compute)
58
- # @@cached_scss ||= {}
59
- # if @@cached_scss.key?(path)
60
- # @@cached_scss[path]
61
- # else
62
- # @@cached_scss[path] = compute.call
63
- # end
64
-
65
50
  @cached_scss ||= {}
66
51
  if @cached_scss.key?(path)
67
52
  @cached_scss[path]
@@ -69,6 +54,11 @@ module Jekyll
69
54
  @cached_scss[path] = compute.call
70
55
  end
71
56
  end
57
+
58
+ # Register the sccs file as include folder
59
+ def tag_includes_dirs(context)
60
+ [context.registers[:site].source].freeze
61
+ end
72
62
  end
73
63
  end
74
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllKwSri
4
- VERSION = '0.0.5'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-kw-sri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Karg
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-11-12 00:00:00.000000000 Z
12
+ date: 2020-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '4.0'
20
+ version: '3.8'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '4.0'
27
+ version: '3.8'
28
28
  description: Jekyll plugin which calculate the integrity hash of CSS (SCSS, SASS)
29
29
  and JS.
30
30
  email: rubygems.org@n13.org
@@ -32,7 +32,10 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
+ - LICENSE
35
36
  - README.md
37
+ - _includes/kw-integrity-css.html
38
+ - _includes/kw-integrity-js.html
36
39
  - lib/jekyll-kw-sri.rb
37
40
  - lib/jekyll-kw-sri/configuration.rb
38
41
  - lib/jekyll-kw-sri/parser.rb
@@ -40,7 +43,9 @@ files:
40
43
  homepage: https://github.com/n13org/jekyll-kw-sri
41
44
  licenses:
42
45
  - MIT
43
- metadata: {}
46
+ metadata:
47
+ bug_tracker_uri: https://github.com/n13org/jekyll-kw-sri/issues
48
+ source_code_uri: https://github.com/n13org/jekyll-kw-sri/
44
49
  post_install_message:
45
50
  rdoc_options: []
46
51
  require_paths:
@@ -49,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
54
  requirements:
50
55
  - - ">="
51
56
  - !ruby/object:Gem::Version
52
- version: '2.7'
57
+ version: '2.4'
53
58
  required_rubygems_version: !ruby/object:Gem::Requirement
54
59
  requirements:
55
60
  - - ">="