jekyll-github-metadata 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-github-metadata.rb +18 -13
- data/lib/jekyll-github-metadata/client.rb +20 -9
- data/lib/jekyll-github-metadata/ghp_metadata_generator.rb +12 -4
- data/lib/jekyll-github-metadata/pages.rb +28 -7
- data/lib/jekyll-github-metadata/repository.rb +48 -15
- data/lib/jekyll-github-metadata/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efed2aebc358aaa6e7cee8d1c5e03e0eca432453
|
4
|
+
data.tar.gz: 424595a71e84aa1917bfb2198b73d0e95132268c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3253b80572e5551d4635c4d878374839be39bbc42af2e756e67b9664e82fe7967b6242501c9b4e62294eed007f7eb9946343e9848df9f2bc379f02f020c39daf
|
7
|
+
data.tar.gz: e81fe89c4d4912f1a0450a3c2df85d6f3511beb0bed3ec0f8a610208aee198e2680dc5ea7d58439abd6ca15db3cf1f77be1ff553e2cc26a3f8d8158c050ce2d3
|
@@ -1,7 +1,12 @@
|
|
1
|
-
require 'jekyll'
|
2
1
|
require 'octokit'
|
3
2
|
|
4
3
|
module Jekyll
|
4
|
+
unless const_defined? :Errors
|
5
|
+
module Errors
|
6
|
+
FatalException = Class.new(::RuntimeError) unless const_defined? :FatalException
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
5
10
|
module GitHubMetadata
|
6
11
|
NoRepositoryError = Class.new(Jekyll::Errors::FatalException)
|
7
12
|
|
@@ -14,9 +19,10 @@ module Jekyll
|
|
14
19
|
|
15
20
|
class << self
|
16
21
|
attr_accessor :repository
|
22
|
+
attr_writer :client
|
17
23
|
|
18
24
|
def environment
|
19
|
-
Jekyll.env
|
25
|
+
Jekyll.respond_to?(:env) ? Jekyll.env : (Pages.env || 'development')
|
20
26
|
end
|
21
27
|
|
22
28
|
def client
|
@@ -26,6 +32,8 @@ module Jekyll
|
|
26
32
|
def values
|
27
33
|
@values ||= Hash.new
|
28
34
|
end
|
35
|
+
alias_method :to_h, :values
|
36
|
+
alias_method :to_liquid, :to_h
|
29
37
|
|
30
38
|
def clear_values!
|
31
39
|
@values = Hash.new
|
@@ -34,27 +42,20 @@ module Jekyll
|
|
34
42
|
def reset!
|
35
43
|
clear_values!
|
36
44
|
@client = nil
|
45
|
+
@repository = nil
|
37
46
|
end
|
38
47
|
|
39
48
|
def [](key)
|
40
49
|
values[key.to_s]
|
41
50
|
end
|
42
51
|
|
43
|
-
def to_h
|
44
|
-
values
|
45
|
-
end
|
46
|
-
|
47
|
-
def to_liquid
|
48
|
-
to_h
|
49
|
-
end
|
50
|
-
|
51
52
|
def register_value(key, value)
|
52
53
|
values[key.to_s] = Value.new(key.to_s, value)
|
53
54
|
end
|
54
55
|
|
55
56
|
# Reset our values hash.
|
56
57
|
def init!
|
57
|
-
|
58
|
+
clear_values!
|
58
59
|
|
59
60
|
# Environment-Specific
|
60
61
|
register_value('environment', proc { environment })
|
@@ -100,11 +101,15 @@ module Jekyll
|
|
100
101
|
register_value('url', proc { |_,r| r.pages_url })
|
101
102
|
register_value('contributors', proc { |c,r| c.contributors(r.nwo) })
|
102
103
|
register_value('releases', proc { |c,r| c.releases(r.nwo) })
|
104
|
+
|
105
|
+
values
|
106
|
+
end
|
107
|
+
|
108
|
+
if Jekyll.const_defined? :Site
|
109
|
+
require_relative 'jekyll-github-metadata/ghp_metadata_generator'
|
103
110
|
end
|
104
111
|
end
|
105
112
|
|
106
113
|
init!
|
107
114
|
end
|
108
115
|
end
|
109
|
-
|
110
|
-
require_relative 'jekyll-github-metadata/ghp_metadata_generator'
|
@@ -14,21 +14,18 @@ module Jekyll
|
|
14
14
|
|
15
15
|
def build_octokit_client(options = nil)
|
16
16
|
options = options || Hash.new
|
17
|
-
|
18
|
-
options.merge!
|
19
|
-
elsif !ENV['NO_NETRC'] && File.exist?(File.join(ENV['HOME'], '.netrc')) && safe_require('netrc')
|
20
|
-
options.merge!(:netrc => true)
|
21
|
-
else
|
22
|
-
Jekyll.logger.warn "GitHubMetadata:", "No GitHub API authentication could be found." +
|
23
|
-
" Some fields may be missing or have incorrect data."
|
17
|
+
unless options.key? :access_token
|
18
|
+
options.merge! pluck_auth_method
|
24
19
|
end
|
25
20
|
Octokit::Client.new({:auto_paginate => true}.merge(options))
|
26
21
|
end
|
27
22
|
|
28
23
|
def method_missing(meth, *args, &block)
|
29
24
|
if @client.respond_to?(meth)
|
30
|
-
|
31
|
-
|
25
|
+
instance_var_name = meth.to_s.sub('?', '_')
|
26
|
+
Jekyll.logger.debug "GitHub Metadata:", "Calling @client.#{meth}(#{args.map(&:inspect).join(", ")})"
|
27
|
+
instance_variable_get(:"@#{instance_var_name}") ||
|
28
|
+
instance_variable_set(:"@#{instance_var_name}", save_from_errors { @client.send(meth, *args, &block) })
|
32
29
|
else
|
33
30
|
super(meth, *args, &block)
|
34
31
|
end
|
@@ -46,6 +43,20 @@ module Jekyll
|
|
46
43
|
Octokit::TooManyRequests
|
47
44
|
default
|
48
45
|
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def pluck_auth_method
|
50
|
+
if ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token
|
51
|
+
{ :access_token => ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token }
|
52
|
+
elsif !ENV['NO_NETRC'] && File.exist?(File.join(ENV['HOME'], '.netrc')) && safe_require('netrc')
|
53
|
+
{ :netrc => true }
|
54
|
+
else
|
55
|
+
Jekyll.logger.warn "GitHub Metadata:", "No GitHub API authentication could be found." +
|
56
|
+
" Some fields may be missing or have incorrect data."
|
57
|
+
{}.freeze
|
58
|
+
end
|
59
|
+
end
|
49
60
|
end
|
50
61
|
end
|
51
62
|
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
require 'jekyll'
|
2
|
-
|
3
1
|
module Jekyll
|
4
2
|
module GitHubMetadata
|
5
3
|
class GHPMetadataGenerator < Jekyll::Generator
|
6
4
|
def generate(site)
|
7
5
|
Jekyll.logger.debug "Generator:", "Calling GHPMetadataGenerator"
|
8
|
-
|
9
|
-
GitHubMetadata.
|
6
|
+
initialize_repo! nwo(site)
|
7
|
+
Jekyll.logger.debug "GitHub Metadata:", "Generating for #{GitHubMetadata.repository.nwo}"
|
8
|
+
|
10
9
|
site.config['github'] =
|
11
10
|
case site.config['github']
|
12
11
|
when nil
|
@@ -18,6 +17,15 @@ module Jekyll
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
20
|
+
private
|
21
|
+
|
22
|
+
def initialize_repo!(repo_nwo)
|
23
|
+
if GitHubMetadata.repository.nil? || GitHubMetadata.repository.nwo != repo_nwo
|
24
|
+
GitHubMetadata.init!
|
25
|
+
GitHubMetadata.repository = GitHubMetadata::Repository.new(repo_nwo)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
21
29
|
def nwo(site)
|
22
30
|
ENV['PAGES_REPO_NWO'] || \
|
23
31
|
site.config['repository'] || \
|
@@ -6,37 +6,58 @@ module Jekyll
|
|
6
6
|
'PAGES_ENV' => 'dotcom'.freeze,
|
7
7
|
'PAGES_API_URL' => 'https://api.github.com'.freeze,
|
8
8
|
'PAGES_HELP_URL' => 'https://help.github.com'.freeze,
|
9
|
-
'PAGES_GITHUB_HOSTNAME' => '
|
9
|
+
'PAGES_GITHUB_HOSTNAME' => 'github.com'.freeze,
|
10
10
|
'PAGES_PAGES_HOSTNAME' => 'github.io'.freeze,
|
11
|
-
'SSL' => 'false'.freeze
|
11
|
+
'SSL' => 'false'.freeze,
|
12
|
+
'SUBDOMAIN_ISOLATION' => 'false'.freeze
|
12
13
|
}.freeze
|
13
14
|
|
14
15
|
def ssl?
|
15
|
-
env_var('SSL')
|
16
|
+
env_var('SSL') == 'true' || test?
|
16
17
|
end
|
17
18
|
|
18
19
|
def scheme
|
19
20
|
ssl? ? "https" : "http"
|
20
21
|
end
|
21
22
|
|
23
|
+
def subdomain_isolation?
|
24
|
+
env_var('SUBDOMAIN_ISOLATION').eql? 'true'
|
25
|
+
end
|
26
|
+
|
27
|
+
def test?; env == 'test' end
|
28
|
+
def dotcom?; env == 'dotcom' end
|
29
|
+
def enterprise?; env == 'enterprise' end
|
30
|
+
|
31
|
+
def custom_domains_enabled?
|
32
|
+
dotcom? || test?
|
33
|
+
end
|
34
|
+
|
22
35
|
def env
|
23
36
|
env_var 'PAGES_ENV'
|
24
37
|
end
|
25
38
|
|
39
|
+
def github_url
|
40
|
+
if dotcom?
|
41
|
+
"https://github.com".freeze
|
42
|
+
else
|
43
|
+
"#{scheme}://#{github_hostname}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
26
47
|
def api_url
|
27
|
-
trim_last_slash env_var('PAGES_API_URL',
|
48
|
+
trim_last_slash env_var('PAGES_API_URL', ENV['API_URL'])
|
28
49
|
end
|
29
50
|
|
30
51
|
def help_url
|
31
|
-
trim_last_slash env_var('PAGES_HELP_URL')
|
52
|
+
trim_last_slash env_var('PAGES_HELP_URL', ENV['HELP_URL'])
|
32
53
|
end
|
33
54
|
|
34
55
|
def github_hostname
|
35
|
-
trim_last_slash env_var('PAGES_GITHUB_HOSTNAME',
|
56
|
+
trim_last_slash env_var('PAGES_GITHUB_HOSTNAME', ENV['GITHUB_HOSTNAME'])
|
36
57
|
end
|
37
58
|
|
38
59
|
def pages_hostname
|
39
|
-
trim_last_slash env_var('PAGES_PAGES_HOSTNAME')
|
60
|
+
trim_last_slash env_var('PAGES_PAGES_HOSTNAME', ENV['PAGES_HOSTNAME'])
|
40
61
|
end
|
41
62
|
|
42
63
|
private
|
@@ -9,7 +9,7 @@ module Jekyll
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def organization_repository?
|
12
|
-
!!
|
12
|
+
!!Value.new(proc { |c| c.organization(owner) }).render
|
13
13
|
end
|
14
14
|
|
15
15
|
def git_ref
|
@@ -29,7 +29,7 @@ module Jekyll
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def owner_url
|
32
|
-
"#{Pages.
|
32
|
+
"#{Pages.github_url}/#{owner}"
|
33
33
|
end
|
34
34
|
|
35
35
|
def owner_gravatar_url
|
@@ -41,7 +41,7 @@ module Jekyll
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def repository_url
|
44
|
-
"#{
|
44
|
+
"#{owner_url}/#{name}"
|
45
45
|
end
|
46
46
|
|
47
47
|
def zip_url
|
@@ -73,46 +73,79 @@ module Jekyll
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def project_page?
|
76
|
-
!
|
76
|
+
!user_page?
|
77
77
|
end
|
78
78
|
|
79
|
-
def
|
80
|
-
|
79
|
+
def github_repo?
|
80
|
+
!Pages.enterprise? && owner.eql?('github')
|
81
81
|
end
|
82
82
|
|
83
|
-
def
|
84
|
-
|
83
|
+
def primary?
|
84
|
+
if Pages.enterprise?
|
85
|
+
name.downcase == "#{owner.to_s.downcase}.#{Pages.github_hostname}"
|
86
|
+
else
|
87
|
+
user_page_domains.include? name.downcase
|
88
|
+
end
|
85
89
|
end
|
86
90
|
|
87
91
|
def default_user_domain
|
88
92
|
if github_repo?
|
89
93
|
"#{owner}.#{Pages.github_hostname}".downcase
|
94
|
+
elsif Pages.enterprise?
|
95
|
+
Pages.pages_hostname.downcase
|
90
96
|
else
|
91
97
|
"#{owner}.#{Pages.pages_hostname}".downcase
|
92
98
|
end
|
93
99
|
end
|
94
100
|
|
95
101
|
def user_page_domains
|
96
|
-
[
|
97
|
-
|
98
|
-
|
99
|
-
|
102
|
+
domains = [default_user_domain]
|
103
|
+
domains.push "#{owner}.github.com".downcase unless Pages.enterprise?
|
104
|
+
domains
|
105
|
+
end
|
106
|
+
|
107
|
+
def user_domain
|
108
|
+
domain = default_user_domain
|
109
|
+
user_page_domains.each do |user_repo|
|
110
|
+
candidate_nwo = "#{owner}/#{user_repo}"
|
111
|
+
next unless Value.new(proc { |client| client.repository? candidate_nwo }).render
|
112
|
+
domain = self.class.new(candidate_nwo).domain
|
113
|
+
end
|
114
|
+
domain
|
100
115
|
end
|
101
116
|
|
102
117
|
def pages_url
|
103
|
-
if
|
118
|
+
if !Pages.custom_domains_enabled?
|
119
|
+
path = user_page? ? owner : nwo
|
120
|
+
if Pages.subdomain_isolation?
|
121
|
+
URI.join("#{Pages.scheme}://#{Pages.pages_hostname}/", path).to_s
|
122
|
+
else
|
123
|
+
URI.join("#{Pages.github_url}/pages/", path).to_s
|
124
|
+
end
|
125
|
+
elsif cname || primary?
|
104
126
|
"#{Pages.scheme}://#{domain}"
|
105
127
|
else
|
106
|
-
URI.join("#{Pages.scheme}://#{domain}",
|
128
|
+
URI.join("#{Pages.scheme}://#{domain}", name).to_s
|
107
129
|
end
|
108
130
|
end
|
109
131
|
|
110
132
|
def cname
|
133
|
+
return @cname if defined?(@cname)
|
134
|
+
return unless Pages.custom_domains_enabled?
|
111
135
|
@cname ||= (Value.new('cname', proc { |c| c.pages(nwo) }).render || {'cname' => nil})['cname']
|
112
136
|
end
|
113
137
|
|
114
138
|
def domain
|
115
|
-
|
139
|
+
@domain ||=
|
140
|
+
if !Pages.custom_domains_enabled?
|
141
|
+
Pages.github_hostname
|
142
|
+
elsif cname # explicit CNAME
|
143
|
+
cname
|
144
|
+
elsif primary? # user/org repo
|
145
|
+
default_user_domain
|
146
|
+
else # project repo
|
147
|
+
user_domain
|
148
|
+
end
|
116
149
|
end
|
117
150
|
end
|
118
151
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-github-metadata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|