jekyll-notion 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -3
- data/lib/jekyll-notion/abstract_notion_resource.rb +1 -1
- data/lib/jekyll-notion/cacheable.rb +41 -0
- data/lib/jekyll-notion/generator.rb +19 -2
- data/lib/jekyll-notion/version.rb +1 -1
- data/lib/jekyll-notion.rb +2 -0
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a99d9e0d1e2b47634401803cdd361f608540db56b02d8599a1723da1d8be635d
|
4
|
+
data.tar.gz: eb0c99a5c4d9f90e54c2b1c5111d3ae916cc92775c550760e82f87765e31011f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06f5e378e96a41cf66bdf21e751165be504fdec9d3263b6a1db6a6a30e7c082d3988310d74bab49b35f2f330a1db244e42ce9fc31308fa42ee4c41a88e09a023
|
7
|
+
data.tar.gz: 7c4c1f8f39d728d3a830d6b3aa7ebfb96483a4823f14756ec40b388d0b2e79b7aba68371c1f5ae9feea3070f8d1e8a8265ef526045b315d17370e7bbd2686237
|
data/README.md
CHANGED
@@ -24,9 +24,9 @@ plugins:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
Before using the gem create an integration and generate a secret token.
|
27
|
+
Before using the gem, create an integration and generate a secret token. For more in-depth instructions, refer to the Notion "Getting Started" [guide](https://developers.notion.com/docs/getting-started).
|
28
28
|
|
29
|
-
Once you have
|
29
|
+
Once you have your secret token, make sure to export it into an environment variable named `NOTION_TOKEN`.
|
30
30
|
|
31
31
|
```bash
|
32
32
|
$ export NOTION_TOKEN=<secret_...>
|
@@ -34,7 +34,7 @@ $ export NOTION_TOKEN=<secret_...>
|
|
34
34
|
|
35
35
|
### Databases
|
36
36
|
|
37
|
-
Once the [notion database](https://
|
37
|
+
Once the [notion database](https://developers.notion.com/docs/working-with-databases) has been shared, specify the database `id` in the `_config.yml` file as follows.
|
38
38
|
|
39
39
|
```yml
|
40
40
|
notion:
|
@@ -155,6 +155,42 @@ notion:
|
|
155
155
|
|
156
156
|
And that's all. Each page in the notion database will be included in the selected collection.
|
157
157
|
|
158
|
+
### Cache
|
159
|
+
|
160
|
+
Starting from version 2.4.0, every request to Notion is cached locally. The cache enables the retrieval of Notion resources only during the first request. Subsequent requests are fetched from the cache, which can significantly reduce build times.
|
161
|
+
|
162
|
+
The cache mechanism is based on the [vcr](https://github.com/vcr/vcr) gem, which records HTTP requests. Every Notion resource, whether it is a database or page, is stored in an independent file using the document ID as the filename. For example, a database ID e42383cd49754897b967ce453760499f will be stored in the following path:
|
163
|
+
|
164
|
+
```bash
|
165
|
+
.cache/jekyll-notion/vcr_cassetes/e42383cd49754897b967ce453760499f.yml
|
166
|
+
```
|
167
|
+
|
168
|
+
**Note: The `cache` option invalidates the fetch_on_watch feature.**
|
169
|
+
|
170
|
+
#### Cache folder
|
171
|
+
|
172
|
+
By default, the cache folder is `.cache/jekyll-notion/vcr_cassetes`, but you can change this folder by setting the `cache_dir` property in the `_config.yml` file as follows.
|
173
|
+
|
174
|
+
```yaml
|
175
|
+
notion:
|
176
|
+
cache_dir: another/folder
|
177
|
+
```
|
178
|
+
|
179
|
+
The path must be relative to the working folder.
|
180
|
+
|
181
|
+
#### Cleaning cache
|
182
|
+
|
183
|
+
To clear the cache, delete the cache folder. If you want to remove a specific cache file, locate the file that matches the Notion resource ID and delete it.
|
184
|
+
|
185
|
+
#### Disabling cache
|
186
|
+
|
187
|
+
If you're not interested in the cache or you just want to disable it, set the ˋcache` option to false.
|
188
|
+
|
189
|
+
```yaml
|
190
|
+
notion:
|
191
|
+
cache: false
|
192
|
+
```
|
193
|
+
|
158
194
|
## Notion properties
|
159
195
|
|
160
196
|
Notion page properties are set for each document in the front matter.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
|
5
|
+
module JekyllNotion
|
6
|
+
module Cacheable
|
7
|
+
def self.setup(cache_dir)
|
8
|
+
# Using VCR to record and playback Notion API responses for caching
|
9
|
+
VCR.configure do |config|
|
10
|
+
config.cassette_library_dir = cache_path(cache_dir)
|
11
|
+
config.hook_into :faraday # Faraday is used by notion-ruby-client gem
|
12
|
+
config.filter_sensitive_data("<NOTION_TOKEN>") { ENV["NOTION_TOKEN"] }
|
13
|
+
config.allow_http_connections_when_no_cassette = true
|
14
|
+
config.default_cassette_options = {
|
15
|
+
:allow_playback_repeats => true,
|
16
|
+
:record => :new_episodes,
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.cache_path(path = nil)
|
22
|
+
if path.nil?
|
23
|
+
File.join(Dir.getwd, ".cache", "jekyll-notion", "vcr_cassettes")
|
24
|
+
else
|
25
|
+
File.join(Dir.getwd, path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def database_query(*args)
|
30
|
+
VCR.use_cassette((args[0][:database_id]).to_s) { super(*args) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def block_children(*args)
|
34
|
+
VCR.use_cassette((args[0][:block_id]).to_s) { super(*args) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def page(*args)
|
38
|
+
VCR.use_cassette((args[0][:page_id]).to_s) { super(*args) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -9,6 +9,8 @@ module JekyllNotion
|
|
9
9
|
|
10
10
|
return unless notion_token? && config?
|
11
11
|
|
12
|
+
setup
|
13
|
+
|
12
14
|
if fetch_on_watch? || cache_empty?
|
13
15
|
read_notion_databases
|
14
16
|
read_notion_pages
|
@@ -78,7 +80,8 @@ module JekyllNotion
|
|
78
80
|
|
79
81
|
def notion_token?
|
80
82
|
if ENV["NOTION_TOKEN"].nil? || ENV["NOTION_TOKEN"].empty?
|
81
|
-
Jekyll.logger.warn("Jekyll Notion:",
|
83
|
+
Jekyll.logger.warn("Jekyll Notion:",
|
84
|
+
"Cannot read from Notion becuase NOTION_TOKEN was not provided")
|
82
85
|
return false
|
83
86
|
end
|
84
87
|
true
|
@@ -86,10 +89,24 @@ module JekyllNotion
|
|
86
89
|
|
87
90
|
def config?
|
88
91
|
if config.empty?
|
89
|
-
Jekyll.logger.warn("Jekyll Notion:", "No
|
92
|
+
Jekyll.logger.warn("Jekyll Notion:", "No configuration provided")
|
90
93
|
return false
|
91
94
|
end
|
92
95
|
true
|
93
96
|
end
|
97
|
+
|
98
|
+
def setup
|
99
|
+
# Cache Notion API responses
|
100
|
+
if ENV["JEKYLL_ENV"] != "test" && cache?
|
101
|
+
JekyllNotion::Cacheable.setup(config["cache_dir"])
|
102
|
+
Notion::Client.prepend JekyllNotion::Cacheable
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def cache?
|
107
|
+
return true if config["cache"].nil?
|
108
|
+
|
109
|
+
config["cache"] == true.to_s
|
110
|
+
end
|
94
111
|
end
|
95
112
|
end
|
data/lib/jekyll-notion.rb
CHANGED
@@ -5,6 +5,7 @@ require "notion"
|
|
5
5
|
require "notion_to_md"
|
6
6
|
require "logger"
|
7
7
|
require "jekyll-notion/generator"
|
8
|
+
require "vcr"
|
8
9
|
|
9
10
|
NotionToMd::Logger.level = Logger::ERROR
|
10
11
|
|
@@ -24,4 +25,5 @@ module JekyllNotion
|
|
24
25
|
autoload :AbstractNotionResource, "jekyll-notion/abstract_notion_resource"
|
25
26
|
autoload :NotionDatabase, "jekyll-notion/notion_database"
|
26
27
|
autoload :NotionPage, "jekyll-notion/notion_page"
|
28
|
+
autoload :Cacheable, "jekyll-notion/cacheable"
|
27
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-notion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Enrique Arias
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -36,28 +36,42 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 1.0
|
39
|
+
version: '1.0'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 1.0
|
46
|
+
version: '1.0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: notion_to_md
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 2.
|
53
|
+
version: '2.2'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 2.
|
60
|
+
version: '2.2'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: vcr
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '6.2'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '6.2'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: bundler
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,28 +106,28 @@ dependencies:
|
|
92
106
|
requirements:
|
93
107
|
- - "~>"
|
94
108
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.12
|
109
|
+
version: '0.12'
|
96
110
|
type: :development
|
97
111
|
prerelease: false
|
98
112
|
version_requirements: !ruby/object:Gem::Requirement
|
99
113
|
requirements:
|
100
114
|
- - "~>"
|
101
115
|
- !ruby/object:Gem::Version
|
102
|
-
version: 0.12
|
116
|
+
version: '0.12'
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
118
|
name: simplecov
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
106
120
|
requirements:
|
107
121
|
- - "~>"
|
108
122
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.21
|
123
|
+
version: '0.21'
|
110
124
|
type: :development
|
111
125
|
prerelease: false
|
112
126
|
version_requirements: !ruby/object:Gem::Requirement
|
113
127
|
requirements:
|
114
128
|
- - "~>"
|
115
129
|
- !ruby/object:Gem::Version
|
116
|
-
version: 0.21
|
130
|
+
version: '0.21'
|
117
131
|
description:
|
118
132
|
email:
|
119
133
|
- emoriarty81@gmail.com
|
@@ -125,6 +139,7 @@ files:
|
|
125
139
|
- README.md
|
126
140
|
- lib/jekyll-notion.rb
|
127
141
|
- lib/jekyll-notion/abstract_notion_resource.rb
|
142
|
+
- lib/jekyll-notion/cacheable.rb
|
128
143
|
- lib/jekyll-notion/document_without_a_file.rb
|
129
144
|
- lib/jekyll-notion/factories/database_factory.rb
|
130
145
|
- lib/jekyll-notion/factories/page_factory.rb
|