jekyll-js-converter 0.0.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/converters/js.rb +74 -26
- data/lib/jekyll/js_source_map_page.rb +29 -0
- data/lib/jekyll-js-converter/version.rb +1 -1
- data/lib/jekyll-js-converter.rb +16 -0
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a7d061dea9f28995d3038724a26ed29c6c6cdae0656d105ce6a36c68fde5b52
|
4
|
+
data.tar.gz: 2f76e7e429cc3dcc1bc31e055f8a3112f846c8929b74e34ed5cabc74a0cd900b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f50bfb3976bfdd1fb284586dd337694794294861a8fae62c357161c7ba90b7355696e2c9697fe969a99b65deda085b5db685756bcd7af6d6464d4a8334fa8e1
|
7
|
+
data.tar.gz: 3502b12bcd960b6dbc0fa090e303c5cabc695700d171740148179051bcd5cd2002c59f9971e703d020532e36d98105e0e3acd6a0f23e4b7478e3b25623b706c7
|
data/lib/jekyll/converters/js.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'uglifier'
|
2
|
+
require 'jekyll/js_source_map_page'
|
2
3
|
|
3
4
|
module Jekyll
|
4
5
|
module Converters
|
@@ -8,21 +9,15 @@ module Jekyll
|
|
8
9
|
safe true
|
9
10
|
priority :low
|
10
11
|
|
11
|
-
def
|
12
|
-
@
|
13
|
-
|
12
|
+
def associate_page(page)
|
13
|
+
@page = page
|
14
|
+
@source_map_page = JsSourceMapPage.new(@page)
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def output_ext(ext)
|
21
|
-
'.js'
|
22
|
-
end
|
23
|
-
|
24
|
-
def safe?
|
25
|
-
!!@config['safe']
|
17
|
+
def dissociate_page(page)
|
18
|
+
@page = nil
|
19
|
+
@site = nil
|
20
|
+
@source_map_page = nil
|
26
21
|
end
|
27
22
|
|
28
23
|
def javascript_config
|
@@ -35,19 +30,19 @@ module Jekyll
|
|
35
30
|
|
36
31
|
def load_paths
|
37
32
|
@load_paths ||= begin
|
38
|
-
paths = [Jekyll.sanitized_path(
|
39
|
-
paths += javascript_config['load_paths'].map { |load_path| File.expand_path(load_path) } rescue []
|
33
|
+
paths = [Jekyll.sanitized_path(site.source, javascript_dir)]
|
34
|
+
paths += javascript_config['load_paths'].map { |load_path| File.expand_path(load_path, site.source) } rescue []
|
40
35
|
|
41
36
|
if safe?
|
42
|
-
paths.map! { |path| Jekyll.sanitized_path(
|
37
|
+
paths.map! { |path| Jekyll.sanitized_path(site.source, path) }
|
43
38
|
end
|
44
39
|
|
45
|
-
Dir.chdir(
|
40
|
+
Dir.chdir(site.source) do
|
46
41
|
paths = paths.flat_map { |path| Dir.glob(path) }
|
47
42
|
|
48
43
|
paths.map! do |path|
|
49
44
|
if safe?
|
50
|
-
Jekyll.sanitized_path(
|
45
|
+
Jekyll.sanitized_path(site.source, path)
|
51
46
|
else
|
52
47
|
File.expand_path(path)
|
53
48
|
end
|
@@ -55,26 +50,71 @@ module Jekyll
|
|
55
50
|
end
|
56
51
|
|
57
52
|
paths.uniq!
|
58
|
-
paths <<
|
53
|
+
paths << site.theme.javascript_path if site.theme&.javascript_path
|
59
54
|
paths.select { |path| File.directory?(path) }
|
60
55
|
end
|
61
56
|
end
|
62
57
|
|
58
|
+
def matches(ext)
|
59
|
+
ext =~ /^\.js$/i
|
60
|
+
end
|
61
|
+
|
62
|
+
def output_ext(ext = '')
|
63
|
+
'.js'
|
64
|
+
end
|
65
|
+
|
66
|
+
def safe?
|
67
|
+
!!@config['safe']
|
68
|
+
end
|
69
|
+
|
63
70
|
def convert(content)
|
64
|
-
|
65
|
-
Jekyll::Utils.
|
66
|
-
|
67
|
-
|
71
|
+
if generate_source_map?
|
72
|
+
config = Jekyll::Utils.symbolize_hash_keys(
|
73
|
+
Jekyll::Utils.deep_merge_hashes(
|
74
|
+
{ :uglifier => {
|
75
|
+
:source_map => {
|
76
|
+
:map_url => @source_map_page.name,
|
77
|
+
:sources_content => true,
|
78
|
+
:filename => @page.name
|
79
|
+
}
|
80
|
+
}
|
81
|
+
},
|
82
|
+
javascript_config
|
83
|
+
)
|
84
|
+
)
|
85
|
+
|
86
|
+
uglified, source_map = Uglifier.new(config[:uglifier]).compile_with_map(insert_imports(content))
|
87
|
+
|
88
|
+
@source_map_page.source_map(source_map)
|
89
|
+
site.pages << @source_map_page
|
90
|
+
|
91
|
+
uglified
|
92
|
+
else
|
93
|
+
config = Jekyll::Utils.symbolize_hash_keys(
|
94
|
+
Jekyll::Utils.deep_merge_hashes(
|
95
|
+
{ :uglifier => {} },
|
96
|
+
javascript_config
|
97
|
+
)
|
68
98
|
)
|
69
|
-
)
|
70
99
|
|
71
|
-
|
100
|
+
Uglifier.new(config[:uglifier]).compile(insert_imports(content))
|
101
|
+
end
|
72
102
|
end
|
73
103
|
|
74
104
|
private
|
75
105
|
|
106
|
+
def generate_source_map?
|
107
|
+
if @page.nil? || source_map_option.eql?(:never)
|
108
|
+
false
|
109
|
+
elsif source_map_option.eql?(:always)
|
110
|
+
true
|
111
|
+
else
|
112
|
+
:development == source_map_option && source_map_option == Jekyll.env.to_sym
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
76
116
|
def insert_imports(content)
|
77
|
-
content.enum_for(:scan,
|
117
|
+
content.enum_for(:scan, /^\/\/=\s*(\w+)\s+([\w\/\\\-\.:]+)\W*$/).map {
|
78
118
|
{ directive: Regexp.last_match[1],
|
79
119
|
path: Regexp.last_match[2],
|
80
120
|
insert_at: Regexp.last_match.end(0) }
|
@@ -109,6 +149,14 @@ module Jekyll
|
|
109
149
|
|
110
150
|
content
|
111
151
|
end
|
152
|
+
|
153
|
+
def site
|
154
|
+
@site ||= @page.nil? ? Jekyll.sites.last : @page.site
|
155
|
+
end
|
156
|
+
|
157
|
+
def source_map_option
|
158
|
+
javascript_config.fetch('source_map', :always).to_sym
|
159
|
+
end
|
112
160
|
end
|
113
161
|
end
|
114
162
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Jekyll
|
2
|
+
class JsSourceMapPage < Page
|
3
|
+
def initialize(js_page)
|
4
|
+
@site = js_page.site
|
5
|
+
@dir = js_page.dir
|
6
|
+
@data = js_page.data
|
7
|
+
@name = js_page.basename + '.js.map'
|
8
|
+
|
9
|
+
process(@name)
|
10
|
+
Jekyll::Hooks.trigger :pages, :post_init, self
|
11
|
+
end
|
12
|
+
|
13
|
+
def source_map(map)
|
14
|
+
self.content = map
|
15
|
+
end
|
16
|
+
|
17
|
+
def ext
|
18
|
+
'.map'
|
19
|
+
end
|
20
|
+
|
21
|
+
def asset_file?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect
|
26
|
+
"#<#{self.class} @name=#{name.inspect}>"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/jekyll-js-converter.rb
CHANGED
@@ -7,4 +7,20 @@ module JekyllJsConverter
|
|
7
7
|
@javascript_path ||= path_for '_javascript'
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
Jekyll::Hooks.register :pages, :pre_render do |page|
|
12
|
+
if page.is_a?(Jekyll::Page)
|
13
|
+
page.converters.each do |converter|
|
14
|
+
converter.associate_page(page) if converter.is_a?(Jekyll::Converters::Js)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Jekyll::Hooks.register :pages, :post_render do |page|
|
20
|
+
if page.is_a?(Jekyll::Page)
|
21
|
+
page.converters.each do |converter|
|
22
|
+
converter.dissociate_page(page) if converter.is_a?(Jekyll::Converters::Js)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
10
26
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-js-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Susco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: jekyll
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 4.2.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 4.2.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: uglifier
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +89,7 @@ files:
|
|
103
89
|
- lib/jekyll-js-converter.rb
|
104
90
|
- lib/jekyll-js-converter/version.rb
|
105
91
|
- lib/jekyll/converters/js.rb
|
92
|
+
- lib/jekyll/js_source_map_page.rb
|
106
93
|
homepage: https://github.com/dsusco/jekyll-js-converter
|
107
94
|
licenses:
|
108
95
|
- MIT
|
@@ -122,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
109
|
- !ruby/object:Gem::Version
|
123
110
|
version: '0'
|
124
111
|
requirements: []
|
125
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.1.4
|
126
113
|
signing_key:
|
127
114
|
specification_version: 4
|
128
115
|
summary: A JavaScript converter for Jekyll.
|