hyde-page-js 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/hyde/page/css.rb +131 -0
- data/lib/hyde/page/generated_page_css_file.rb +35 -0
- data/lib/hyde/renderer.rb +18 -0
- data/lib/hyde-page-js.rb +11 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad8c15a48cdb354d8445e0cc30b9d4ba2544b6afb510cd79426a42a76a8d883c
|
4
|
+
data.tar.gz: b367b416ff3bf8925cfe2c0eeec958111a0144a306aeab1fd030cbb330759bf1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec5049e2ab3676ecbe9b1b606a3eaf1806aeac25d8543671219a6eb7c422b5e12fdfa732d11e730efd7e31c0afa09c396c1e04bd6c0e06f485961ced4c78ca19
|
7
|
+
data.tar.gz: fca64106f4a05093fc2fc3d0787b4ec115beab21482c7d4e4a4898e1a6393f78224d3b785599794eb823969f6f028978728bcee24569adeb153bede1929d564d
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
require_relative "generated_page_css_file"
|
3
|
+
|
4
|
+
module Hyde
|
5
|
+
module Page
|
6
|
+
class Css
|
7
|
+
@@config = {
|
8
|
+
"asset_path" => "assets/css",
|
9
|
+
"file_output_path" => "assets/css",
|
10
|
+
"css_minify" => true,
|
11
|
+
"enable" => true,
|
12
|
+
"keep_files" => true,
|
13
|
+
"dev_mode" => false
|
14
|
+
}
|
15
|
+
|
16
|
+
def initialize(layout, info)
|
17
|
+
@site = info[:registers][:site]
|
18
|
+
@page = info[:registers][:page]
|
19
|
+
@data = layout.data
|
20
|
+
@config = @@config.merge(@site.config.dig("hyde_page_css") || {})
|
21
|
+
|
22
|
+
@qualified_asset_path = File.join(*[@site.source, @config["asset_path"]].compact)
|
23
|
+
|
24
|
+
if config("keep_files") == true && config("dev_mode") == false
|
25
|
+
@site.config["keep_files"].push(config("file_output_path"))
|
26
|
+
end
|
27
|
+
|
28
|
+
@page["css"] = if @page["css"].nil?
|
29
|
+
[]
|
30
|
+
else
|
31
|
+
[@page["css"]]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def generate
|
36
|
+
return unless config("enable") == true
|
37
|
+
@page["css"].unshift(@data["css"])
|
38
|
+
|
39
|
+
file_groups = flatten_group(@page["css"])
|
40
|
+
|
41
|
+
css_files = []
|
42
|
+
|
43
|
+
for files in file_groups do
|
44
|
+
break if !files&.length
|
45
|
+
|
46
|
+
data = concatenate_files(files.compact)
|
47
|
+
data = minify(data)
|
48
|
+
next if data == ""
|
49
|
+
|
50
|
+
file = generate_file(files, data)
|
51
|
+
css_files << file.url
|
52
|
+
|
53
|
+
# file already exists, so skip writing out the data to disk
|
54
|
+
next if @site.static_files.find { |x| x.name == file.name }
|
55
|
+
|
56
|
+
# place file data into the new file
|
57
|
+
file.file_contents = data
|
58
|
+
|
59
|
+
# assign static file to list for jekyll to render
|
60
|
+
@site.static_files << file
|
61
|
+
end
|
62
|
+
|
63
|
+
# the recursive nature of this will sometimes have duplicate css files
|
64
|
+
@page["css_files"] = css_files.uniq
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def config(*)
|
70
|
+
@config.dig(*)
|
71
|
+
end
|
72
|
+
|
73
|
+
def flatten_group(arr, acc = [])
|
74
|
+
return [arr] if !arr.last.is_a?(Array)
|
75
|
+
|
76
|
+
acc += [arr.first]
|
77
|
+
acc += flatten_group(arr.last)
|
78
|
+
end
|
79
|
+
|
80
|
+
def concatenate_files(files, data = "")
|
81
|
+
for file in files do
|
82
|
+
# tmp page required to handle anything with frontmatter/yaml header
|
83
|
+
tmp_page = Jekyll::PageWithoutAFile.new(@site, nil, config("asset_path"), file)
|
84
|
+
path = File.join([@qualified_asset_path, file])
|
85
|
+
|
86
|
+
begin
|
87
|
+
file_contents = File.read(path)
|
88
|
+
tmp_page.content = file_contents
|
89
|
+
# original jekyll renderer, not our modified version
|
90
|
+
data << Jekyll::Renderer.new(@site, tmp_page).run
|
91
|
+
rescue
|
92
|
+
Jekyll.logger.warn("Page CSS Warning:", "Unable to find #{path}")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
data
|
97
|
+
end
|
98
|
+
|
99
|
+
def minify(data)
|
100
|
+
style = if config("dev_mode") == true
|
101
|
+
"expanded"
|
102
|
+
elsif config("css_minify") == false
|
103
|
+
"expanded"
|
104
|
+
else
|
105
|
+
"compressed"
|
106
|
+
end
|
107
|
+
|
108
|
+
converter_config = {"sass" => {"style" => style}}
|
109
|
+
Jekyll::Converters::Scss.new(converter_config).convert(data)
|
110
|
+
end
|
111
|
+
|
112
|
+
def generate_file(files, data)
|
113
|
+
file_name = generate_file_name(files, data)
|
114
|
+
|
115
|
+
Hyde::Page::GeneratedPageCssFile.new(@site, config("asset_path"), file_name)
|
116
|
+
end
|
117
|
+
|
118
|
+
def generate_file_name(files, data, prefix: nil)
|
119
|
+
file_names = [prefix]
|
120
|
+
|
121
|
+
if config("dev_mode")
|
122
|
+
files.each { |file| file_names.push(file.gsub(".css", "")) }
|
123
|
+
end
|
124
|
+
|
125
|
+
file_names.push(Digest::MD5.hexdigest(data)[0, 6])
|
126
|
+
|
127
|
+
file_names.compact.join("-") + ".css"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Hyde
|
2
|
+
module Page
|
3
|
+
# Alternative class for jekyll's static files
|
4
|
+
# this allows the creation of files without a source file
|
5
|
+
|
6
|
+
class GeneratedPageCssFile < Jekyll::StaticFile
|
7
|
+
attr_accessor :file_contents
|
8
|
+
attr_reader :generator
|
9
|
+
|
10
|
+
def initialize(site, dir, name)
|
11
|
+
@site = site
|
12
|
+
@dir = dir
|
13
|
+
@name = name
|
14
|
+
@relative_path = File.join(*[@dir, @name].compact)
|
15
|
+
@extname = File.extname(@name)
|
16
|
+
@type = @collection&.label&.to_sym
|
17
|
+
@generator = "hyde-page-css"
|
18
|
+
end
|
19
|
+
|
20
|
+
def write(dest)
|
21
|
+
dest_path = destination(dest)
|
22
|
+
return false if File.exist?(dest_path)
|
23
|
+
|
24
|
+
FileUtils.mkdir_p(File.dirname(dest_path))
|
25
|
+
FileUtils.rm(dest_path) if File.exist?(dest_path)
|
26
|
+
|
27
|
+
File.open(dest_path, "w") do |output_file|
|
28
|
+
output_file << file_contents
|
29
|
+
end
|
30
|
+
|
31
|
+
true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Jekyll
|
2
|
+
class Renderer
|
3
|
+
def render_layout(output, layout, info)
|
4
|
+
Hyde::Page::Css.new(layout, info).generate
|
5
|
+
|
6
|
+
# TODO Would be nice to call super here instead of cloned logic from Jekyll internals
|
7
|
+
payload["content"] = output
|
8
|
+
payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {})
|
9
|
+
|
10
|
+
render_liquid(
|
11
|
+
layout.content,
|
12
|
+
payload,
|
13
|
+
info,
|
14
|
+
layout.path
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/hyde-page-js.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hyde-page-js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregory Daynes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-12-25 00:00:00.000000000 Z
|
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.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: terser
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.1'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.1'
|
47
|
+
description: Hyde Page JS is a plugin for Jekyll that enables concatenating, processing
|
48
|
+
and caching js files for separate pages.
|
49
|
+
email: email@gregdaynes.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/hyde-page-js.rb
|
55
|
+
- lib/hyde/page/css.rb
|
56
|
+
- lib/hyde/page/generated_page_css_file.rb
|
57
|
+
- lib/hyde/renderer.rb
|
58
|
+
homepage: https://github.com/gregdaynes/hyde-page-js
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubygems_version: 3.4.10
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Plugin for jekyll to enable per page js files
|
81
|
+
test_files: []
|