jekyll-fetch 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/README.md +13 -0
- data/lib/jekyll-fetch/version.rb +1 -1
- data/lib/jekyll-fetch.rb +65 -16
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4434d6eccdd7106706ea9bc830e1112398ad65a2aeba36784b2329e910a2ff1
|
4
|
+
data.tar.gz: bfc916463dc0571bc8796bb40c7f561cc0ac1fe14726517a8b158d7c21ecd824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 224200bbc378ba973f547545ec1a6cb382184ac79aec98d03b17da34b5bbabf8b90051cf3c003a233b37ce47a21ab487c06c557d38f1a1afc3ad50e4454223c5
|
7
|
+
data.tar.gz: 67f3dd59fa6215fcf957715fd451f9bd6385e7adf98b2569f04178f43716388e015e31526a6273021d2053a8f14ba96537f9433547cf43157ad1e37b7e918594
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -29,6 +29,19 @@ The example above will render to the raw markdown of this readme. You can chain
|
|
29
29
|
{{ "https://raw.githubusercontent.com/pcouy/jekyll-fetch/main/README.md" | fetch | markdownify }}
|
30
30
|
```
|
31
31
|
|
32
|
+
Additionally, this plugin contains helper filters that help you work with files from GitHub repositories :
|
33
|
+
|
34
|
+
```
|
35
|
+
{{ "gh_user/repo_name" | github_url }}
|
36
|
+
Will render to : https://github.com/gh_user/repo_name
|
37
|
+
|
38
|
+
{{ "gh_user/repo_name" | github_readme }}
|
39
|
+
Will render to the content of the `README.md` file from the repository
|
40
|
+
|
41
|
+
{{ "gh_user/repo_name" | github_file: "path/to/file/in/repo" }}
|
42
|
+
Will render to the content of the specified file from the repository
|
43
|
+
```
|
44
|
+
|
32
45
|
## Development
|
33
46
|
|
34
47
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/jekyll-fetch/version.rb
CHANGED
data/lib/jekyll-fetch.rb
CHANGED
@@ -1,28 +1,77 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require_relative 'jekyll-fetch/version'
|
4
|
+
require 'liquid'
|
5
|
+
require 'net/https'
|
6
6
|
|
7
7
|
module Jekyll
|
8
|
+
# Filters for transforming URL strings into the content at the URL
|
8
9
|
module JekyllFetch
|
9
10
|
class Error < StandardError; end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
# Helper functions for HTTP requests
|
13
|
+
class Utils
|
14
|
+
class << self
|
15
|
+
def fetch(uri_str, limit = 10)
|
16
|
+
raise ArgumentError, 'Max retries reached' if limit.zero?
|
17
|
+
|
18
|
+
begin
|
19
|
+
unsafe_fetch(uri_str, limit)
|
20
|
+
rescue Errno::ECONNREFUSED
|
21
|
+
Jekyll.logger.warn "Connection refused for #{uri_str}, retrying in 2s..."
|
22
|
+
sleep 2
|
23
|
+
Jekyll.logger.warn "Retrying (#{limit - 1} tries left)"
|
24
|
+
fetch(uri_str, limit - 1)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def unsafe_fetch(uri_str, limit)
|
31
|
+
raise ArgumentError, 'Max retries reached' if limit.zero?
|
32
|
+
|
33
|
+
response_to_body(
|
34
|
+
uri_to_response(uri_str), limit - 1
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def uri_to_response(uri_str)
|
39
|
+
url = URI.parse(uri_str)
|
40
|
+
req = Net::HTTP::Get.new(url.path, { 'User-Agent' => 'Mozilla/5.0 (etc...)' })
|
41
|
+
Net::HTTP.start(url.host, url.port, use_ssl: true) { |http| http.request(req) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def response_to_body(response, limit)
|
45
|
+
case response
|
46
|
+
when Net::HTTPSuccess then response.body.force_encoding('UTF-8')
|
47
|
+
when Net::HTTPRedirection then fetch(response['location'], limit)
|
48
|
+
else
|
49
|
+
response.error!
|
50
|
+
end
|
51
|
+
end
|
24
52
|
end
|
25
53
|
end
|
54
|
+
|
55
|
+
def fetch(uri_str, limit = 10)
|
56
|
+
raise ArgumentError, 'HTTP redirect too deep' if limit.zero?
|
57
|
+
|
58
|
+
Jekyll.logger.debug "fetch(#{uri_str})"
|
59
|
+
Utils.fetch(uri_str, limit)
|
60
|
+
end
|
61
|
+
|
62
|
+
def github_url(repo)
|
63
|
+
"https://github.com/#{repo}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def github_readme(repo)
|
67
|
+
Jekyll.logger.debug "github_readme(#{repo})"
|
68
|
+
github_file repo, 'README.md'
|
69
|
+
end
|
70
|
+
|
71
|
+
def github_file(repo, file)
|
72
|
+
Jekyll.logger.debug "github_file(#{repo}, #{file})"
|
73
|
+
fetch "#{github_url(repo)}/raw/main/#{file}"
|
74
|
+
end
|
26
75
|
end
|
27
76
|
end
|
28
77
|
|
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-fetch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pcouy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: liquid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-http
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
@@ -26,7 +40,7 @@ dependencies:
|
|
26
40
|
version: '0'
|
27
41
|
description:
|
28
42
|
email:
|
29
|
-
- couy.
|
43
|
+
- contact@pierre-couy.dev
|
30
44
|
executables: []
|
31
45
|
extensions: []
|
32
46
|
extra_rdoc_files: []
|
@@ -39,12 +53,12 @@ files:
|
|
39
53
|
- lib/jekyll-fetch.rb
|
40
54
|
- lib/jekyll-fetch/version.rb
|
41
55
|
- sig/jekyll_http.rbs
|
42
|
-
homepage: https://
|
56
|
+
homepage: https://pierre-couy.dev/projects/jekyll-fetch.html
|
43
57
|
licenses:
|
44
58
|
- MIT
|
45
59
|
metadata:
|
46
60
|
allowed_push_host: https://rubygems.org
|
47
|
-
homepage_uri: https://
|
61
|
+
homepage_uri: https://pierre-couy.dev/projects/jekyll-fetch.html
|
48
62
|
source_code_uri: https://github.com/pcouy/jekyll-fetch
|
49
63
|
post_install_message:
|
50
64
|
rdoc_options: []
|