jekyll-notion 2.3.2 → 2.4.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: dadf92a4c00ce112ad5ca51e136b676a380b54fedfa75a9488ce5437d56a71d1
4
- data.tar.gz: df4431eab3308f7502082196c9d8bb8518b340c94d7c76950f0430664769afa1
3
+ metadata.gz: a99d9e0d1e2b47634401803cdd361f608540db56b02d8599a1723da1d8be635d
4
+ data.tar.gz: eb0c99a5c4d9f90e54c2b1c5111d3ae916cc92775c550760e82f87765e31011f
5
5
  SHA512:
6
- metadata.gz: 6d4aba49009378a8ca3e298d1de97d5285854bc5282c1aedb6e43ad7d6406a60baa0cfae614f33d027fa7a94353f2d03bd93405d6c8b60ac0ea72639a7f50f26
7
- data.tar.gz: 79bc2b133cd57a4da85216433564963ac56a49120ac36ed15aa8bb585fce64b54751f8a635816c1c9fc6afd968ad6289e4cc1dea854cee85576753cfd22e1397
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. Check [notion getting started guide](https://developers.notion.com/docs/getting-started) to learn more.
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 youe secret, export it in an environment variable named `NOTION_TOKEN`.
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://www.notion.so/help/intro-to-databases) has been shared, specify the database `id` in the `_config.yml` file as follows.
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.
@@ -39,7 +39,7 @@ module JekyllNotion
39
39
  end
40
40
 
41
41
  def build_blocks(block_id)
42
- NotionToMd::Blocks.build(block_id: block_id) do |nested_id|
42
+ NotionToMd::Blocks.build(:block_id => block_id) do |nested_id|
43
43
  @notion.block_children({ :block_id => nested_id })
44
44
  end
45
45
  end
@@ -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:", "NOTION_TOKEN not provided. Cannot read from 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 config provided.")
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllNotion
4
- VERSION = "2.3.2"
4
+ VERSION = "2.4.0"
5
5
  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.3.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: 2022-10-05 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
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
@@ -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