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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28969fe017d3182ae86953154bef64b2faf3fea5477eea3b315af7b0c6e99def
4
- data.tar.gz: 4fe4fdeb77eaaafcadd5adce283e2a77e17ea9bfa57c32464e0c45d467038827
3
+ metadata.gz: 1a2d58cc88c6a7012d3efc3eb431e9030f6287feec5b1307d731fb2b8a78a6e5
4
+ data.tar.gz: 939b5e04a4b019fd7a295dfba5c765e4f5fb5bf0f41e1b3527b01d84bf02a2cf
5
5
  SHA512:
6
- metadata.gz: 30a409cbf940624c5d60556f50c70f19edcdd6d936b969faf375f410cf5ecfaea940eb0441de1ff527717bfdef5f0580a35d7619e41f3e6ff2d75f0851776a55
7
- data.tar.gz: dd5ae8d678bc6f6ebeef2703e2722161a36cecef145a275146818bea6fb0abccdb3cb9427bf1020cdd33271912e1c10c75c395eea86d51d371b6fc2fd548fe49
6
+ metadata.gz: bf6461f39325a08b18dfdd18ac9413e50991bc7c18032c30e59bba013ae00f77cab5b79ddcbf44100d4248cc957b98ccfd0538ddf323e3881f408e7ff5c46762
7
+ data.tar.gz: d451dfcbe921c165c232fa7a6195471f7da133ab6ddb46feadcc2705771cbc6092462e8ec29fa128b7d1c14db816b77ce84d07c05d2287eb53e93e4da9e7c06c
data/README.md CHANGED
@@ -1,2 +1,81 @@
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
+ filter: { "property": "Published", "checkbox": { "equals": true } }
43
+ sort: { "propery": "Last ordered", "direction": "ascending" }
44
+ frontmatter:
45
+ layout: post
46
+ ```
47
+
48
+ The other properties are:
49
+ * `collection`: what collection each page belongs to,
50
+ * `filter`: the database query filter,
51
+ * `sort`: the database query sort,
52
+ * `frontmatter`: additional frontmatter to append to each page in the collection.
53
+
54
+ Note: Only one database is available.
55
+
56
+ And that's all. Each page in the notion database will be included in the selected collection.
57
+
58
+ ## Notion properties
59
+
60
+ Below, page notion default properties are set in each page frontmatter.
61
+
62
+ ```
63
+ ---
64
+ id: id
65
+ title: properties > Name > title > plain_text
66
+ cover: cover > external > url
67
+ date: created_time
68
+ ---
69
+ ```
70
+
71
+ ## Page filename
72
+
73
+ There are two kinds of collections: posts and others.
74
+
75
+ 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).
76
+
77
+ ```
78
+ YEAR-MONTH-DAY-title.MARKUP
79
+ ```
80
+
81
+ Any other collection, the filename is the page title.
@@ -2,11 +2,11 @@
2
2
 
3
3
  module JekyllNotion
4
4
  class DocumentWithoutAFile < Jekyll::Document
5
- def read_content(new_content, **opts)
5
+ def read_content(_new_content, **_opts)
6
6
  if content =~ YAML_FRONT_MATTER_REGEXP
7
- self.content = $POSTMATCH
7
+ self.content = Regexp.last_match.post_match
8
8
  data_file = SafeYAML.load(Regexp.last_match(1))
9
- merge_data!(data_file, :source => "YAML front matter") if data_file
9
+ merge_data!(data_file, source: 'YAML front matter') if data_file
10
10
  end
11
11
  end
12
12
  end
@@ -1,31 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/inflector'
4
- require 'notion'
5
- require 'notion_to_md'
6
- require_relative './notion_database'
7
-
8
3
  module JekyllNotion
9
4
  class Generator < Jekyll::Generator
10
5
  attr_reader :current_page
11
6
 
12
- def initialize(plugin)
13
- super(plugin)
14
- end
15
-
16
7
  def generate(site)
17
8
  @site = site
9
+
10
+ return unless notion_token?
11
+ return unless config?
12
+
13
+ read_notion_database
14
+ end
15
+
16
+ def read_notion_database
18
17
  @db = NotionDatabase.new(config: config)
19
18
  @db.pages do |page|
20
19
  @current_page = page
21
- site.posts.docs << make_page
22
- Jekyll.logger.info("New page from notion", site.posts.docs.last.path)
20
+ collection.docs << make_page
21
+ Jekyll.logger.info('Jekyll Notion:', "New notion page at #{collection.docs.last.path}")
23
22
  end
24
23
  end
25
24
 
26
25
  def make_page
27
26
  new_post = DocumentWithoutAFile.new(
28
- "#{Dir.pwd}/_#{config['collection']}/#{make_filename}",
27
+ "#{Dir.pwd}/_#{collection_name}/#{make_filename}",
29
28
  { site: @site, collection: collection }
30
29
  )
31
30
  new_post.content = "#{make_frontmatter}\n\n#{make_md}"
@@ -38,27 +37,50 @@ module JekyllNotion
38
37
  end
39
38
 
40
39
  def make_frontmatter
41
- <<-CONTENT
42
- #{config['frontmatter'].to_yaml}
43
- id: #{current_page.id}
44
- layout: #{current_page.layout}
45
- title: #{current_page.title}
46
- date: #{current_page.created_datetime.to_s}
47
- cover: #{current_page.cover}
48
- ---
40
+ <<~CONTENT
41
+ #{config.dig('database', 'frontmatter').to_yaml}
42
+ id: #{current_page.id}
43
+ title: #{current_page.title}
44
+ date: #{current_page.created_datetime}
45
+ cover: #{current_page.cover}
46
+ ---
49
47
  CONTENT
50
48
  end
51
49
 
52
50
  def make_filename
53
- "#{current_page.created_date.to_s}-#{current_page.title.downcase.parameterize}.md"
51
+ if collection_name == 'posts'
52
+ "#{current_page.created_date}-#{current_page.title.downcase.parameterize}.md"
53
+ else
54
+ "#{current_page.title.downcase.parameterize}.md"
55
+ end
56
+ end
57
+
58
+ def collection_name
59
+ config.dig('database', 'collection')
54
60
  end
55
61
 
56
62
  def collection
57
- @site.send(config['collection'].to_sym)
63
+ @site.send(collection_name.to_sym)
58
64
  end
59
65
 
60
66
  def config
61
- @config ||= @site.config["notion"] || {}
67
+ @config ||= @site.config['notion'] || {}
68
+ end
69
+
70
+ def notion_token?
71
+ if ENV['NOTION_TOKEN'].nil? || ENV['NOTION_TOKEN'].empty?
72
+ Jekyll.logger.error('Jekyll Notion:', 'NOTION_TOKEN not provided. Cannot read from Notion.')
73
+ return false
74
+ end
75
+ true
76
+ end
77
+
78
+ def config?
79
+ if config.empty?
80
+ Jekyll.logger.error('Jekyll Notion:', 'No config provided.')
81
+ return false
82
+ end
83
+ true
62
84
  end
63
85
  end
64
86
  end
@@ -1,4 +1,4 @@
1
- require_relative './notion_page'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module JekyllNotion
4
4
  class NotionDatabase
@@ -7,18 +7,22 @@ module JekyllNotion
7
7
  @config = config
8
8
  end
9
9
 
10
- def pages
10
+ def pages(&block)
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?
16
16
 
17
- @pages.each { |page| yield page }
17
+ @pages.each(&block)
18
18
  end
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
@@ -31,8 +35,8 @@ module JekyllNotion
31
35
  @config.dig('database', 'id')
32
36
  end
33
37
 
34
- def query
38
+ def query
35
39
  { id: id, filter: filter, sort: sort }
36
40
  end
37
41
  end
38
- end
42
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllNotion
2
4
  class NotionPage
3
5
  attr_reader :page, :layout
@@ -30,7 +32,7 @@ module JekyllNotion
30
32
  end
31
33
 
32
34
  def created_datetime
33
- DateTime.parse(page["created_time"])
35
+ DateTime.parse(page['created_time'])
34
36
  end
35
37
 
36
38
  def updated_date
@@ -38,11 +40,11 @@ module JekyllNotion
38
40
  end
39
41
 
40
42
  def updated_datetime
41
- DateTime.parse(page["last_edited_time"])
43
+ DateTime.parse(page['last_edited_time'])
42
44
  end
43
45
 
44
46
  def url
45
47
  page[:url]
46
48
  end
47
49
  end
48
- end
50
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllNotion
2
- VERSION = '0.0.0.alpha'
3
- end
4
+ VERSION = '0.0.0.beta.1'
5
+ end
data/lib/jekyll-notion.rb CHANGED
@@ -1,10 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jekyll'
2
4
  require 'notion'
3
- require 'notion_to_md/logger'
5
+ require 'notion_to_md'
4
6
  require 'logger'
7
+ require 'active_support/inflector'
8
+ require 'jekyll-notion/generator'
5
9
 
6
10
  NotionToMd::Logger.level = Logger::ERROR
7
11
 
8
12
  Notion.configure do |config|
9
- config.token = ENV['NOTION_TOKEN']
10
- end
13
+ config.token = ENV['NOTION_TOKEN']
14
+ end
15
+
16
+ module JekyllNotion
17
+ autoload :DocumentWithoutAFile, 'jekyll-notion/document_without_a_file'
18
+ autoload :NotionDatabase, 'jekyll-notion/notion_database'
19
+ autoload :NotionPage, 'jekyll-notion/notion_page'
20
+ 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: 0.0.0.alpha
4
+ version: 0.0.0.beta.1
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-13 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
@@ -45,7 +45,7 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '5.0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: notion_to_md
48
+ name: notion-ruby-client
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
@@ -59,7 +59,7 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: notion-ruby-client
62
+ name: notion_to_md
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"