jekyll-vibrantjs 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/LICENSE.md +26 -0
- data/README.md +134 -0
- data/jekyll-vibrantjs.gemspec +17 -0
- data/lib/jekyll-vibrantjs.rb +9 -0
- data/lib/jekyll-vibrantjs/call-vibrant.js +18 -0
- data/lib/jekyll-vibrantjs/jekyll-vibrantjs-tag.rb +48 -0
- data/lib/jekyll-vibrantjs/version.rb +5 -0
- data/lib/jekyll-vibrantjs/vibrantjs-css.html +30 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e22b638bd2a77a8eb1a6554dcc9555ca59680c43
|
4
|
+
data.tar.gz: ccdbd507f74cf8056e800c82d75d8eaf6a5ed592
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e69828ef28a95bc56a1509c4f20483dd26a6d6437246227a7f483bea4decc52b73625d3e020ac255001b3b193df36fb709c7c95283032db211d32cfae8377718
|
7
|
+
data.tar.gz: c4a322c6be0575f395de5ef43a4777bc8c7d14aafd21a9f5d68636074691cca92244029ff055eb939db181540ec3130f8f01a39b6268b59e9e4635f58d74c329
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Documentation cache and generated files:
|
17
|
+
/.yardoc/
|
18
|
+
/_yardoc/
|
19
|
+
/doc/
|
20
|
+
/rdoc/
|
21
|
+
|
22
|
+
## Environment normalization:
|
23
|
+
/.bundle/
|
24
|
+
/vendor/bundle
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
.ruby-version
|
31
|
+
.ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/LICENSE.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# DON'T BE A DICK PUBLIC LICENSE
|
2
|
+
|
3
|
+
> Version 1.1, December 2016
|
4
|
+
|
5
|
+
> Copyright (C) 2019 WarrantyNowVoid.com
|
6
|
+
|
7
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
8
|
+
copies of this license document.
|
9
|
+
|
10
|
+
> DON'T BE A DICK PUBLIC LICENSE
|
11
|
+
> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
12
|
+
|
13
|
+
1. Do whatever you like with the original work, just don't be a dick.
|
14
|
+
|
15
|
+
Being a dick includes - but is not limited to - the following instances:
|
16
|
+
|
17
|
+
1a. Outright copyright infringement - Don't just copy the original work/works and change the name.
|
18
|
+
1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
|
19
|
+
1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
|
20
|
+
|
21
|
+
2. If you become rich through modifications, related works/services, or supporting the original work,
|
22
|
+
share the love. Only a dick would make loads off this work and not buy the original work's
|
23
|
+
creator(s) a pint.
|
24
|
+
|
25
|
+
3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
|
26
|
+
you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back or submit a [bug report](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html)
|
data/README.md
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# Jekyll Vibrantjs
|
2
|
+
|
3
|
+
Generate a set of CSS override rules from a template based on the prominent colors from a given image.
|
4
|
+
|
5
|
+
## Why?
|
6
|
+
|
7
|
+
Doesn't Vibrantjs have an in-browser library that can do all this in real time? Yes, but with Jekyll we have an opportunity to do all the work to generate the entire static site before even deploying it to the web. So if we're using these colors to theme static pages, why *wouldn't* we take advantage of that, rather than potentially putting all that work on the browser, eating up users' batteries, or even showing the un-themed version for a few seconds before processing is completed.
|
8
|
+
|
9
|
+
## Prerequisites
|
10
|
+
|
11
|
+
Requires `node-vibrant` installed (<https://github.com/akfish/node-vibrant/>).
|
12
|
+
|
13
|
+
### Installing `node-vibrant` in your jekyll project
|
14
|
+
|
15
|
+
If you have an existing `package.json`, just add it there and run `npm install`. Otherwise, at the root level of your project, run `npm install node-vibrant` (and remember to add `node_modules` to your `.gitignore` file and check in the new `package-lock.json`).
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
(https://jekyllrb.com/docs/plugins/installation/)
|
20
|
+
|
21
|
+
One of two options:
|
22
|
+
|
23
|
+
### Bundler Config
|
24
|
+
:warning: **If using bundler with a vendor prefix, this is the required method**
|
25
|
+
|
26
|
+
1. In your `Gemfile`, add the `jekyll_plugins` group if it doesn't already exist, and add `jekyll-vibrantjs` to it. For example:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
group :jekyll_plugins do
|
30
|
+
gem "jekyll-vibrantjs"
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
2. Tell bundler to install any plugins with
|
35
|
+
|
36
|
+
```
|
37
|
+
$ bundle install
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
### Jekyll Config
|
42
|
+
|
43
|
+
1. In your `_config.yml`, add the `plugins` key if it doesn't already exist, and add a value of `jekyll-vibrantjs`. For example:
|
44
|
+
|
45
|
+
```yaml
|
46
|
+
plugins:
|
47
|
+
- jekyll-vibrantjs
|
48
|
+
```
|
49
|
+
|
50
|
+
2. Install this gem
|
51
|
+
|
52
|
+
```
|
53
|
+
$ gem install jekyll-vibrantjs
|
54
|
+
```
|
55
|
+
|
56
|
+
## Usage
|
57
|
+
|
58
|
+
### Tag
|
59
|
+
|
60
|
+
Wherever you want to generate the set of CSS rules, add the `vibrantjs` tag with a path (relative to the Jekyll project root) to the image you want colors extracted from.
|
61
|
+
|
62
|
+
As a string:
|
63
|
+
|
64
|
+
```
|
65
|
+
{% vibrantjs "assets/img/mycoolphoto.jpg" %}
|
66
|
+
```
|
67
|
+
|
68
|
+
From frontmatter:
|
69
|
+
|
70
|
+
```
|
71
|
+
{% vibrantjs post.image.feature %}
|
72
|
+
```
|
73
|
+
|
74
|
+
Or just a variable:
|
75
|
+
|
76
|
+
```
|
77
|
+
{% assign the_image = "assets/pictures_of_butts/butt.png" %}
|
78
|
+
...
|
79
|
+
{% vibrantjs the_image %}
|
80
|
+
```
|
81
|
+
|
82
|
+
### CSS Output
|
83
|
+
|
84
|
+
At build time, this tag will be replaced with CSS using the colors extracted from the given image. The default CSS template will generate a style tag containing override (using `!important`) class rules for each of the six extracted colors to be used as a CSS `color` property or `background-color`, including `:hover` states. For example:
|
85
|
+
|
86
|
+
```html
|
87
|
+
<style type="text/css">
|
88
|
+
/* background-color */
|
89
|
+
.background-color-vibrant{ background-color: rgba(124, 76, 36, 1) !important; }
|
90
|
+
.background-color-light-vibrant{ background-color: rgba(252, 252, 204, 1) !important; }
|
91
|
+
.background-color-dark-vibrant{ background-color: rgba(4, 52, 100, 1) !important; }
|
92
|
+
.background-color-muted{ background-color: rgba(104, 132, 164, 1) !important; }
|
93
|
+
.background-color-light-muted{ background-color: rgba(190, 190, 157, 1) !important; }
|
94
|
+
.background-color-dark-muted{ background-color: rgba(63, 63, 61, 1) !important; }
|
95
|
+
/* background-color :hover */
|
96
|
+
.hover-background-color-vibrant:hover{ background-color: rgba(124, 76, 36, 1) !important; }
|
97
|
+
.hover-background-color-light-vibrant:hover{ background-color: rgba(252, 252, 204, 1) !important; }
|
98
|
+
.hover-background-color-dark-vibrant:hover{ background-color: rgba(4, 52, 100, 1) !important; }
|
99
|
+
.hover-background-color-muted:hover{ background-color: rgba(104, 132, 164, 1) !important; }
|
100
|
+
.hover-background-color-light-muted:hover{ background-color: rgba(190, 190, 157, 1) !important; }
|
101
|
+
.hover-background-color-dark-muted:hover{ background-color: rgba(63, 63, 61, 1) !important; }
|
102
|
+
/* color */
|
103
|
+
.color-vibrant{ color: rgba(124, 76, 36, 1) !important; }
|
104
|
+
.color-light-vibrant{ color: rgba(252, 252, 204, 1) !important; }
|
105
|
+
.color-dark-vibrant{ color: rgba(4, 52, 100, 1) !important; }
|
106
|
+
.color-muted{ color: rgba(104, 132, 164, 1) !important; }
|
107
|
+
.color-light-muted{ color: rgba(190, 190, 157, 1) !important; }
|
108
|
+
.color-dark-muted{ color: rgba(63, 63, 61, 1) !important; }
|
109
|
+
/* color :hover */
|
110
|
+
.hover-color-vibrant:hover{ color: rgba(124, 76, 36, 1) !important; }
|
111
|
+
.hover-color-light-vibrant:hover{ color: rgba(252, 252, 204, 1) !important; }
|
112
|
+
.hover-color-dark-vibrant:hover{ color: rgba(4, 52, 100, 1) !important; }
|
113
|
+
.hover-color-muted:hover{ color: rgba(104, 132, 164, 1) !important; }
|
114
|
+
.hover-color-light-muted:hover{ color: rgba(190, 190, 157, 1) !important; }
|
115
|
+
.hover-color-dark-muted:hover{ color: rgba(63, 63, 61, 1) !important; }
|
116
|
+
</style>
|
117
|
+
```
|
118
|
+
|
119
|
+
Use these classes in your HTML to dynamically change these colors for some particular image source.
|
120
|
+
|
121
|
+
### Custom Template
|
122
|
+
|
123
|
+
You can specify a custom template by adding a file named `_includes/vibrantjs-css.html` in your jekyll project. All six colors' rgb values (ex: `rgba(104, 132, 164, 1)`) are available as template variables with the prefix "rgb" to use like `{{ rgbDarkVibrant }}`.
|
124
|
+
|
125
|
+
### Colors
|
126
|
+
|
127
|
+
Six colors are available (see <https://jariz.github.io/vibrant.js/> for examples):
|
128
|
+
|
129
|
+
- Vibrant
|
130
|
+
- LightVibrant
|
131
|
+
- DarkVibrant
|
132
|
+
- Muted
|
133
|
+
- LightMuted
|
134
|
+
- DarkMuted
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "jekyll-vibrantjs/version"
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jekyll-vibrantjs"
|
7
|
+
spec.summary = "Extract image colors to CSS"
|
8
|
+
spec.description = "Jekyll plugin to generate CSS overrides based on Vibrant.js colors extracted from a given image"
|
9
|
+
spec.version = Jekyll::VibrantJS::VERSION
|
10
|
+
spec.authors = ["Nick Pettazzoni"]
|
11
|
+
spec.email = ["pettazz@gmail.com"]
|
12
|
+
spec.homepage = "https://github.com/warrantynowvoid/jekyll-vibrantjs"
|
13
|
+
spec.licenses = ["Nonstandard"]
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
spec.add_dependency "jekyll", "~> 3.0"
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
var Vibrant = require('node-vibrant')
|
2
|
+
|
3
|
+
const imagePath = process.argv[2];
|
4
|
+
let v = new Vibrant(imagePath, {quality: 1});
|
5
|
+
v.getPalette((err, palette) => {
|
6
|
+
console.log('{');
|
7
|
+
for(let swatch in palette){
|
8
|
+
console.log(`"${swatch}" => "${toRGBAString(palette[swatch].getRgb())}",`);
|
9
|
+
}
|
10
|
+
console.log('}');
|
11
|
+
});
|
12
|
+
|
13
|
+
const toRGBAString = (colorArr) => {
|
14
|
+
return 'rgba(' +
|
15
|
+
colorArr[0] + ', ' +
|
16
|
+
colorArr[1] + ', ' +
|
17
|
+
colorArr[2] + ', 1)';
|
18
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module VibrantJS
|
3
|
+
class VibrantJSTag < Liquid::Tag
|
4
|
+
|
5
|
+
def initialize(tagName, image_arg, tokens)
|
6
|
+
super
|
7
|
+
@image_arg = image_arg
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(context)
|
11
|
+
# if we pass in something like "post.image.feature" instead of a path,
|
12
|
+
# the variable name gets passed in as a string, so we can look it up in the context
|
13
|
+
image_path = "#{context[@image_arg.strip]}"
|
14
|
+
|
15
|
+
if File.exist?(image_path)
|
16
|
+
script_path = File.expand_path('./call-vibrant.js', File.dirname(__FILE__))
|
17
|
+
node_modules_path = File.join Dir.pwd, "node_modules"
|
18
|
+
|
19
|
+
stdout, status = Open3.capture2({"NODE_PATH" => node_modules_path}, 'node', script_path, image_path)
|
20
|
+
|
21
|
+
raise "Failed to call vibrantjs" unless status.success?
|
22
|
+
else
|
23
|
+
raise "Given image file `#{image_path}` doesn't exist"
|
24
|
+
end
|
25
|
+
|
26
|
+
@palette = eval(stdout)
|
27
|
+
|
28
|
+
tmpl_path = File.join Dir.pwd, "_includes", "vibrantjs-css.html"
|
29
|
+
unless File.exist?(tmpl_path)
|
30
|
+
tmpl_path = File.expand_path('./vibrantjs-css.html', File.dirname(__FILE__))
|
31
|
+
end
|
32
|
+
|
33
|
+
tmpl = File.read tmpl_path
|
34
|
+
site = context.registers[:site]
|
35
|
+
tmpl = (Liquid::Template.parse tmpl).render site.site_payload.merge!({
|
36
|
+
"rgbVibrant" => @palette["Vibrant"],
|
37
|
+
"rgbLightVibrant" => @palette["LightVibrant"],
|
38
|
+
"rgbDarkVibrant" => @palette["DarkVibrant"],
|
39
|
+
"rgbMuted" => @palette["Muted"],
|
40
|
+
"rgbLightMuted" => @palette["LightMuted"],
|
41
|
+
"rgbDarkMuted" => @palette["DarkMuted"]
|
42
|
+
})
|
43
|
+
end
|
44
|
+
|
45
|
+
Liquid::Template.register_tag "vibrantjs", self
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<style type="text/css">
|
2
|
+
/* background-color */
|
3
|
+
.background-color-vibrant{ background-color: {{ rgbVibrant }} !important; }
|
4
|
+
.background-color-light-vibrant{ background-color: {{ rgbLightVibrant }} !important; }
|
5
|
+
.background-color-dark-vibrant{ background-color: {{ rgbDarkVibrant }} !important; }
|
6
|
+
.background-color-muted{ background-color: {{ rgbMuted }} !important; }
|
7
|
+
.background-color-light-muted{ background-color: {{ rgbLightMuted }} !important; }
|
8
|
+
.background-color-dark-muted{ background-color: {{ rgbDarkMuted }} !important; }
|
9
|
+
/* background-color :hover */
|
10
|
+
.hover-background-color-vibrant:hover{ background-color: {{ rgbVibrant }} !important; }
|
11
|
+
.hover-background-color-light-vibrant:hover{ background-color: {{ rgbLightVibrant }} !important; }
|
12
|
+
.hover-background-color-dark-vibrant:hover{ background-color: {{ rgbDarkVibrant }} !important; }
|
13
|
+
.hover-background-color-muted:hover{ background-color: {{ rgbMuted }} !important; }
|
14
|
+
.hover-background-color-light-muted:hover{ background-color: {{ rgbLightMuted }} !important; }
|
15
|
+
.hover-background-color-dark-muted:hover{ background-color: {{ rgbDarkMuted }} !important; }
|
16
|
+
/* color */
|
17
|
+
.color-vibrant{ color: {{ rgbVibrant }} !important; }
|
18
|
+
.color-light-vibrant{ color: {{ rgbLightVibrant }} !important; }
|
19
|
+
.color-dark-vibrant{ color: {{ rgbDarkVibrant }} !important; }
|
20
|
+
.color-muted{ color: {{ rgbMuted }} !important; }
|
21
|
+
.color-light-muted{ color: {{ rgbLightMuted }} !important; }
|
22
|
+
.color-dark-muted{ color: {{ rgbDarkMuted }} !important; }
|
23
|
+
/* color :hover */
|
24
|
+
.hover-color-vibrant:hover{ color: {{ rgbVibrant }} !important; }
|
25
|
+
.hover-color-light-vibrant:hover{ color: {{ rgbLightVibrant }} !important; }
|
26
|
+
.hover-color-dark-vibrant:hover{ color: {{ rgbDarkVibrant }} !important; }
|
27
|
+
.hover-color-muted:hover{ color: {{ rgbMuted }} !important; }
|
28
|
+
.hover-color-light-muted:hover{ color: {{ rgbLightMuted }} !important; }
|
29
|
+
.hover-color-dark-muted:hover{ color: {{ rgbDarkMuted }} !important; }
|
30
|
+
</style>
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-vibrantjs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Pettazzoni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-11 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: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: Jekyll plugin to generate CSS overrides based on Vibrant.js colors extracted
|
28
|
+
from a given image
|
29
|
+
email:
|
30
|
+
- pettazz@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- LICENSE.md
|
37
|
+
- README.md
|
38
|
+
- jekyll-vibrantjs.gemspec
|
39
|
+
- lib/jekyll-vibrantjs.rb
|
40
|
+
- lib/jekyll-vibrantjs/call-vibrant.js
|
41
|
+
- lib/jekyll-vibrantjs/jekyll-vibrantjs-tag.rb
|
42
|
+
- lib/jekyll-vibrantjs/version.rb
|
43
|
+
- lib/jekyll-vibrantjs/vibrantjs-css.html
|
44
|
+
homepage: https://github.com/warrantynowvoid/jekyll-vibrantjs
|
45
|
+
licenses:
|
46
|
+
- Nonstandard
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.6.14
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Extract image colors to CSS
|
68
|
+
test_files: []
|