jekyll-fetch 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4434d6eccdd7106706ea9bc830e1112398ad65a2aeba36784b2329e910a2ff1
4
- data.tar.gz: bfc916463dc0571bc8796bb40c7f561cc0ac1fe14726517a8b158d7c21ecd824
3
+ metadata.gz: c5454f6d5abbbd61428289ac94ae2283a5668ace9ec37941d6a333897e70d140
4
+ data.tar.gz: 295243d723f1b8e149a3ef010d40bff5c7468569937144720a3756a998114612
5
5
  SHA512:
6
- metadata.gz: 224200bbc378ba973f547545ec1a6cb382184ac79aec98d03b17da34b5bbabf8b90051cf3c003a233b37ce47a21ab487c06c557d38f1a1afc3ad50e4454223c5
7
- data.tar.gz: 67f3dd59fa6215fcf957715fd451f9bd6385e7adf98b2569f04178f43716388e015e31526a6273021d2053a8f14ba96537f9433547cf43157ad1e37b7e918594
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllFetch
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
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
- Jekyll.logger.debug "github_readme(#{repo})"
68
- github_file repo, 'README.md'
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
- Jekyll.logger.debug "github_file(#{repo}, #{file})"
73
- fetch "#{github_url(repo)}/raw/main/#{file}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-fetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pcouy