nanoc-github 1.0.1 → 1.1.0

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: df7617ea3b0051571d87c07cc323c6df1164b19b525d94bbd84ccef3456888b8
4
- data.tar.gz: 2579afafcde3ead1a537a41de736c10152e59e97d78811baa58e6947bbbf4f1d
3
+ metadata.gz: fd984944196f6054b8fd003d57caa00c57651f843112c2f16305be56e1ec8e4d
4
+ data.tar.gz: 50435138314259aa25e3649663b695b5e0f52e3f12a7a278b70d3c513e8ea6bb
5
5
  SHA512:
6
- metadata.gz: f7d327a0a0e097ab9db731ff7941b76e74fbe1556ee28d9cb68929d4e86b873783e85643391ced643327f8a0420cde465953b031f26d16360ce5e5cfc2385f16
7
- data.tar.gz: 2c3b89f16b0a5ca4d7092a76290d412abbe7c39f172646bebb5800261befa04932345aa683c3f07ea6e169966c6bc7c4ab0b5ed1bf3e768d4d1db881637ea854
6
+ metadata.gz: 9dcbbff78cc680d767f444202bb501861372afd2bf1ba704ebc8ebcc8f3d2aa705d528ad09e8e204212921a771d0963288ff01ba33e6099b66599d3ad15653e0
7
+ data.tar.gz: c4f2ba46b7c121bbe37fb04cb456e619d2dde881c68496a7d679a3471186635278f053983d1de56566aec67735c88a3dc0dd364c50e01d3463d2e53b3caaabf3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Nanoc::Github
2
2
 
3
- Content source from git repository. A way to have your writing in public and open for edition while not being distracted
3
+ Content source from git repository. A way to have your writing in public and open for editing while not being distracted
4
4
  by static site generator trivia this content is usually mixed with.
5
5
 
6
6
  ## Usage
@@ -23,14 +23,16 @@ At last, enable github data source in `nanoc.yaml`:
23
23
  data_sources:
24
24
  - type: github
25
25
  items_root: /posts # the root where items should be mounted
26
- repository: arkency/posts-from-arkency-blog # organization/repository on github to use as a source of content
26
+ repository: arkency/posts # organization/repository on github to use as a source of content
27
27
  encoding: utf-8 # how to decode content (default: utf-8)
28
28
  access_token: secret123 # github access token, not required for public repositories (default: nil)
29
29
  path: posts/ # subdirectory of the content in given repository (default: nil)
30
30
  concurrency: 10 # how many threads to spawn to fetch data (default: 5)
31
+ verbose: true # show HTTP cache hit/miss on STDOUT (default: false)
32
+ max_age: 600 # override time in which cached content is considered to be fresh (default: 60)
31
33
  ```
32
34
 
33
35
  ## Status
34
36
 
35
37
  [![build status](https://github.com/pawelpacana/nanoc-github/workflows/test/badge.svg)](https://github.com/pawelpacana/nanoc-github/actions)
36
- [![gem version](https://badge.fury.io/rb/nanoc-github.svg)](https://badge.fury.io/rb/nanoc-github)
38
+ [![gem version](https://badge.fury.io/rb/nanoc-github.svg)](https://badge.fury.io/rb/nanoc-github)
@@ -1,14 +1,68 @@
1
1
  require "nanoc"
2
2
  require "octokit"
3
3
  require "concurrent-ruby"
4
+ require "faraday/http_cache"
5
+ require "pstore"
4
6
 
5
7
  module Nanoc
6
8
  module Github
7
9
  REGEX = /^(?<metadata>---\s*\n.*?\n?)^(---\s*$\n?)/m
8
10
 
11
+ class Cache
12
+ def initialize(cache_dir)
13
+ @store = PStore.new(File.join(cache_dir, "nanoc-github.store"), true)
14
+ end
15
+
16
+ def write(name, value, options = nil)
17
+ store.transaction { store[name] = value }
18
+ end
19
+
20
+ def read(name, options = nil)
21
+ store.transaction(true) { store[name] }
22
+ end
23
+
24
+ def delete(name, options = nil)
25
+ store.transaction { store.delete(name) }
26
+ end
27
+
28
+ private
29
+ attr_reader :store
30
+ end
31
+
32
+ class ModifyMaxAge < Faraday::Middleware
33
+ def initialize(app, time:)
34
+ @app = app
35
+ @time = Integer(time)
36
+ end
37
+
38
+ def call(request_env)
39
+ @app.call(request_env).on_complete do |response_env|
40
+ response_env[:response_headers][:cache_control] = "public, max-age=#{@time}, s-maxage=#{@time}"
41
+ end
42
+ end
43
+ end
44
+
9
45
  class Source < Nanoc::DataSource
10
46
  identifier :github
11
47
 
48
+ def up
49
+ stack = Faraday::RackBuilder.new do |builder|
50
+ builder.use Faraday::HttpCache,
51
+ serializer: Marshal,
52
+ shared_cache: false,
53
+ store: Cache.new(tmp_dir),
54
+ logger: verbose ? logger : nil
55
+ builder.use ModifyMaxAge, time: max_age
56
+ builder.use Faraday::Request::Retry,
57
+ exceptions: [Octokit::ServerError]
58
+ builder.use Octokit::Middleware::FollowRedirects
59
+ builder.use Octokit::Response::RaiseError
60
+ builder.use Octokit::Response::FeedParser
61
+ builder.adapter Faraday.default_adapter
62
+ end
63
+ Octokit.middleware = stack
64
+ end
65
+
12
66
  def items
13
67
  @items ||= begin
14
68
  repository_items.map do |item|
@@ -51,7 +105,7 @@ module Nanoc
51
105
  def encoding
52
106
  @config[:encoding] || "utf-8"
53
107
  end
54
-
108
+
55
109
  def concurrency
56
110
  @config[:concurrency] || 5
57
111
  end
@@ -67,6 +121,22 @@ module Nanoc
67
121
  def repository
68
122
  @config[:repository]
69
123
  end
124
+
125
+ def verbose
126
+ @config[:verbose]
127
+ end
128
+
129
+ def max_age
130
+ @config[:max_age] || 60
131
+ end
132
+
133
+ def logger
134
+ Logger.new(STDOUT)
135
+ end
136
+
137
+ def tmp_dir
138
+ File.join(@site_config.dir, "tmp")
139
+ end
70
140
  end
71
141
  end
72
142
  end
@@ -1,5 +1,5 @@
1
1
  module Nanoc
2
2
  module Github
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Pacana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-18 00:00:00.000000000 Z
11
+ date: 2020-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nanoc
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "<"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '2.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: faraday-http-cache
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
61
75
  description: |
62
76
  Nanoc content source from git repository. A way to have your writing in public and open for edition while not being
63
77
  distracted by static site generator trivia this content is usually mixed with.
@@ -96,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
110
  - !ruby/object:Gem::Version
97
111
  version: '0'
98
112
  requirements: []
99
- rubygems_version: 3.1.2
113
+ rubygems_version: 3.0.3
100
114
  signing_key:
101
115
  specification_version: 4
102
116
  summary: Nanoc content source from git repository