jekyll-remote-theme 0.6.1 → 0.6.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e01afd90316ec162cddd29765466d934ae241d626f473bcd9acfd9976a1fd01
4
- data.tar.gz: '00945458c1ed12cb8bdc2a21aa41d11d22e3cc8060a67eb65b494e9bc1ac0775'
3
+ metadata.gz: e03229a94b9e765b76cb5dee2b5838ab13a58098e33fa73d5e5733570102e828
4
+ data.tar.gz: 77020e301b78ebe789c608a29e7217f722c53b25275afec32c876a8c9bf2d370
5
5
  SHA512:
6
- metadata.gz: 12c833b553ab123f001a1ec6610a01551265b675349045cd322e73816e2f421e3033174cad40a542b18087272f30edb945c838fe24b4e1d21b095d0453d2c9e4
7
- data.tar.gz: 267ffe076935719f7e91cfc4ce4673ff29d437a908068b89b296e456d17d9a61128af54ddda2008e1d1fff5e58e430542d623b7925ae39e6b722afdbee1a2d4c
6
+ metadata.gz: c3a79a33a692b97472f6cdd2a42af44f623bf769772beee69f0488611d0e47a5e55697a7baf9e17be88841a1d712288bdf73e91e3e98f42dc57830037f224be7
7
+ data.tar.gz: f368911a263cc85af35d168a64e20796c0c81b906b68e7dca041a7bb81f1c58ee9daaa2bd4bcff236f3ff2afd3dff85ffc8535e7184f49625c667e7df6ac78af
@@ -15,7 +15,7 @@ module Jekyll
15
15
  return unless raw_theme
16
16
 
17
17
  unless theme.valid?
18
- Jekyll.logger.error LOG_KEY, "#{raw_theme.inspect} is not a valid remote theme"
18
+ Jekyll.logger.error LOG_KEY, invalid_theme_message
19
19
  return
20
20
  end
21
21
 
@@ -33,6 +33,14 @@ module Jekyll
33
33
 
34
34
  private
35
35
 
36
+ def invalid_theme_message
37
+ message = "#{raw_theme.inspect} is not a valid remote theme"
38
+ return message unless theme.disallowed_host?
39
+
40
+ "#{message}; host #{theme.host.inspect} is not allowed. " \
41
+ "Set PAGES_GITHUB_HOSTNAME or GITHUB_HOSTNAME to #{theme.host.inspect}"
42
+ end
43
+
36
44
  def munged?
37
45
  site.theme&.is_a?(Jekyll::RemoteTheme::Theme)
38
46
  end
@@ -5,8 +5,14 @@ module Jekyll
5
5
  class Theme < Jekyll::Theme
6
6
  OWNER_REGEX = %r!(?<owner>[a-z0-9\-]+)!i.freeze
7
7
  NAME_REGEX = %r!(?<name>[a-z0-9\._\-]+)!i.freeze
8
- REF_REGEX = %r!@(?<ref>[a-z0-9\._\-]+)!i.freeze # May be a branch, tag, commit, or "latest"
8
+ # A ref segment can't be "." or "..": the ref goes into a normalized download
9
+ # URL, where those segments would point at a different path.
10
+ REF_SEGMENT_REGEX = %r!(?\!\.\.?(?:/|\z))[a-z0-9\._\-]+!i.freeze
11
+ # May be a branch, tag, commit, or "latest". Branches may contain "/", as in
12
+ # "feature/new-layout", but not at the start or end, or twice in a row.
13
+ REF_REGEX = %r!@(?<ref>#{REF_SEGMENT_REGEX}(?:/#{REF_SEGMENT_REGEX})*)!i.freeze
9
14
  THEME_REGEX = %r!\A#{OWNER_REGEX}/#{NAME_REGEX}(?:#{REF_REGEX})?\z!i.freeze
15
+ REF_SUFFIX_REGEX = %r!\A#{REF_REGEX}\z!.freeze
10
16
 
11
17
  # Initializes a new Jekyll::RemoteTheme::Theme
12
18
  #
@@ -27,7 +33,7 @@ module Jekyll
27
33
  @site = site
28
34
  original_theme = raw_theme.to_s.strip
29
35
  local_path = looks_like_local_path?(original_theme)
30
- @raw_theme = local_path ? original_theme : original_theme.downcase
36
+ @raw_theme = local_path ? original_theme : normalize_remote_theme(original_theme)
31
37
  super(@raw_theme)
32
38
  end
33
39
 
@@ -67,11 +73,17 @@ module Jekyll
67
73
 
68
74
  parsed_ref = theme_parts[:ref]
69
75
  return "HEAD" unless parsed_ref
70
- return resolve_latest_release if parsed_ref == "latest"
76
+ return resolve_latest_release if parsed_ref.casecmp?("latest")
71
77
 
72
78
  parsed_ref
73
79
  end
74
80
 
81
+ def disallowed_host?
82
+ return false unless uri && theme_parts && name && owner
83
+
84
+ host && !valid_hosts.include?(host)
85
+ end
86
+
75
87
  def root
76
88
  return (expanded_local_path if local_path_valid?) if local_theme?
77
89
 
@@ -98,6 +110,16 @@ module Jekyll
98
110
  super
99
111
  end
100
112
 
113
+ # Owners and repo names are case-insensitive on GitHub, so normalize them,
114
+ # but leave the git ref alone: branch and tag names are case-sensitive, and
115
+ # downcasing them points codeload at a ref that doesn't exist.
116
+ def normalize_remote_theme(theme)
117
+ theme_without_ref, separator, ref = theme.rpartition("@")
118
+ return theme.downcase if separator.empty? || !"@#{ref}".match?(REF_SUFFIX_REGEX)
119
+
120
+ "#{theme_without_ref.downcase}@#{ref}"
121
+ end
122
+
101
123
  def looks_like_local_path?(path)
102
124
  # Check if it looks like a local path
103
125
  # Supports: /, ./, ../, ~/ (Unix-style) and drive letters (Windows-style)
@@ -172,7 +194,7 @@ module Jekyll
172
194
  if response.is_a?(Net::HTTPSuccess)
173
195
  parse_tag_from_response(response)
174
196
  else
175
- log_no_releases_warning
197
+ log_failed_response_warning(response)
176
198
  nil
177
199
  end
178
200
  rescue StandardError => e
@@ -221,6 +243,19 @@ module Jekyll
221
243
  "No releases found for #{name_with_owner}, using HEAD"
222
244
  end
223
245
 
246
+ def log_failed_response_warning(response)
247
+ if response.code == "404"
248
+ log_no_releases_warning
249
+ else
250
+ message = "Unexpected HTTP #{response.code} response " \
251
+ "for #{name_with_owner}, using HEAD"
252
+ if %w(403 429).include?(response.code)
253
+ message += "; this is likely caused by GitHub API rate limiting"
254
+ end
255
+ Jekyll.logger.warn LOG_KEY, message
256
+ end
257
+ end
258
+
224
259
  def log_api_error(error)
225
260
  Jekyll.logger.warn LOG_KEY,
226
261
  "Failed to fetch latest release for #{name_with_owner}: " \
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module RemoteTheme
5
- VERSION = "0.6.1"
5
+ VERSION = "0.6.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-remote-theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
@@ -159,6 +159,20 @@ dependencies:
159
159
  - - "~>"
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0.11'
162
+ - !ruby/object:Gem::Dependency
163
+ name: rake
164
+ requirement: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - "~>"
167
+ - !ruby/object:Gem::Version
168
+ version: '13.0'
169
+ type: :development
170
+ prerelease: false
171
+ version_requirements: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - "~>"
174
+ - !ruby/object:Gem::Version
175
+ version: '13.0'
162
176
  - !ruby/object:Gem::Dependency
163
177
  name: rspec
164
178
  requirement: !ruby/object:Gem::Requirement
@@ -271,6 +285,8 @@ dependencies:
271
285
  - - "~>"
272
286
  - !ruby/object:Gem::Version
273
287
  version: '3.0'
288
+ description: Jekyll plugin to build a site with any public GitHub-hosted theme, set
289
+ via the remote_theme config key. Supported on GitHub Pages.
274
290
  email:
275
291
  - ben.balter@github.com
276
292
  executables: []
@@ -287,7 +303,11 @@ files:
287
303
  homepage: https://github.com/benbalter/jekyll-remote-theme
288
304
  licenses:
289
305
  - MIT
290
- metadata: {}
306
+ metadata:
307
+ homepage_uri: https://github.com/benbalter/jekyll-remote-theme
308
+ source_code_uri: https://github.com/benbalter/jekyll-remote-theme
309
+ bug_tracker_uri: https://github.com/benbalter/jekyll-remote-theme/issues
310
+ changelog_uri: https://github.com/benbalter/jekyll-remote-theme/releases
291
311
  rdoc_options: []
292
312
  require_paths:
293
313
  - lib
@@ -302,7 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
302
322
  - !ruby/object:Gem::Version
303
323
  version: '0'
304
324
  requirements: []
305
- rubygems_version: 3.6.9
325
+ rubygems_version: 4.0.20
306
326
  specification_version: 4
307
327
  summary: Jekyll plugin for building Jekyll sites with any GitHub-hosted theme
308
328
  test_files: []