jekyll-fetch 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +19 -0
- data/lib/jekyll-fetch/version.rb +1 -1
- data/lib/jekyll-fetch.rb +19 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5454f6d5abbbd61428289ac94ae2283a5668ace9ec37941d6a333897e70d140
|
4
|
+
data.tar.gz: 295243d723f1b8e149a3ef010d40bff5c7468569937144720a3756a998114612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c8ca44f9b14fb48ff1662e7ca8e0a901dab63ee028fdccee0dae934af36548a05ec7611945084d44c039be8747313f0632397bbfaf836cf310de128015cc669
|
7
|
+
data.tar.gz: 57fb86f18102e24be963427de16c7a00136da3a90920ec3eafe2cefbb1cccf7110b090fce3c9cff69d3b6e5d61e4937e773e9c9455507dfd869f11f4a852a5b7
|
data/README.md
CHANGED
@@ -42,6 +42,25 @@ Will render to the content of the `README.md` file from the repository
|
|
42
42
|
Will render to the content of the specified file from the repository
|
43
43
|
```
|
44
44
|
|
45
|
+
### Specify GitHub branches
|
46
|
+
|
47
|
+
You can change the default branch used for retrieving GitHub files from main to the value of your choice by updating `_config.yml` :
|
48
|
+
|
49
|
+
```yaml
|
50
|
+
fetch: # Config section for the plugin
|
51
|
+
default_github_branch: main # This is the default value but you can use whatever you want
|
52
|
+
```
|
53
|
+
|
54
|
+
The `github_readme` and `github_file` accept an optional argument for one-time overrides of the branch :
|
55
|
+
|
56
|
+
```
|
57
|
+
{{ "gh_user/repo_name" | github_readme: 'branch_name' }}
|
58
|
+
Will render to the content of the `README.md` file from the repository
|
59
|
+
|
60
|
+
{{ "gh_user/repo_name" | github_file: "path/to/file/in/repo", "branch_name" }}
|
61
|
+
Will render to the content of the specified file from the repository
|
62
|
+
```
|
63
|
+
|
45
64
|
## Development
|
46
65
|
|
47
66
|
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
@@ -7,6 +7,9 @@ require 'net/https'
|
|
7
7
|
module Jekyll
|
8
8
|
# Filters for transforming URL strings into the content at the URL
|
9
9
|
module JekyllFetch
|
10
|
+
CONFIG = {
|
11
|
+
'default_github_branch' => 'main'
|
12
|
+
}.freeze
|
10
13
|
class Error < StandardError; end
|
11
14
|
|
12
15
|
# Helper functions for HTTP requests
|
@@ -25,6 +28,10 @@ module Jekyll
|
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
31
|
+
def config
|
32
|
+
@config ||= CONFIG.merge(JEKYLL_SITE.config['fetch'] || {})
|
33
|
+
end
|
34
|
+
|
28
35
|
private
|
29
36
|
|
30
37
|
def unsafe_fetch(uri_str, limit)
|
@@ -63,16 +70,22 @@ module Jekyll
|
|
63
70
|
"https://github.com/#{repo}"
|
64
71
|
end
|
65
72
|
|
66
|
-
def github_readme(repo)
|
67
|
-
|
68
|
-
|
73
|
+
def github_readme(repo, branch = nil)
|
74
|
+
branch ||= Utils.config['default_github_branch']
|
75
|
+
Jekyll.logger.debug "github_readme(#{repo}, #{branch})"
|
76
|
+
github_file repo, 'README.md', branch
|
69
77
|
end
|
70
78
|
|
71
|
-
def github_file(repo, file)
|
72
|
-
|
73
|
-
|
79
|
+
def github_file(repo, file, branch = nil)
|
80
|
+
branch ||= Utils.config['default_github_branch']
|
81
|
+
Jekyll.logger.debug "github_file(#{repo}, #{file}, #{branch})"
|
82
|
+
fetch "#{github_url(repo)}/raw/#{branch}/#{file}"
|
74
83
|
end
|
75
84
|
end
|
76
85
|
end
|
77
86
|
|
78
87
|
Liquid::Template.register_filter(Jekyll::JekyllFetch)
|
88
|
+
|
89
|
+
Jekyll::Hooks.register :site, :after_init do |site|
|
90
|
+
Jekyll::JekyllFetch::JEKYLL_SITE = site
|
91
|
+
end
|