jekyll-avatar 0.5.0 → 0.8.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 +5 -5
- data/README.md +19 -5
- data/lib/jekyll-avatar/version.rb +2 -1
- data/lib/jekyll-avatar.rb +102 -29
- metadata +59 -30
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/.rubocop.yml +0 -16
- data/.ruby-version +0 -1
- data/.travis.yml +0 -7
- data/Gemfile +0 -6
- data/Rakefile +0 -8
- data/jekyll-avatar.gemspec +0 -29
- data/script/bootstrap +0 -5
- data/script/cibuild +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 59a9a3637415d5b08eab35b0c56c43282eb55d0d068ecbcee79e7aefb38af288
|
4
|
+
data.tar.gz: ae037ea80d6f45c2443a7cfa560633cd32dd6de06476083e48abf898e41e5cb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a3d603193c1c92e9b98a78f58899b4c2d6ae39666509a87f4ab43028ae993c4901246a644b45406955b19acbab58072d2e26cf6973b44988c269659a717101e
|
7
|
+
data.tar.gz: 7f1a6ca837d81f451acf8a86d4ee6560734978e5b2071163424ad8a9f1ec2babae36678aef9e421eb50245276814b22ece3434e653f8f9f7e43b49e65a5082d6
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
*A Jekyll plugin for rendering GitHub avatars*
|
4
4
|
|
5
|
-
[](https://github.com/jekyll/jekyll-avatar/actions/workflows/ci.yml)
|
6
6
|
|
7
7
|
Jekyll Avatar makes it easy to add GitHub avatars to your Jekyll site by specifying a username. If performance is a concern, Jekyll Avatar is deeply integrated with the GitHub avatar API, ensuring avatars are cached and load in parallel. It even automatically upgrades users to Retina images, when supported.
|
8
8
|
|
@@ -17,9 +17,10 @@ gem 'jekyll-avatar'
|
|
17
17
|
And add the following to your site's `_config.yml` file:
|
18
18
|
|
19
19
|
```yaml
|
20
|
-
|
20
|
+
plugins:
|
21
21
|
- jekyll-avatar
|
22
22
|
```
|
23
|
+
Note: If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`.
|
23
24
|
|
24
25
|
## Usage
|
25
26
|
|
@@ -60,8 +61,8 @@ That will output:
|
|
60
61
|
You can also pass the username as a variable, like this:
|
61
62
|
|
62
63
|
```
|
63
|
-
{% assign
|
64
|
-
{% avatar {{
|
64
|
+
{% assign user="hubot" %}
|
65
|
+
{% avatar {{ user }} %}
|
65
66
|
```
|
66
67
|
|
67
68
|
Or, if the variable is someplace a bit more complex, like a loop:
|
@@ -73,6 +74,19 @@ Or, if the variable is someplace a bit more complex, like a loop:
|
|
73
74
|
{% endfor %}
|
74
75
|
```
|
75
76
|
|
77
|
+
### Lazy loading images
|
78
|
+
|
79
|
+
For pages showing a large number of avatars, you may want to load the images lazily.
|
80
|
+
|
81
|
+
```liquid
|
82
|
+
{% avatar hubot lazy=true %}
|
83
|
+
```
|
84
|
+
|
85
|
+
This will set the `data-src` and `data-srcset` attributes on the `<img>` tag, which is compatible with many lazy load JavaScript plugins, such as:
|
86
|
+
|
87
|
+
* https://www.andreaverlicchi.eu/lazyload/
|
88
|
+
* https://appelsiini.net/projects/lazyload/
|
89
|
+
|
76
90
|
### Using with GitHub Enterprise
|
77
91
|
|
78
92
|
To use Jekyll Avatars with GitHub Enterprise, you must set the `PAGES_AVATARS_URL` environmental variable.
|
@@ -80,4 +94,4 @@ To use Jekyll Avatars with GitHub Enterprise, you must set the `PAGES_AVATARS_UR
|
|
80
94
|
This should be the full URL to the avatars subdomain or subpath. For example:
|
81
95
|
|
82
96
|
* With subdomain isolation: `PAGES_AVATARS_URL="https://avatars.github.example.com"`
|
83
|
-
* Without subdomain isolation: `PAGES_AVATARS_URL="https://github.example.com/avatars"`
|
97
|
+
* Without subdomain isolation: `PAGES_AVATARS_URL="https://github.example.com/avatars"`
|
data/lib/jekyll-avatar.rb
CHANGED
@@ -4,54 +4,112 @@ require "zlib"
|
|
4
4
|
|
5
5
|
module Jekyll
|
6
6
|
class Avatar < Liquid::Tag
|
7
|
-
|
7
|
+
def self.generate_template_with(keys)
|
8
|
+
attrs = (BASE_ATTRIBUTES + keys).map! { |key| %(#{key}="%<#{key}>s") }.join(" ")
|
9
|
+
"<img #{attrs} />"
|
10
|
+
end
|
11
|
+
private_class_method :generate_template_with
|
12
|
+
|
13
|
+
#
|
8
14
|
|
9
15
|
SERVERS = 4
|
10
|
-
DEFAULT_SIZE = 40
|
11
|
-
API_VERSION = 3
|
16
|
+
DEFAULT_SIZE = "40"
|
17
|
+
API_VERSION = "3"
|
18
|
+
|
19
|
+
BASE_ATTRIBUTES = %w(
|
20
|
+
class alt width height data-proofer-ignore src
|
21
|
+
).freeze
|
22
|
+
|
23
|
+
BASE_TEMPLATE = generate_template_with %w(srcset)
|
24
|
+
LAZY_TEMPLATE = generate_template_with %w(data-src data-srcset)
|
25
|
+
|
26
|
+
private_constant :BASE_ATTRIBUTES, :BASE_TEMPLATE, :LAZY_TEMPLATE
|
12
27
|
|
13
28
|
def initialize(_tag_name, text, _tokens)
|
14
29
|
super
|
15
|
-
@text = text
|
30
|
+
@text = text.strip
|
31
|
+
@markup = Liquid::Template.parse(@text)
|
32
|
+
|
33
|
+
@size = compute_size
|
34
|
+
@user_variable = extract_user_variable
|
35
|
+
|
36
|
+
@custom_host = ENV["PAGES_AVATARS_URL"]
|
37
|
+
@custom_host = "" unless @custom_host.is_a?(String)
|
16
38
|
end
|
17
39
|
|
18
40
|
def render(context)
|
19
41
|
@context = context
|
20
|
-
@text =
|
21
|
-
|
22
|
-
|
42
|
+
@text = @markup.render(@context)
|
43
|
+
template = lazy_load? ? LAZY_TEMPLATE : BASE_TEMPLATE
|
44
|
+
format(template, attributes)
|
23
45
|
end
|
24
46
|
|
25
47
|
private
|
26
48
|
|
27
49
|
def attributes
|
28
|
-
{
|
29
|
-
:class
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:height => size,
|
35
|
-
"data-proofer-ignore" => true,
|
50
|
+
result = {
|
51
|
+
:class => classes,
|
52
|
+
:alt => username,
|
53
|
+
:width => size,
|
54
|
+
:height => size,
|
55
|
+
:"data-proofer-ignore" => "true",
|
36
56
|
}
|
57
|
+
|
58
|
+
if lazy_load?
|
59
|
+
result[:src] = ""
|
60
|
+
result[:"data-src"] = url
|
61
|
+
result[:"data-srcset"] = srcset
|
62
|
+
else
|
63
|
+
result[:src] = url
|
64
|
+
result[:srcset] = srcset
|
65
|
+
end
|
66
|
+
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
def lazy_load?
|
71
|
+
@text.include?("lazy=true")
|
72
|
+
end
|
73
|
+
|
74
|
+
def extract_user_variable
|
75
|
+
matches = @text.match(%r!\buser=([\w.]+)\b!)
|
76
|
+
matches[1] if matches
|
37
77
|
end
|
38
78
|
|
39
79
|
def username
|
40
|
-
|
41
|
-
|
42
|
-
|
80
|
+
return lookup_variable(@user_variable) if @user_variable
|
81
|
+
|
82
|
+
result = @text.include?(" ") ? @text.split(" ")[0] : @text
|
83
|
+
result.start_with?("@") ? result.sub("@", "") : result
|
84
|
+
end
|
85
|
+
|
86
|
+
# Lookup a Liquid variable in the current context.
|
87
|
+
#
|
88
|
+
# variable - the variable name, as a string.
|
89
|
+
#
|
90
|
+
# Returns the value of the variable in the context or the variable name if not found.
|
91
|
+
def lookup_variable(variable)
|
92
|
+
lookup = @context
|
93
|
+
if variable.include?(".")
|
94
|
+
variable.split(".").each do |value|
|
95
|
+
lookup = lookup[value]
|
96
|
+
end
|
43
97
|
else
|
44
|
-
|
98
|
+
lookup = lookup[variable]
|
45
99
|
end
|
100
|
+
|
101
|
+
lookup || variable
|
46
102
|
end
|
47
103
|
|
48
|
-
|
104
|
+
# Returns a string value
|
105
|
+
def compute_size
|
49
106
|
matches = @text.match(%r!\bsize=(\d+)\b!i)
|
50
|
-
matches ? matches[1]
|
107
|
+
matches ? matches[1] : DEFAULT_SIZE
|
51
108
|
end
|
109
|
+
attr_reader :size
|
52
110
|
|
53
111
|
def path(scale = 1)
|
54
|
-
"#{username}?v=#{API_VERSION}&s=#{size * scale}"
|
112
|
+
"#{username}?v=#{API_VERSION}&s=#{scale == 1 ? size : (size.to_i * scale)}"
|
55
113
|
end
|
56
114
|
|
57
115
|
def server_number
|
@@ -59,26 +117,41 @@ module Jekyll
|
|
59
117
|
end
|
60
118
|
|
61
119
|
def host
|
62
|
-
if
|
120
|
+
if @custom_host.empty?
|
63
121
|
"https://avatars#{server_number}.githubusercontent.com"
|
64
122
|
else
|
65
|
-
|
123
|
+
@custom_host
|
66
124
|
end
|
67
125
|
end
|
68
126
|
|
69
|
-
def
|
70
|
-
|
127
|
+
def parsed_host
|
128
|
+
@parsed_host ||= {}
|
129
|
+
@parsed_host[host] ||= Addressable::URI.parse(host)
|
130
|
+
end
|
131
|
+
|
132
|
+
def url_with_custom_host(scale = 1)
|
133
|
+
uri = parsed_host
|
71
134
|
uri.path << "/" unless uri.path.end_with?("/")
|
72
|
-
uri.join path(scale)
|
135
|
+
uri = uri.join path(scale)
|
136
|
+
uri.to_s
|
73
137
|
end
|
74
138
|
|
139
|
+
def url(scale = 1)
|
140
|
+
return url_with_custom_host(scale) unless @custom_host.empty?
|
141
|
+
|
142
|
+
"#{host}/#{path(scale)}"
|
143
|
+
end
|
144
|
+
|
145
|
+
SCALES = %w(1 2 3 4).freeze
|
146
|
+
private_constant :SCALES
|
147
|
+
|
75
148
|
def srcset
|
76
|
-
|
149
|
+
SCALES.map { |scale| "#{url(scale.to_i)} #{scale}x" }.join(", ")
|
77
150
|
end
|
78
151
|
|
79
152
|
# See http://primercss.io/avatars/#small-avatars
|
80
153
|
def classes
|
81
|
-
size < 48 ? "avatar avatar-small" : "avatar"
|
154
|
+
size.to_i < 48 ? "avatar avatar-small" : "avatar"
|
82
155
|
end
|
83
156
|
end
|
84
157
|
end
|
metadata
CHANGED
@@ -1,57 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-avatar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- - "
|
37
|
+
- - ">"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
- - "<"
|
32
41
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
42
|
+
version: '3.0'
|
34
43
|
type: :development
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
38
|
-
- - "
|
47
|
+
- - ">"
|
39
48
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
49
|
+
version: '1.0'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '3.0'
|
41
53
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
54
|
+
name: kramdown-parser-gfm
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
44
56
|
requirements:
|
45
57
|
- - "~>"
|
46
58
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
59
|
+
version: '1.0'
|
48
60
|
type: :development
|
49
61
|
prerelease: false
|
50
62
|
version_requirements: !ruby/object:Gem::Requirement
|
51
63
|
requirements:
|
52
64
|
- - "~>"
|
53
65
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
66
|
+
version: '1.0'
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
68
|
name: rspec
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,19 +79,47 @@ dependencies:
|
|
67
79
|
- !ruby/object:Gem::Version
|
68
80
|
version: '3.0'
|
69
81
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
82
|
+
name: rspec-html-matchers
|
71
83
|
requirement: !ruby/object:Gem::Requirement
|
72
84
|
requirements:
|
73
|
-
- - "
|
85
|
+
- - "~>"
|
74
86
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
87
|
+
version: '0.9'
|
76
88
|
type: :development
|
77
89
|
prerelease: false
|
78
90
|
version_requirements: !ruby/object:Gem::Requirement
|
79
91
|
requirements:
|
80
|
-
- - "
|
92
|
+
- - "~>"
|
81
93
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
94
|
+
version: '0.9'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rubocop-jekyll
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.12.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.12.0
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: rubocop-rspec
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '2.0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '2.0'
|
83
123
|
description:
|
84
124
|
email:
|
85
125
|
- ben.balter@github.com
|
@@ -87,21 +127,11 @@ executables: []
|
|
87
127
|
extensions: []
|
88
128
|
extra_rdoc_files: []
|
89
129
|
files:
|
90
|
-
- ".gitignore"
|
91
|
-
- ".rspec"
|
92
|
-
- ".rubocop.yml"
|
93
|
-
- ".ruby-version"
|
94
|
-
- ".travis.yml"
|
95
|
-
- Gemfile
|
96
130
|
- LICENSE.txt
|
97
131
|
- README.md
|
98
|
-
- Rakefile
|
99
|
-
- jekyll-avatar.gemspec
|
100
132
|
- lib/jekyll-avatar.rb
|
101
133
|
- lib/jekyll-avatar/version.rb
|
102
|
-
|
103
|
-
- script/cibuild
|
104
|
-
homepage: https://github.com/benbalter/jekyll-avatar
|
134
|
+
homepage: https://github.com/jekyll/jekyll-avatar
|
105
135
|
licenses:
|
106
136
|
- MIT
|
107
137
|
metadata: {}
|
@@ -113,15 +143,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
143
|
requirements:
|
114
144
|
- - ">="
|
115
145
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
146
|
+
version: 2.5.0
|
117
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
148
|
requirements:
|
119
149
|
- - ">="
|
120
150
|
- !ruby/object:Gem::Version
|
121
151
|
version: '0'
|
122
152
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.5.1
|
153
|
+
rubygems_version: 3.1.6
|
125
154
|
signing_key:
|
126
155
|
specification_version: 4
|
127
156
|
summary: A Jekyll plugin for rendering GitHub avatars
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.3.1
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/jekyll-avatar.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
lib = File.expand_path("../lib", __FILE__)
|
5
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
-
require "jekyll-avatar/version"
|
7
|
-
|
8
|
-
Gem::Specification.new do |spec|
|
9
|
-
spec.name = "jekyll-avatar"
|
10
|
-
spec.version = Jekyll::Avatar::VERSION
|
11
|
-
spec.authors = ["Ben Balter"]
|
12
|
-
spec.email = ["ben.balter@github.com"]
|
13
|
-
|
14
|
-
spec.summary = "A Jekyll plugin for rendering GitHub avatars"
|
15
|
-
spec.homepage = "https://github.com/benbalter/jekyll-avatar"
|
16
|
-
spec.license = "MIT"
|
17
|
-
|
18
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |file|
|
19
|
-
file.match(%r!^(test|spec|features)/!)
|
20
|
-
end
|
21
|
-
|
22
|
-
spec.require_paths = ["lib"]
|
23
|
-
|
24
|
-
spec.add_dependency "jekyll", "~> 3.0"
|
25
|
-
spec.add_development_dependency "bundler", "~> 1.11"
|
26
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
-
spec.add_development_dependency "rubocop"
|
29
|
-
end
|