jekyll-notion 0.0.0.alpha.2 → 0.0.0.beta

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: c85349b9010ff1ccbbc88b83e46315f8e31bc9b489943dce0c75c7a503820db3
4
- data.tar.gz: f0ae3ebe202b1cd3d184fe232d350b6024148a2bffe298a771c9221e1ac0684b
3
+ metadata.gz: bc64ea093044b7a8b5f0f1059e175d439b8b70fc1b4b08a30ea39438b4dc6d46
4
+ data.tar.gz: 608c37287a98f0ce89184616c27392048c9fdc725ab77f327e0cffb35fa4020b
5
5
  SHA512:
6
- metadata.gz: 1c98f9f772b8290d78e0ab393c5dbd55b419518a9f9baccd84906218e6a650d903027f10b85f120a779c71364f9a3d3ec2d8bd88fddf284f59fe2ffc80c1e3de
7
- data.tar.gz: 0fe7d15ad3c33de0929072ad7ba7df7f8c0ed22cb4aefb9084bfc868a2aa23641c08d3f1d8f6c22b8ac35b765b938a2e2798f02a028a2c37e4d41d4bfa51fca0
6
+ metadata.gz: 6c1b27117aee99b01dd988d243d1419b054447aa5afb02e5cffc5ed9120a8acd2e3a0b11759cccf6bd28a8657bc65e147307be501b2140421e961d48920c0f4d
7
+ data.tar.gz: cb1fbc6a9edb4069fd8019e5a29837bdf80a551c119a9371d7678f48ca10a32e58c5a5da2edbe4c4bff0c41d6d560041db0fbf9a26fdeb0bcf9101cd88d3cabd
data/README.md CHANGED
@@ -1,2 +1,59 @@
1
1
  # jekyll-notion
2
- Import pages from notion.
2
+
3
+ Import notion pages to a jekyll collection.
4
+
5
+ ## Installation
6
+
7
+ Use gem to install.
8
+ ```bash
9
+ $ gem install 'jekyll-notion'
10
+ ```
11
+
12
+ Or add it to the `Gemfile`.
13
+ ```ruby
14
+ # Gemfile
15
+ gem 'jekyll-notion'
16
+ ```
17
+
18
+ And update your jekyll plugins property in `_config.yml`.
19
+
20
+ ```yml
21
+ plugins:
22
+ - jekyll-notion
23
+ ```
24
+
25
+ ## Setup
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.
28
+
29
+ Export the notion secret token in an environment variable named `NOTION_TOKEN`.
30
+
31
+ ```bash
32
+ $ export NOTION_TOKEN=<secret_...>
33
+ ```
34
+
35
+ Once your notion database has been shared, specify the `id` in your `_config.yml` as follows.
36
+
37
+ ```yml
38
+ notion:
39
+ database:
40
+ id: b91d5...
41
+ collection: posts
42
+ layout: post
43
+ filter: { "property": "Published", "checkbox": { "equals": true } }
44
+ sort: { "propery": "Last ordered", "direction": "ascending" }
45
+ frontmatter:
46
+ prop_1: blabla
47
+ prop_2: albalb
48
+ ```
49
+
50
+ The other properties are:
51
+ * `collection`: what collection each page belongs to,
52
+ * `layout`: the collection layout,
53
+ * `filter`: the database query filter,
54
+ * `sort`: the database query sort,
55
+ * `frontmatter`: additonal frontmatter to append to each page in the collection.
56
+
57
+ Note: Only one database is available.
58
+
59
+ And that's all. Each page in the notion database will be included in the selected collection.
@@ -10,17 +10,25 @@ module JekyllNotion
10
10
 
11
11
  def generate(site)
12
12
  @site = site
13
+
14
+ return unless notion_token?
15
+ return unless config?
16
+
17
+ read_notion_database
18
+ end
19
+
20
+ def read_notion_database
13
21
  @db = NotionDatabase.new(config: config)
14
22
  @db.pages do |page|
15
23
  @current_page = page
16
- site.posts.docs << make_page
17
- Jekyll.logger.info("New page from notion", site.posts.docs.last.path)
24
+ collection.docs << make_page
25
+ Jekyll.logger.info('Jekyll Notion:', "New notion page at #{collection.docs.last.path}")
18
26
  end
19
27
  end
20
28
 
21
29
  def make_page
22
30
  new_post = DocumentWithoutAFile.new(
23
- "#{Dir.pwd}/_#{config['collection']}/#{make_filename}",
31
+ "#{Dir.pwd}/_#{config.dig('database', 'collection')}/#{make_filename}",
24
32
  { site: @site, collection: collection }
25
33
  )
26
34
  new_post.content = "#{make_frontmatter}\n\n#{make_md}"
@@ -34,7 +42,7 @@ module JekyllNotion
34
42
 
35
43
  def make_frontmatter
36
44
  <<-CONTENT
37
- #{config['frontmatter'].to_yaml}
45
+ #{config.dig('database', 'frontmatter').to_yaml}
38
46
  id: #{current_page.id}
39
47
  layout: #{current_page.layout}
40
48
  title: #{current_page.title}
@@ -49,11 +57,27 @@ cover: #{current_page.cover}
49
57
  end
50
58
 
51
59
  def collection
52
- @site.send(config['collection'].to_sym)
60
+ @site.send(config.dig('database', 'collection').to_sym)
53
61
  end
54
62
 
55
63
  def config
56
64
  @config ||= @site.config["notion"] || {}
57
65
  end
66
+
67
+ def notion_token?
68
+ if ENV['NOTION_TOKEN'].nil? || ENV['NOTION_TOKEN'].empty?
69
+ Jekyll.logger.error('Jekyll Notion:', 'NOTION_TOKEN not provided. Cannot read from Notion.')
70
+ return false
71
+ end
72
+ true
73
+ end
74
+
75
+ def config?
76
+ if config.empty?
77
+ Jekyll.logger.error('Jekyll Notion:', 'No config provided.')
78
+ return false
79
+ end
80
+ true
81
+ end
58
82
  end
59
83
  end
@@ -9,7 +9,7 @@ module JekyllNotion
9
9
 
10
10
  def pages
11
11
  @pages ||= @notion.database_query(query)[:results].map do |page|
12
- NotionPage.new(page: page, layout: @config['layout'])
12
+ NotionPage.new(page: page, layout: config['layout'])
13
13
  end
14
14
 
15
15
  return @pages unless block_given?
@@ -19,6 +19,10 @@ module JekyllNotion
19
19
 
20
20
  private
21
21
 
22
+ def config
23
+ @config['database']
24
+ end
25
+
22
26
  def filter
23
27
  @config.dig('database', 'filter')
24
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllNotion
4
- VERSION = '0.0.0.alpha.2'
4
+ VERSION = '0.0.0.beta'
5
5
  end
data/lib/jekyll-notion.rb CHANGED
@@ -10,7 +10,7 @@ require 'jekyll-notion/generator'
10
10
  NotionToMd::Logger.level = Logger::ERROR
11
11
 
12
12
  Notion.configure do |config|
13
- config.token = ENV['NOTION_TOKEN']
13
+ config.token = ENV['NOTION_TOKEN']
14
14
  end
15
15
 
16
16
  module JekyllNotion
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: 0.0.0.alpha.2
4
+ version: 0.0.0.beta
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-01-14 00:00:00.000000000 Z
11
+ date: 2022-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport