jekyll-kw-sri 0.0.4 → 0.1.2

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: 2bf7b33dc9b54d2ebcec17404f4bf5548760edba5148f8bf35b78a721d307293
4
- data.tar.gz: 03f1d62d5b555a4225c4d352d744de1152b8976afda0332dd7d5510b8c17a1dc
3
+ metadata.gz: ce17b7850d6f74e3cba9b00d0b75a1c93bf7ab17160ab14a4747738c4d30e6a2
4
+ data.tar.gz: 5955abff66c1ed35c604193648fbb6cbc6498ca61b7c3213daa69efdc0cba0cd
5
5
  SHA512:
6
- metadata.gz: 1a9fe066a7815dff331e10b68da1c3d83ae020afc901bdb81624aeb970d794fad34c2e53290481c4295a648dcf88e9d0c33c75fae707adf140efd81c10d34d7b
7
- data.tar.gz: 4165a4c3b504a10622cc7991e13302bd3ee5c76ee8e62df7d86b28ed5a03268d87badf9c62c7881a89f6c7df25f69fdcb30b1deb008bbf258db7e5f84076d11d
6
+ metadata.gz: dd2ac1faad52d4d9577390f48f3ff71249f8406ebb1dac79cfd530e100a113ff68c98531f39bad583082f751b3af927bd0bcb3b8dd499f190e8bee39ab521dd4
7
+ data.tar.gz: 2524654da0dcfb241ff1b9b7ca218ab4c4f3f24c7b17210d5a574a62483b46003cb6094b761d355f5cfdabca3ea89d881bb2084ebc19094839431eb23c060c23
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,16 +1,72 @@
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
- Add `kw-sri` section to `_config.yml` configure the plugin globally.
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
 
15
71
  ```yaml
16
72
  kw-sri:
@@ -27,18 +83,46 @@ 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
- Add `sri: true` to **Front Matter** of `<page>` or `<post>` to activate the sri plugin.
86
+ ## 🚀 Action Items / Shell commands
31
87
 
32
- ## Build gem
88
+ Run linting and tests
33
89
 
34
- ## Publish gem
90
+ ```sh
91
+ bundle exec rubocop
92
+ bundle exec rake test
93
+ ```
35
94
 
36
- ## Run tests
95
+ Build gem package
37
96
 
38
97
  ```sh
39
- bundle exec rake test
98
+ bundle exec rake build
99
+ ```
100
+
101
+ Publish gem package
102
+
103
+ ```sh
104
+ bundle exec rake release
105
+ ```
106
+
107
+ Calc a SRI Integrity hash of `./style.css` in format `sha256`
108
+
109
+ ```shell
110
+ openssl dgst -sha256 -binary ./style.css | openssl base64 -A
40
111
  ```
41
112
 
113
+ Calc different **SRI integrity** hash-files from `css-files` (same is valid for `js-files`) in format `sha256`, `sha384` and `sha512` inside a **Makefile**
114
+
115
+ ```plain
116
+ calc-integrity-files:
117
+ for strength in 256 384 512 ; do \
118
+ cat ./assets/css/style.min.css | openssl dgst -sha$$strength -binary | openssl base64 -A > ./_includes/integrity/style.min.css.sha$$strength ; \
119
+ cat ./assets/css/main.css | openssl dgst -sha$$strength -binary | openssl base64 -A > ./_includes/integrity/main.css.sha$$strength ; \
120
+ cat ./assets/js/script.js | openssl dgst -sha$$strength -binary | openssl base64 -A > ./_includes/integrity/script.js.sha$$strength ; \
121
+ done
122
+ ```
123
+
124
+ ## 📝 Notes / Hints
125
+
42
126
  ### Appraisal - Gemfile Generator
43
127
 
44
128
  [GitHub](https://github.com/thoughtbot/appraisal)
@@ -50,8 +134,6 @@ bundle exec rake test
50
134
  bundle exec appraisal generate
51
135
  ```
52
136
 
53
- ## Notes / Hints
54
-
55
137
  ### Site context is empty
56
138
 
57
139
  Inside the `render(context)` function of a `Liquid::Tag` there is a context object. With that context you can get the `site` object, anyhow when you want to cretae your temporry **site** and **context** you need a workaround.
@@ -92,13 +174,7 @@ converter = if defined? site.find_converter_instance
92
174
  end
93
175
  ```
94
176
 
95
- ## SRI Integrity
96
-
97
- ```shell
98
- openssl dgst -sha256 -binary ./style.css | openssl base64 -A
99
- ```
100
-
101
- ## Setup Steps
177
+ ### Setup Steps
102
178
 
103
179
  ```sh
104
180
  bundle init
@@ -113,5 +189,26 @@ bundle add redcarpet
113
189
  bundle add shoulda
114
190
  ```
115
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/
116
205
  [Wikipedia SRI]: https://en.wikipedia.org/wiki/Subresource_Integrity
117
- [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,30 +9,14 @@ 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
 
19
15
  raise 'Please enter a file path' if input.length <= 0
20
-
21
- @scss_file = strip_or_self(input)
22
16
  # File.exists? is file?
23
-
24
- @tag_name = tag_name
25
-
26
- # puts syntax_example
27
17
  end
28
18
 
29
- # def syntax_example
30
- # "{% #{@tag_name} css/main.scss %}"
31
- # end
32
-
33
19
  def render(context)
34
- # return '' unless context.registers[:page]['sri']
35
-
36
20
  cache_compiled_scss(@file, context, lambda {
37
21
  if context.nil? || context.registers[:site].nil?
38
22
  puts 'WARNING: There was no context, generate default site and context'
@@ -44,29 +28,25 @@ module Jekyll
44
28
  @sri_config = context.registers[:site].config['kw-sri'] || {}
45
29
  end
46
30
 
31
+ # Render the context with the base-class
47
32
  converter = site.find_converter_instance(Jekyll::Converters::Scss)
48
-
49
- # var scss = render(context)
50
- result = super_render(context) # super(context)
33
+ result = super(context) # super_render(context)
51
34
  scss = result.gsub(/^---.*---/m, '')
52
35
  data = converter.convert(scss)
53
36
 
37
+ # Get path out of the file object
54
38
  file = render_variable(context) || @file
55
39
  validate_file_name(file)
56
40
  path = locate_include_file(context, file, site.safe)
57
41
 
42
+ # Use default config for kw-sri if it is nil
43
+ @sri_config ||= Jekyll::KargWare::Integrity::Configuration::DEFAULT_CONFIG
44
+
58
45
  Integrity::Parser.new(@sri_config).calc_integrity(path, data)
59
46
  })
60
47
  end
61
48
 
62
49
  def cache_compiled_scss(path, _context, compute)
63
- # @@cached_scss ||= {}
64
- # if @@cached_scss.key?(path)
65
- # @@cached_scss[path]
66
- # else
67
- # @@cached_scss[path] = compute.call
68
- # end
69
-
70
50
  @cached_scss ||= {}
71
51
  if @cached_scss.key?(path)
72
52
  @cached_scss[path]
@@ -75,11 +55,7 @@ module Jekyll
75
55
  end
76
56
  end
77
57
 
78
- # https://stackoverflow.com/a/1000975
79
- def strip_or_self(str)
80
- str.strip! || str
81
- end
82
-
58
+ # Register the sccs file as include folder
83
59
  def tag_includes_dirs(context)
84
60
  [context.registers[:site].source].freeze
85
61
  end
@@ -19,7 +19,7 @@ module Jekyll
19
19
  data_modified = add_source_mapping_url(filename, data)
20
20
 
21
21
  # Debuging, save rendered css file as tmp file
22
- File.open(".#{filename}.tmp", 'w') { |file| file.write(data_modified) } if @configuration.create_tmpfile
22
+ File.open("#{filename}.tmp", 'w') { |file| file.write(data_modified) } if @configuration.create_tmpfile
23
23
 
24
24
  case hash_type
25
25
  when 'sha256'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllKwSri
4
- VERSION = '0.0.4'
4
+ VERSION = '0.1.2'
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.4
4
+ version: 0.1.2
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
@@ -49,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
52
  requirements:
50
53
  - - ">="
51
54
  - !ruby/object:Gem::Version
52
- version: '2.7'
55
+ version: '2.4'
53
56
  required_rubygems_version: !ruby/object:Gem::Requirement
54
57
  requirements:
55
58
  - - ">="