jekyll-notion 1.2.0 → 2.0.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: ac8561afc4f42d433ae33d4baafb38e9eaf7a34167513bf628eef849c3e773b7
4
- data.tar.gz: 7c55ac94b8490943d981f3c25d36d0b3993680614ba25cdb16be78f07b5e028a
3
+ metadata.gz: 79520a9f4d598b024d2934fd68140f0f34775e2611ff601b1352ba60f67e9dd3
4
+ data.tar.gz: bcd325965c4eec49a498fe99c2101fa238f6c67587cb13723927abe0b8e83c1f
5
5
  SHA512:
6
- metadata.gz: d402be5b38a3dc4cae78daf0e95140ecc0b593db1091ac325f262a68024236f50639c25f1bee42db6cee025122bfb82d2318f312909278509c66f2375062d4d1
7
- data.tar.gz: c22e49f752ba7a848c6329e55c57707c6bc9d59e510f5407a112448335a9a36b877c9abe4e94cf30fd383db29defd5fafbba14558742417375c4df4990f91a90
6
+ metadata.gz: 17ca3742b0b48a22dd7cca185c25f9368565e7af35ccdc3e9add259faa20aa101e908aac961363c1ecf2b0d2f6822153e6b7d4a6bc53a3dc1d49697cb1199bc1
7
+ data.tar.gz: 0a46f5e5ce29f09bc1966ac4199a080da5eea58cedcaa37062cf5fd3bc77b35a8ad45bbf1067d01d32ca9094e53e36e21223187b8c3d94970ef092eb09ca56d0
data/README.md CHANGED
@@ -22,16 +22,18 @@ plugins:
22
22
  - jekyll-notion
23
23
  ```
24
24
 
25
- ## Setup
25
+ ## Usage
26
26
 
27
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.
28
28
 
29
- Export the notion secret token in an environment variable named `NOTION_TOKEN`.
29
+ Once you have youe secret, export it in an environment variable named `NOTION_TOKEN`.
30
30
 
31
31
  ```bash
32
32
  $ export NOTION_TOKEN=<secret_...>
33
33
  ```
34
34
 
35
+ ### Databases
36
+
35
37
  Once your [notion database](https://www.notion.so/help/intro-to-databases) has been shared, specify the database `id` in your `_config.yml` as follows.
36
38
 
37
39
  ```yml
@@ -40,12 +42,9 @@ notion:
40
42
  id: 5cfed4de3bdc4f43ae8ba653a7a2219b
41
43
  ```
42
44
 
43
- After running `jekyll build` (or `serve`) command, the `posts` collection is loaded with pages of the notion database specified in the configuration.
44
-
45
+ By default, the notion pages contained in the database will be loaded into the `posts` collection.
45
46
 
46
- ### Mutiple dabatases
47
-
48
- You can also define multiple databases as follows.
47
+ You can also define __multiple databases__ as follows.
49
48
 
50
49
  ```yml
51
50
  collections:
@@ -61,63 +60,86 @@ notion:
61
60
  collection: films
62
61
  ```
63
62
 
64
- ### Data
63
+ After running `jekyll build` (or `serve`) command, the `posts`, `recipes` and `films` collections will be loaded with pages from the notion databases.
65
64
 
66
- Instead of storing notion pages in a collection, you can also map to the data object. Use the `data` property instead of `collection`.
65
+ #### Database options
66
+
67
+ Each dabatase support the following options.
68
+
69
+ * `id`: the notion database unique identifier,
70
+ * `collection`: the collection each page belongs to (posts by default),
71
+ * `filter`: the database query filter,
72
+ * `sort`: the database query sort,
67
73
 
68
74
  ```yml
69
75
  notion:
70
76
  database:
71
77
  id: e42383cd49754897b967ce453760499f
72
- data: films
78
+ collection: posts
79
+ filter: { "property": "Published", "checkbox": { "equals": true } }
80
+ sort: { "property": "Last ordered", "direction": "ascending" }
73
81
  ```
74
82
 
75
- Page properties and body are stored as a hash data.
83
+ ### Pages
76
84
 
77
- As a particular characteristic, the page is stored in a key named `content`.
85
+ Individual Notion pages can also be loaded into Jekyll. Just define the `page` property as follows.
78
86
 
79
- ```html
80
- <p>{{ site.data.films.content }}</p>
87
+ ```yml
88
+ notion:
89
+ page:
90
+ id: 5cfed4de3bdc4f43ae8ba653a7a2219b
81
91
  ```
82
92
 
83
- The rest of properties as mapped as expected.
84
-
85
- ### Pages
86
-
87
- Individual Notion pages can also be mapped to data. Just define the `pages` or `page` property as follows.
93
+ As databases, we can set up multiple pages.
88
94
 
89
95
  ```yaml
90
96
  notion:
91
97
  pages:
92
98
  - id: e42383cd49754897b967ce453760499f
93
- data: about
94
99
  - id: b0e688e199af4295ae80b67eb52f2e2f
95
- data: contact
96
100
  - id: 2190450d4cb34739a5c8340c4110fe21
97
- data: footer
98
-
99
101
  ```
100
102
 
101
- _This feature is only available for data._
103
+ The filename of the generated page is the notion page title. Check [below](#page-filename) for more info.
102
104
 
103
- ### Database options
105
+ All properties assigned to a notion page will be interpreted by jekyll as front matter. For example, if the [permalink](https://jekyllrb.com/docs/permalinks/#front-matter) property is set to `/about/` in the notion page, jekyll will use it to create the corresponding path at the output directory at `/about/index.html`.
104
106
 
105
- Each dabatase support the following options.
107
+ ### Data
106
108
 
107
- * `id`: the notion database unique identifier,
108
- * `collection`: the collection each page belongs to (posts by default),
109
- * `filter`: the database query filter,
110
- * `sort`: the database query sort,
109
+ Instead of storing the notion pages in a collection or in the pages list, you can assign them to the data object.Just declare the `data` property next to the page or database id.
111
110
 
112
111
  ```yml
113
112
  notion:
114
- database:
115
- id: e42383cd49754897b967ce453760499f
116
- collection: posts
117
- filter: { "property": "Published", "checkbox": { "equals": true } }
118
- sort: { "property": "Last ordered", "direction": "ascending" }
113
+ databases:
114
+ - id: b0e688e199af4295ae80b67eb52f2e2f
115
+ - id: e42383cd49754897b967ce453760499f
116
+ data: films
117
+ pages:
118
+ - id: e42383cd49754897b967ce453760499f
119
+ - id: b0e688e199af4295ae80b67eb52f2e2f
120
+ data: about
119
121
  ```
120
122
 
123
+ Page properties and body of the notion page are stored as a hash object.
124
+
125
+ In the previous example, data objects can be accesses as follows.
126
+
127
+ ```html
128
+ <ul>
129
+ {% for film in site.data.films %}
130
+ <li>{{ film.title }}</li>
131
+ {% endfor %}
132
+ </ul>
133
+ ```
134
+
135
+ Notice, the page body is stored in the key `content`.
136
+
137
+ ```html
138
+ {{ site.data.about.content }}
139
+ ```
140
+
141
+ The rest of properties are mapped as expected. For more info go to [notion properties](#notion-properties).
142
+
121
143
  ### Watch
122
144
 
123
145
  By default, databases are only requested during the first build. Subsequent builds use the results from the cache.
@@ -156,12 +178,12 @@ Please, refer to the [notion_to_md](https://github.com/emoriarty/notion_to_md/)
156
178
 
157
179
  ## Page filename
158
180
 
159
- There are two kinds of collections: posts and others.
181
+ There are two kinds of documents in Jekyll: posts and others.
160
182
 
161
- When the collection is posts, the filename format contains the `created_time` property plus the page title as specified in [jekyll docs](https://jekyllrb.com/docs/posts/#creating-posts).
183
+ When the document is a post, the filename format contains the `created_time` property plus the page title as specified in [jekyll docs](https://jekyllrb.com/docs/posts/#creating-posts).
162
184
 
163
185
  ```
164
186
  YEAR-MONTH-DAY-title.MARKUP
165
187
  ```
166
188
 
167
- Any other collection, the filename is the page title.
189
+ The filename for any other document is the page title.
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllNotion
4
- class GeneratorFactory
4
+ class DatabaseFactory
5
5
  def self.for(notion_resource:, site:, plugin:)
6
- if notion_resource.is_a?(NotionDatabase) && notion_resource.data_name.nil?
6
+ if notion_resource.data_name.nil?
7
7
  CollectionGenerator.new(:notion_resource => notion_resource, :site => site,
8
8
  :plugin => plugin)
9
9
  else
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllNotion
4
+ class PageFactory
5
+ def self.for(notion_resource:, site:, plugin:)
6
+ if notion_resource.data_name.nil?
7
+ PageGenerator.new(:notion_resource => notion_resource, :site => site,
8
+ :plugin => plugin)
9
+ else
10
+ DataGenerator.new(:notion_resource => notion_resource, :site => site, :plugin => plugin)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -9,20 +9,21 @@ module JekyllNotion
9
9
 
10
10
  return unless notion_token? && config?
11
11
 
12
- if fetch_on_watch? || collections_and_data_empty?
12
+ if fetch_on_watch? || cache_empty?
13
13
  read_notion_databases
14
14
  read_notion_pages
15
15
  else
16
16
  collections.each_pair { |key, val| @site.collections[key] = val }
17
17
  data.each_pair { |key, val| @site.data[key] = val }
18
+ pages.each { |page| @site.pages << page }
18
19
  end
19
20
  end
20
21
 
21
- def databases
22
+ def config_databases
22
23
  config["databases"] || [config["database"]]
23
24
  end
24
25
 
25
- def pages
26
+ def config_pages
26
27
  config["pages"] || [config["page"]]
27
28
  end
28
29
 
@@ -34,23 +35,27 @@ module JekyllNotion
34
35
  @data ||= {}
35
36
  end
36
37
 
38
+ def pages
39
+ @pages ||= []
40
+ end
41
+
37
42
  protected
38
43
 
39
- def collections_and_data_empty?
40
- collections.empty? && data.empty?
44
+ def cache_empty?
45
+ collections.empty? && pages.empty? && data.empty?
41
46
  end
42
47
 
43
48
  def read_notion_databases
44
- databases.each do |db_config|
49
+ config_databases.each do |db_config|
45
50
  db = NotionDatabase.new(:config => db_config)
46
- GeneratorFactory.for(:notion_resource => db, :site => @site, :plugin => self).generate
51
+ DatabaseFactory.for(:notion_resource => db, :site => @site, :plugin => self).generate
47
52
  end
48
53
  end
49
54
 
50
55
  def read_notion_pages
51
- pages.each do |page_config|
56
+ config_pages.each do |page_config|
52
57
  page = NotionPage.new(:config => page_config)
53
- GeneratorFactory.for(:notion_resource => page, :site => @site, :plugin => self).generate
58
+ PageFactory.for(:notion_resource => page, :site => @site, :plugin => self).generate
54
59
  end
55
60
  end
56
61
 
@@ -57,7 +57,7 @@ module JekyllNotion
57
57
  "collections", @notion_resource.collection_name, "output"
58
58
  )
59
59
  Jekyll.logger.info("",
60
- "Path => #{collection.docs.last.path}")
60
+ "URL => #{collection.docs.last.url}")
61
61
  end
62
62
  Jekyll.logger.debug("", "Props => #{collection.docs.last.data.keys.inspect}")
63
63
  end
@@ -28,7 +28,7 @@ module JekyllNotion
28
28
  # Returns String the converted content.
29
29
  def convert(page)
30
30
  converters.reduce(page.body) do |output, converter|
31
- converter.convert output
31
+ converter.convert(output)
32
32
  rescue StandardError => e
33
33
  Jekyll.logger.error "Conversion error:",
34
34
  "#{converter.class} encountered an error while "\
@@ -44,14 +44,16 @@ module JekyllNotion
44
44
 
45
45
  def log_pages
46
46
  if data.is_a?(Array)
47
- data.each do |page|
48
- Jekyll.logger.info("Jekyll Notion:", "Page => #{page["title"]}")
49
- Jekyll.logger.debug("", "Props => #{page.keys.inspect}")
50
- end
47
+ data.each { |page| log_page(page, Array.to_s) }
51
48
  else
52
- Jekyll.logger.info("Jekyll Notion:", "Page => #{data["title"]}")
53
- Jekyll.logger.debug("", "Props => #{data.keys.inspect}")
49
+ log_page(data, Hash.to_s)
54
50
  end
55
51
  end
52
+
53
+ def log_page(page, type)
54
+ Jekyll.logger.info("Jekyll Notion:", "Page => #{page["title"]}")
55
+ Jekyll.logger.info("", "#{type} => site.data.#{@notion_resource.data_name}")
56
+ Jekyll.logger.debug("", "Props => #{page.keys.inspect}")
57
+ end
56
58
  end
57
59
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllNotion
4
+ class PageGenerator < AbstractGenerator
5
+ def generate
6
+ notion_page = @notion_resource.fetch
7
+ unless notion_page.nil?
8
+ page = make_page(notion_page)
9
+ @site.pages << page
10
+ log_page(notion_page)
11
+ @plugin.pages << page
12
+ end
13
+ end
14
+
15
+ def make_page(notion_page)
16
+ JekyllNotion::PageWithoutAFile.new(@site, @site.source, "", "#{notion_page.title}.md",
17
+ make_md)
18
+ end
19
+
20
+ def log_page(notion_page)
21
+ Jekyll.logger.info("Jekyll Notion:", "Page => #{notion_page.title}")
22
+ Jekyll.logger.info("", "URL => #{@site.pages.last.url}")
23
+ Jekyll.logger.debug("", "Props => #{notion_page.props.keys.inspect}")
24
+ end
25
+
26
+ def make_md
27
+ NotionToMd::Converter.new(:page_id => @notion_resource.id).convert(:frontmatter => true)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllNotion
4
+ class PageWithoutAFile < Jekyll::Page
5
+ def initialize(site, base, dir, name, new_content)
6
+ self.content = new_content
7
+ super(site, base, dir, name)
8
+ end
9
+
10
+ def read_yaml(base, name, _opts = {})
11
+ filename = @path || site.in_source_dir(base, name)
12
+ Jekyll.logger.debug "Reading:", relative_path
13
+
14
+ begin
15
+ if content =~ Jekyll::Document::YAML_FRONT_MATTER_REGEXP
16
+ self.content = Regexp.last_match.post_match
17
+ self.data = SafeYAML.load(Regexp.last_match(1))
18
+ end
19
+ rescue Psych::SyntaxError => e
20
+ Jekyll.logger.warn "YAML Exception reading page #{name}: #{e.message}"
21
+ raise e if site.config["strict_front_matter"]
22
+ end
23
+
24
+ self.data ||= {}
25
+
26
+ validate_data! filename
27
+ validate_permalink! filename
28
+
29
+ self.data
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllNotion
4
- VERSION = "1.2.0"
4
+ VERSION = "2.0.0"
5
5
  end
data/lib/jekyll-notion.rb CHANGED
@@ -13,12 +13,15 @@ Notion.configure do |config|
13
13
  end
14
14
 
15
15
  module JekyllNotion
16
- autoload :GeneratorFactory, "jekyll-notion/generator_factory"
17
- autoload :AbstractGenerator, "jekyll-notion/abstract_generator"
18
- autoload :AbstractNotionResource, "jekyll-notion/abstract_notion_resource"
19
- autoload :CollectionGenerator, "jekyll-notion/collection_generator"
20
- autoload :DataGenerator, "jekyll-notion/data_generator"
16
+ autoload :DatabaseFactory, "jekyll-notion/factories/database_factory"
17
+ autoload :PageFactory, "jekyll-notion/factories/page_factory"
18
+ autoload :AbstractGenerator, "jekyll-notion/generators/abstract_generator"
19
+ autoload :DataGenerator, "jekyll-notion/generators/data_generator"
20
+ autoload :PageGenerator, "jekyll-notion/generators/page_generator"
21
+ autoload :CollectionGenerator, "jekyll-notion/generators/collection_generator"
21
22
  autoload :DocumentWithoutAFile, "jekyll-notion/document_without_a_file"
23
+ autoload :PageWithoutAFile, "jekyll-notion/page_without_a_file"
24
+ autoload :AbstractNotionResource, "jekyll-notion/abstract_notion_resource"
22
25
  autoload :NotionDatabase, "jekyll-notion/notion_database"
23
26
  autoload :NotionPage, "jekyll-notion/notion_page"
24
27
  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: 1.2.0
4
+ version: 2.0.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-03-09 00:00:00.000000000 Z
11
+ date: 2022-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -110,15 +110,18 @@ extra_rdoc_files:
110
110
  files:
111
111
  - README.md
112
112
  - lib/jekyll-notion.rb
113
- - lib/jekyll-notion/abstract_generator.rb
114
113
  - lib/jekyll-notion/abstract_notion_resource.rb
115
- - lib/jekyll-notion/collection_generator.rb
116
- - lib/jekyll-notion/data_generator.rb
117
114
  - lib/jekyll-notion/document_without_a_file.rb
115
+ - lib/jekyll-notion/factories/database_factory.rb
116
+ - lib/jekyll-notion/factories/page_factory.rb
118
117
  - lib/jekyll-notion/generator.rb
119
- - lib/jekyll-notion/generator_factory.rb
118
+ - lib/jekyll-notion/generators/abstract_generator.rb
119
+ - lib/jekyll-notion/generators/collection_generator.rb
120
+ - lib/jekyll-notion/generators/data_generator.rb
121
+ - lib/jekyll-notion/generators/page_generator.rb
120
122
  - lib/jekyll-notion/notion_database.rb
121
123
  - lib/jekyll-notion/notion_page.rb
124
+ - lib/jekyll-notion/page_without_a_file.rb
122
125
  - lib/jekyll-notion/version.rb
123
126
  homepage: https://github.com/emoriarty/jekyll-notion
124
127
  licenses: