hyde-page-css 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/generated_page_css_file.rb +35 -0
- data/lib/hyde_page_css/hyde_page_css.rb +130 -0
- data/lib/hyde_page_css.rb +10 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6b19628b2044bbd6587c2c36f3b0af88a08e740d55ca4592b0a0accf893dc41d
|
4
|
+
data.tar.gz: f2c251830627641c2f5968d72a0f6af564ce075f699d44f8bbf7eb7265cc80b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d8558ead6ba03564fc316d7a85a399ca540bab485870c6f6ce68d665d4205b49660ff756cb4a0463bd655cadafe591fcf6f5c0b8ec881b76cc14576f6d292f5
|
7
|
+
data.tar.gz: 562b82f82f0ea3d6ab29492738cd3b8b44de66fcf1e2598d4015ff2a5ffaabd68fd911c40692330963b90a41a7358bc3439aa4572ab030bd9c161fae40d264f5
|
@@ -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,130 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
require_relative 'generated_page_css_file.rb'
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class Renderer
|
6
|
+
def render_layout(output, layout, info)
|
7
|
+
Hyde::Page::Css.new(layout, info).generate
|
8
|
+
|
9
|
+
# TODO Would be nice to call super here instead of cloned logic from Jekyll internals
|
10
|
+
payload["content"] = output
|
11
|
+
payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {})
|
12
|
+
|
13
|
+
render_liquid(
|
14
|
+
layout.content,
|
15
|
+
payload,
|
16
|
+
info,
|
17
|
+
layout.path
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Hyde
|
24
|
+
module Page
|
25
|
+
class Css
|
26
|
+
@@config = {
|
27
|
+
"asset_path" => 'assets/css',
|
28
|
+
"file_output_path" => 'assets/css',
|
29
|
+
"css_minify" => true,
|
30
|
+
"enable" => true,
|
31
|
+
"keep_files" => true
|
32
|
+
}
|
33
|
+
|
34
|
+
def initialize(layout, info)
|
35
|
+
@site = info[:registers][:site]
|
36
|
+
@page = info[:registers][:page]
|
37
|
+
@data = layout.data
|
38
|
+
@config = @site.config.dig('hyde_page_css') || @@config
|
39
|
+
|
40
|
+
@qualified_asset_path = File.join(*[@site.source, @config['asset_path']].compact)
|
41
|
+
|
42
|
+
if config('keep_files') == true
|
43
|
+
@site.config['keep_files'].push(config('file_output_path'))
|
44
|
+
end
|
45
|
+
|
46
|
+
if @page["css"].nil?
|
47
|
+
@page["css"] = []
|
48
|
+
else
|
49
|
+
@page["css"] = [@page["css"]]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def generate
|
54
|
+
return unless config('enable') == true
|
55
|
+
@page["css"].unshift(@data['css'])
|
56
|
+
|
57
|
+
file_groups = flatten_group(@page["css"])
|
58
|
+
|
59
|
+
css_files = []
|
60
|
+
|
61
|
+
for files in file_groups do
|
62
|
+
break if !files&.length
|
63
|
+
|
64
|
+
data = concatenate_files(files.compact)
|
65
|
+
|
66
|
+
next if data == ""
|
67
|
+
|
68
|
+
data = minify(data)
|
69
|
+
file = generate_file(data)
|
70
|
+
css_files << file.url
|
71
|
+
|
72
|
+
# file already exists, so skip writing out the data to disk
|
73
|
+
next if @site.static_files.find { |x| x.name == file.name }
|
74
|
+
|
75
|
+
# place file data into the new file
|
76
|
+
file.file_contents = data
|
77
|
+
|
78
|
+
# assign static file to list for jekyll to render
|
79
|
+
@site.static_files << file
|
80
|
+
end
|
81
|
+
|
82
|
+
# the recursive nature of this will sometimes have duplicate css files
|
83
|
+
@page['css_files'] = css_files.uniq
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def config(*keys)
|
89
|
+
@config.dig(*keys)
|
90
|
+
end
|
91
|
+
|
92
|
+
def flatten_group(arr, acc = [])
|
93
|
+
return [arr] if !arr.last.is_a?(Array)
|
94
|
+
|
95
|
+
acc += [arr.first]
|
96
|
+
acc += flatten_group(arr.last)
|
97
|
+
end
|
98
|
+
|
99
|
+
def concatenate_files(files, data = '')
|
100
|
+
for file in files do
|
101
|
+
# tmp page required to handle anything with frontmatter/yaml header
|
102
|
+
tmp_page = Jekyll::PageWithoutAFile.new(@site, nil, config('asset_path'), file)
|
103
|
+
path = File.join([@qualified_asset_path, file])
|
104
|
+
|
105
|
+
begin
|
106
|
+
file_contents = File.read(path)
|
107
|
+
tmp_page.content = file_contents
|
108
|
+
data << Jekyll::Renderer.new(@site, tmp_page).run()
|
109
|
+
rescue
|
110
|
+
Jekyll.logger.warn('Page CSS Warning:', "Unable to find #{path}")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
data
|
115
|
+
end
|
116
|
+
|
117
|
+
def minify(data)
|
118
|
+
return data if !config('minify') == true
|
119
|
+
|
120
|
+
converter_config = { 'sass' => { 'style' => 'compressed' } }
|
121
|
+
Jekyll::Converters::Scss.new(converter_config).convert(data)
|
122
|
+
end
|
123
|
+
|
124
|
+
def generate_file(data)
|
125
|
+
hashed_file_name = Digest::MD5.hexdigest(data) + '.css'
|
126
|
+
Hyde::Page::GeneratedPageCssFile.new(@site, config('asset_path'), hashed_file_name)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hyde-page-css
|
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-05 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
|
+
description: Hyde Page CSS is a plugin for Jekyll that enables concatenating, processing
|
34
|
+
and caching css files for separate pages.
|
35
|
+
email: email@gregdaynes.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- lib/hyde_page_css.rb
|
41
|
+
- lib/hyde_page_css/generated_page_css_file.rb
|
42
|
+
- lib/hyde_page_css/hyde_page_css.rb
|
43
|
+
homepage: https://github.com/gregdaynes/hyde-page-css
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.4.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Plugin for jekyll to enable per page css files
|
66
|
+
test_files: []
|