jekyll-notion 0.0.0.beta → 0.0.1

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: bc64ea093044b7a8b5f0f1059e175d439b8b70fc1b4b08a30ea39438b4dc6d46
4
- data.tar.gz: 608c37287a98f0ce89184616c27392048c9fdc725ab77f327e0cffb35fa4020b
3
+ metadata.gz: 7d1ccb2f2f5451b3eaf6d80dd8f8fed62cd2d5fd582d1cce09fbf10a494b54ac
4
+ data.tar.gz: f651dd2f6e3c5404b33af0abdb11274eacc34296c6301e9d79d76f38ccb8f1e6
5
5
  SHA512:
6
- metadata.gz: 6c1b27117aee99b01dd988d243d1419b054447aa5afb02e5cffc5ed9120a8acd2e3a0b11759cccf6bd28a8657bc65e147307be501b2140421e961d48920c0f4d
7
- data.tar.gz: cb1fbc6a9edb4069fd8019e5a29837bdf80a551c119a9371d7678f48ca10a32e58c5a5da2edbe4c4bff0c41d6d560041db0fbf9a26fdeb0bcf9101cd88d3cabd
6
+ metadata.gz: f87ce41674b28e289e7b69a0d4a40ac64fc0c9e9384ce5fdfb9b82312ba439ba60c5b7bab2a8ead2d1075adffd4a852bbae7534acc67d5317221c5fe236b52bf
7
+ data.tar.gz: 9ac472cd2c48b0affd89825b8d08a11fb8e562ac8da05193111bcc85f219196352345f4c6ebd6ff0b9721c847f00e30fc0820190fa8dd6950758355b24aafbd5
data/README.md CHANGED
@@ -39,21 +39,45 @@ notion:
39
39
  database:
40
40
  id: b91d5...
41
41
  collection: posts
42
- layout: post
43
42
  filter: { "property": "Published", "checkbox": { "equals": true } }
44
43
  sort: { "propery": "Last ordered", "direction": "ascending" }
45
44
  frontmatter:
46
- prop_1: blabla
47
- prop_2: albalb
45
+ layout: post
48
46
  ```
49
47
 
50
48
  The other properties are:
51
- * `collection`: what collection each page belongs to,
52
- * `layout`: the collection layout,
49
+ * `collection`: the collection each page belongs to (posts by default),
53
50
  * `filter`: the database query filter,
54
51
  * `sort`: the database query sort,
55
- * `frontmatter`: additonal frontmatter to append to each page in the collection.
52
+ * `frontmatter`: additional frontmatter to append to each page in the collection.
56
53
 
57
54
  Note: Only one database is available.
58
55
 
59
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
+ Any property provided in the frontmatter config that matches a default property will be overwritten by the default value.
72
+
73
+ ## Page filename
74
+
75
+ There are two kinds of collections: posts and others.
76
+
77
+ 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).
78
+
79
+ ```
80
+ YEAR-MONTH-DAY-title.MARKUP
81
+ ```
82
+
83
+ Any other collection, the filename is the page title.
@@ -2,9 +2,9 @@
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
9
  merge_data!(data_file, :source => "YAML front matter") if data_file
10
10
  end
@@ -4,32 +4,27 @@ module JekyllNotion
4
4
  class Generator < Jekyll::Generator
5
5
  attr_reader :current_page
6
6
 
7
- def initialize(plugin)
8
- super(plugin)
9
- end
10
-
11
7
  def generate(site)
12
8
  @site = site
13
9
 
14
- return unless notion_token?
15
- return unless config?
10
+ return unless notion_token? && config?
16
11
 
17
12
  read_notion_database
18
13
  end
19
14
 
20
15
  def read_notion_database
21
- @db = NotionDatabase.new(config: config)
22
- @db.pages do |page|
16
+ @db = NotionDatabase.new(:config => config)
17
+ @db.pages.each do |page|
23
18
  @current_page = page
24
19
  collection.docs << make_page
25
- Jekyll.logger.info('Jekyll Notion:', "New notion page at #{collection.docs.last.path}")
20
+ Jekyll.logger.info("Jekyll Notion:", "New notion page at #{collection.docs.last.path}")
26
21
  end
27
22
  end
28
23
 
29
24
  def make_page
30
25
  new_post = DocumentWithoutAFile.new(
31
- "#{Dir.pwd}/_#{config.dig('database', 'collection')}/#{make_filename}",
32
- { site: @site, collection: collection }
26
+ "#{Dir.pwd}/_#{collection_name}/#{make_filename}",
27
+ { :site => @site, :collection => collection }
33
28
  )
34
29
  new_post.content = "#{make_frontmatter}\n\n#{make_md}"
35
30
  new_post.read
@@ -37,27 +32,46 @@ module JekyllNotion
37
32
  end
38
33
 
39
34
  def make_md
40
- NotionToMd::Converter.new(page_id: current_page.id).convert
35
+ NotionToMd::Converter.new(:page_id => current_page.id).convert
41
36
  end
42
37
 
43
38
  def make_frontmatter
44
- <<-CONTENT
45
- #{config.dig('database', 'frontmatter').to_yaml}
46
- id: #{current_page.id}
47
- layout: #{current_page.layout}
48
- title: #{current_page.title}
49
- date: #{current_page.created_datetime.to_s}
50
- cover: #{current_page.cover}
51
- ---
39
+ data = Jekyll::Utils.deep_merge_hashes(config_frontmatter, notion_frontmatter)
40
+ page_frontmatter = data.to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
41
+ <<~CONTENT
42
+ ---
43
+ #{page_frontmatter}
44
+ ---
52
45
  CONTENT
53
46
  end
54
47
 
48
+ def notion_frontmatter
49
+ {
50
+ :id => current_page.id,
51
+ :title => current_page.title,
52
+ :date => current_page.created_datetime,
53
+ :cover => current_page.cover,
54
+ }
55
+ end
56
+
57
+ def config_frontmatter
58
+ config.dig("database", "frontmatter") || {}
59
+ end
60
+
55
61
  def make_filename
56
- "#{current_page.created_date.to_s}-#{current_page.title.downcase.parameterize}.md"
62
+ if collection_name == "posts"
63
+ "#{current_page.created_date}-#{current_page.title.downcase.parameterize}.md"
64
+ else
65
+ "#{current_page.title.downcase.parameterize}.md"
66
+ end
67
+ end
68
+
69
+ def collection_name
70
+ config.dig("database", "collection") || "posts"
57
71
  end
58
72
 
59
73
  def collection
60
- @site.send(config.dig('database', 'collection').to_sym)
74
+ @collection ||= @site.collections[collection_name]
61
75
  end
62
76
 
63
77
  def config
@@ -65,8 +79,8 @@ cover: #{current_page.cover}
65
79
  end
66
80
 
67
81
  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.')
82
+ if ENV["NOTION_TOKEN"].nil? || ENV["NOTION_TOKEN"].empty?
83
+ Jekyll.logger.warn("Jekyll Notion:", "NOTION_TOKEN not provided. Cannot read from Notion.")
70
84
  return false
71
85
  end
72
86
  true
@@ -74,7 +88,7 @@ cover: #{current_page.cover}
74
88
 
75
89
  def config?
76
90
  if config.empty?
77
- Jekyll.logger.error('Jekyll Notion:', 'No config provided.')
91
+ Jekyll.logger.warn("Jekyll Notion:", "No config provided.")
78
92
  return false
79
93
  end
80
94
  true
@@ -8,35 +8,42 @@ module JekyllNotion
8
8
  end
9
9
 
10
10
  def pages
11
+ return [] unless id?
12
+
11
13
  @pages ||= @notion.database_query(query)[:results].map do |page|
12
- NotionPage.new(page: page, layout: config['layout'])
14
+ NotionPage.new(:page => page, :layout => config["layout"])
13
15
  end
14
-
15
- return @pages unless block_given?
16
-
17
- @pages.each { |page| yield page }
18
16
  end
19
17
 
20
18
  private
21
19
 
22
20
  def config
23
- @config['database']
21
+ @config["database"]
24
22
  end
25
23
 
26
24
  def filter
27
- @config.dig('database', 'filter')
25
+ @config.dig("database", "filter")
28
26
  end
29
27
 
30
28
  def sort
31
- @config.dig('database', 'sort')
29
+ @config.dig("database", "sort")
32
30
  end
33
31
 
34
32
  def id
35
- @config.dig('database', 'id')
33
+ @config.dig("database", "id")
34
+ end
35
+
36
+ def id?
37
+ if id.nil? || id.empty?
38
+ Jekyll.logger.warn("Jekyll Notion:",
39
+ "database id is not provided. Cannot read from Notion.")
40
+ return false
41
+ end
42
+ true
36
43
  end
37
44
 
38
- def query
39
- { id: id, filter: filter, sort: sort }
45
+ def query
46
+ { :id => id, :filter => filter, :sort => sort }
40
47
  end
41
48
  end
42
49
  end
@@ -10,7 +10,7 @@ module JekyllNotion
10
10
  end
11
11
 
12
12
  def title
13
- page.dig(:properties, :Name, :title).inject('') do |acc, slug|
13
+ page.dig(:properties, :Name, :title).inject("") do |acc, slug|
14
14
  acc + slug[:plain_text]
15
15
  end
16
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllNotion
4
- VERSION = '0.0.0.beta'
4
+ VERSION = "0.0.1"
5
5
  end
data/lib/jekyll-notion.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jekyll'
4
- require 'notion'
5
- require 'notion_to_md'
6
- require 'logger'
7
- require 'active_support/inflector'
8
- require 'jekyll-notion/generator'
3
+ require "jekyll"
4
+ require "notion"
5
+ require "notion_to_md"
6
+ require "logger"
7
+ require "active_support/inflector"
8
+ require "jekyll-notion/generator"
9
9
 
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
17
- autoload :DocumentWithoutAFile, 'jekyll-notion/document_without_a_file'
18
- autoload :NotionDatabase, 'jekyll-notion/notion_database'
19
- autoload :NotionPage, 'jekyll-notion/notion_page'
17
+ autoload :DocumentWithoutAFile, "jekyll-notion/document_without_a_file"
18
+ autoload :NotionDatabase, "jekyll-notion/notion_database"
19
+ autoload :NotionPage, "jekyll-notion/notion_page"
20
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.beta
4
+ version: 0.0.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-15 00:00:00.000000000 Z
11
+ date: 2022-01-22 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
  - - "~>"
@@ -86,6 +86,34 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '2'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop-jekyll
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.12.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.12.0
89
117
  description:
90
118
  email:
91
119
  - emoriarty81@gmail.com
@@ -116,9 +144,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
144
  version: 2.5.0
117
145
  required_rubygems_version: !ruby/object:Gem::Requirement
118
146
  requirements:
119
- - - ">"
147
+ - - ">="
120
148
  - !ruby/object:Gem::Version
121
- version: 1.3.1
149
+ version: '0'
122
150
  requirements: []
123
151
  rubyforge_project:
124
152
  rubygems_version: 2.7.3