jekyll-tidy 0.0.1 → 0.2.0
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 +4 -4
- data/.travis.yml +5 -0
- data/LICENSE.txt +17 -18
- data/README.md +56 -11
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/jekyll-tidy.gemspec +12 -8
- data/lib/jekyll/tidy.rb +47 -33
- data/lib/jekyll/tidy/version.rb +1 -1
- metadata +27 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c805bb34d487c1a46119f92371bebe325adc9832
|
4
|
+
data.tar.gz: fb1e1beb9d82ddab33e6b47996689d09ca264483
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad9d1ddccf895a04e817699c37597340d4c756eaa49825be958b3250289cdee1f4f6dd2049ed10ccef1a4c7bf816477270a5e39b051f39e7df95fb46bfd42a42
|
7
|
+
data.tar.gz: 415b64fbbdd4f2035061c5208bfd86fc9f756623880e8fca26b386d7e4ea9ba2e3799ce346496ea4ab77abb1ea1fcd782aa6f2bf5656a1443771336984fbe39b
|
data/.travis.yml
ADDED
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2017 Wyatt Kirby
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
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:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
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
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
# Jekyll::Tidy
|
2
2
|
|
3
|
+
[](https://travis-ci.org/apsislabs/jekyll-tidy)
|
4
|
+
|
3
5
|
`jekyll-tidy` is a plugin for tidying the HTML output of your Jekyll website, using either `htmlbeautifier` or `htmlcompressor`.
|
4
6
|
|
5
7
|
## Usage
|
6
8
|
|
7
9
|
Usage is straightforward. Simply include the gem in your `Gemfile` with:
|
8
10
|
|
9
|
-
```
|
10
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'jekyll-tidy'
|
11
13
|
```
|
12
14
|
|
13
15
|
And then include the plugin in a file located in your `_plugins` directory. You can also include the plugin using the `gems` option in your `_config.yml` file, like so:
|
14
16
|
|
15
17
|
```
|
16
|
-
|
18
|
+
gems: [jekyll-tidy]
|
17
19
|
```
|
18
20
|
|
19
21
|
**Note**: if you set the `compress_html` option to `true` and your templates have inline CSS or javascript, it will not be minified.
|
@@ -23,15 +25,58 @@ And then include the plugin in a file located in your `_plugins` directory. You
|
|
23
25
|
`jekyll-tidy` takes two configuration settings, an array of files to exclude, and a flag for whether or not to compress the HTML output.
|
24
26
|
|
25
27
|
```
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
jekyll_tidy:
|
29
|
+
exclude: ["index.html"]
|
30
|
+
compress_html: true
|
31
|
+
ignore_env: development
|
32
|
+
```
|
33
|
+
|
34
|
+
### exclude (default: [])
|
35
|
+
|
36
|
+
`exclude` is an array of relative file paths that will be ignored by `jekyll-tidy`. Exclude must be set as an array, or it will cause errors.
|
37
|
+
|
38
|
+
```
|
39
|
+
exclude: ["index.html"] # excludes only index.html
|
29
40
|
```
|
30
41
|
|
42
|
+
`exclude` can also take a glob of file paths. *Note:* File globs must be wrapped with `""`.
|
43
|
+
|
44
|
+
```
|
45
|
+
exclude: ["_posts/*.md"] # excludes all markdown files directly within the posts directory.
|
46
|
+
exclude: ["_posts/**/*.md"] # excludes all markdown files anywhere within the _posts directory
|
47
|
+
```
|
48
|
+
|
49
|
+
### compress_html (default: false)
|
50
|
+
|
51
|
+
If `compress_html` is set to `true` then `htmlcompressor` will be used to tidy the markup. If it
|
52
|
+
is set to `false` then `htmlbeautifier` will be used to tidy the markup.
|
53
|
+
|
54
|
+
### ignore_env (default: nil)
|
55
|
+
|
56
|
+
If `ignore_env` is set to a string, we will check the `JEKYLL_ENV` environment variable and skip tidying if it matches. Setting `_config.yml` with:
|
57
|
+
|
58
|
+
```
|
59
|
+
ignore_env: development
|
60
|
+
```
|
61
|
+
|
62
|
+
And then running jekyll with:
|
63
|
+
|
64
|
+
```sh
|
65
|
+
$ JEKYLL_ENV=development jekyll serve
|
66
|
+
```
|
67
|
+
|
68
|
+
Will skip all tidying.
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
|
+
|
74
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
31
76
|
## Contributing
|
32
77
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/apsislabs/jekyll-tidy.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jekyll/tidy"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/jekyll-tidy.gemspec
CHANGED
@@ -8,19 +8,23 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Jekyll::Tidy::VERSION
|
9
9
|
spec.authors = ["Wyatt Kirby"]
|
10
10
|
spec.email = ["wyatt@apsis.io"]
|
11
|
+
|
11
12
|
spec.summary = %q{Sanitize and Tidy HTML Output for Jekyll}
|
12
13
|
spec.homepage = "http://www.apsis.io"
|
13
14
|
spec.license = "MIT"
|
14
15
|
|
15
|
-
spec.files = `git ls-files -z`.split("\x0")
|
16
|
-
|
17
|
-
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
21
|
spec.require_paths = ["lib"]
|
19
22
|
|
20
|
-
spec.
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
+
spec.add_runtime_dependency "jekyll"
|
24
|
+
spec.add_runtime_dependency "htmlbeautifier"
|
25
|
+
spec.add_runtime_dependency "htmlcompressor"
|
23
26
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.
|
25
|
-
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
30
|
end
|
data/lib/jekyll/tidy.rb
CHANGED
@@ -1,45 +1,59 @@
|
|
1
|
+
require "jekyll/tidy/version"
|
2
|
+
|
1
3
|
require "jekyll"
|
2
4
|
require "htmlbeautifier"
|
3
5
|
require "htmlcompressor"
|
4
6
|
|
5
|
-
JEKYLL_CONFIG = Jekyll.configuration({})
|
6
|
-
|
7
7
|
module Jekyll
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def self.output_clean(output)
|
25
|
-
if compress_html?
|
26
|
-
compressor = HtmlCompressor::Compressor.new
|
27
|
-
return compressor.compress output
|
28
|
-
else
|
29
|
-
return HtmlBeautifier.beautify output
|
30
|
-
end
|
31
|
-
end
|
8
|
+
module Tidy
|
9
|
+
def self.init(site)
|
10
|
+
@JEKYLL_CONFIG = site.config
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.jekyll_config
|
14
|
+
@JEKYLL_CONFIG || Jekyll.configuration({})
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.exclude?(path, override = {})
|
18
|
+
exclude_paths = jekyll_config.merge(override).dig("jekyll_tidy", "exclude").to_a
|
19
|
+
exclude_paths.any? { |exclude| File.fnmatch(exclude, path) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.compress_output?
|
23
|
+
jekyll_config.dig("jekyll_tidy", "compress_html")
|
32
24
|
end
|
33
|
-
end
|
34
25
|
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
def self.output_clean(output, compress = false)
|
27
|
+
if compress
|
28
|
+
return HtmlCompressor::Compressor.new.compress output
|
29
|
+
else
|
30
|
+
return HtmlBeautifier.beautify output
|
31
|
+
end
|
38
32
|
end
|
33
|
+
|
34
|
+
def self.ignore_env?
|
35
|
+
Jekyll.env == jekyll_config.dig("jekyll_tidy", "ignore_env")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Jekyll Hooks
|
41
|
+
# -------------------------------------
|
42
|
+
|
43
|
+
Jekyll::Hooks.register :site, :after_reset do |jekyll|
|
44
|
+
Jekyll::Tidy.init(jekyll)
|
45
|
+
end
|
46
|
+
|
47
|
+
Jekyll::Hooks.register :documents, :post_render do |doc|
|
48
|
+
next if Jekyll::Tidy.ignore_env?
|
49
|
+
unless Jekyll::Tidy::exclude?(doc.relative_path)
|
50
|
+
doc.output = Jekyll::Tidy::output_clean(doc.output, Jekyll::Tidy.compress_output?)
|
51
|
+
end
|
39
52
|
end
|
40
53
|
|
41
54
|
Jekyll::Hooks.register :pages, :post_render do |page|
|
42
|
-
|
43
|
-
|
44
|
-
|
55
|
+
next if Jekyll::Tidy.ignore_env?
|
56
|
+
unless Jekyll::Tidy::exclude?(page.relative_path)
|
57
|
+
page.output = Jekyll::Tidy::output_clean(page.output, Jekyll::Tidy.compress_output?)
|
58
|
+
end
|
45
59
|
end
|
data/lib/jekyll/tidy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-tidy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wyatt Kirby
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -58,28 +58,42 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
61
|
+
version: '1.14'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
68
|
+
version: '1.14'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '10.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- wyatt@apsis.io
|
@@ -88,10 +102,13 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
91
106
|
- Gemfile
|
92
107
|
- LICENSE.txt
|
93
108
|
- README.md
|
94
109
|
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
95
112
|
- jekyll-tidy.gemspec
|
96
113
|
- lib/jekyll-tidy.rb
|
97
114
|
- lib/jekyll/tidy.rb
|
@@ -116,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
133
|
version: '0'
|
117
134
|
requirements: []
|
118
135
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.6.8
|
120
137
|
signing_key:
|
121
138
|
specification_version: 4
|
122
139
|
summary: Sanitize and Tidy HTML Output for Jekyll
|