jekyll-notion 0.0.0.beta.1 → 0.0.2
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 +4 -4
- data/README.md +5 -2
- data/lib/jekyll-notion/document_without_a_file.rb +1 -1
- data/lib/jekyll-notion/generator.rb +31 -19
- data/lib/jekyll-notion/notion_database.rb +18 -11
- data/lib/jekyll-notion/notion_page.rb +3 -3
- data/lib/jekyll-notion/version.rb +1 -1
- data/lib/jekyll-notion.rb +10 -10
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47fd2ef3b63206ceb2e5ca1933daf4eb90bf283703371c4497c73f9beafd23f4
|
4
|
+
data.tar.gz: e44cf9e5a3b3b44a0e02b48334375df9e8afe779b7745bdbc146baff3e8de903
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 281ae8dca0453fb7a498a4457863b666ab7363bcca6e11d707843b35c9b81df91f5dfb6c7073a8af0c8f640560fbc9407c97e101495bef480dd8236c0f013f38
|
7
|
+
data.tar.gz: e915dc5d190bda6caae8b4942929fdc506ed4ae171e0a8cce126f0d2bee42d1ab5503205f970ee279f58a706c23e9684c0076a6c42e0d1eb856270e7effcad8c
|
data/README.md
CHANGED
@@ -40,13 +40,13 @@ notion:
|
|
40
40
|
id: b91d5...
|
41
41
|
collection: posts
|
42
42
|
filter: { "property": "Published", "checkbox": { "equals": true } }
|
43
|
-
sort: { "
|
43
|
+
sort: { "property": "Last ordered", "direction": "ascending" }
|
44
44
|
frontmatter:
|
45
45
|
layout: post
|
46
46
|
```
|
47
47
|
|
48
48
|
The other properties are:
|
49
|
-
* `collection`:
|
49
|
+
* `collection`: the collection each page belongs to (posts by default),
|
50
50
|
* `filter`: the database query filter,
|
51
51
|
* `sort`: the database query sort,
|
52
52
|
* `frontmatter`: additional frontmatter to append to each page in the collection.
|
@@ -65,9 +65,12 @@ id: id
|
|
65
65
|
title: properties > Name > title > plain_text
|
66
66
|
cover: cover > external > url
|
67
67
|
date: created_time
|
68
|
+
icon: icon > emoji
|
68
69
|
---
|
69
70
|
```
|
70
71
|
|
72
|
+
Any property provided in the frontmatter config that matches a default property will be overwritten by the default value.
|
73
|
+
|
71
74
|
## Page filename
|
72
75
|
|
73
76
|
There are two kinds of collections: posts and others.
|
@@ -6,7 +6,7 @@ module JekyllNotion
|
|
6
6
|
if content =~ YAML_FRONT_MATTER_REGEXP
|
7
7
|
self.content = Regexp.last_match.post_match
|
8
8
|
data_file = SafeYAML.load(Regexp.last_match(1))
|
9
|
-
merge_data!(data_file, source
|
9
|
+
merge_data!(data_file, :source => "YAML front matter") if data_file
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -7,25 +7,24 @@ module JekyllNotion
|
|
7
7
|
def generate(site)
|
8
8
|
@site = site
|
9
9
|
|
10
|
-
return unless notion_token?
|
11
|
-
return unless config?
|
10
|
+
return unless notion_token? && config?
|
12
11
|
|
13
12
|
read_notion_database
|
14
13
|
end
|
15
14
|
|
16
15
|
def read_notion_database
|
17
|
-
@db = NotionDatabase.new(config
|
18
|
-
@db.pages do |page|
|
16
|
+
@db = NotionDatabase.new(:config => config)
|
17
|
+
@db.pages.each do |page|
|
19
18
|
@current_page = page
|
20
19
|
collection.docs << make_page
|
21
|
-
Jekyll.logger.info(
|
20
|
+
Jekyll.logger.info("Jekyll Notion:", "New notion page at #{collection.docs.last.path}")
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
24
|
def make_page
|
26
25
|
new_post = DocumentWithoutAFile.new(
|
27
26
|
"#{Dir.pwd}/_#{collection_name}/#{make_filename}",
|
28
|
-
{ site
|
27
|
+
{ :site => @site, :collection => collection }
|
29
28
|
)
|
30
29
|
new_post.content = "#{make_frontmatter}\n\n#{make_md}"
|
31
30
|
new_post.read
|
@@ -33,22 +32,35 @@ module JekyllNotion
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def make_md
|
36
|
-
NotionToMd::Converter.new(page_id
|
35
|
+
NotionToMd::Converter.new(:page_id => current_page.id).convert
|
37
36
|
end
|
38
37
|
|
39
38
|
def make_frontmatter
|
39
|
+
data = Jekyll::Utils.deep_merge_hashes(config_frontmatter, notion_frontmatter)
|
40
|
+
page_frontmatter = data.to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
|
40
41
|
<<~CONTENT
|
41
|
-
|
42
|
-
|
43
|
-
title: #{current_page.title}
|
44
|
-
date: #{current_page.created_datetime}
|
45
|
-
cover: #{current_page.cover}
|
42
|
+
---
|
43
|
+
#{page_frontmatter}
|
46
44
|
---
|
47
45
|
CONTENT
|
48
46
|
end
|
49
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
|
+
:icon => current_page.icon,
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def config_frontmatter
|
59
|
+
config.dig("database", "frontmatter") || {}
|
60
|
+
end
|
61
|
+
|
50
62
|
def make_filename
|
51
|
-
if collection_name ==
|
63
|
+
if collection_name == "posts"
|
52
64
|
"#{current_page.created_date}-#{current_page.title.downcase.parameterize}.md"
|
53
65
|
else
|
54
66
|
"#{current_page.title.downcase.parameterize}.md"
|
@@ -56,20 +68,20 @@ module JekyllNotion
|
|
56
68
|
end
|
57
69
|
|
58
70
|
def collection_name
|
59
|
-
config.dig(
|
71
|
+
config.dig("database", "collection") || "posts"
|
60
72
|
end
|
61
73
|
|
62
74
|
def collection
|
63
|
-
@site.
|
75
|
+
@collection ||= @site.collections[collection_name]
|
64
76
|
end
|
65
77
|
|
66
78
|
def config
|
67
|
-
@config ||= @site.config[
|
79
|
+
@config ||= @site.config["notion"] || {}
|
68
80
|
end
|
69
81
|
|
70
82
|
def notion_token?
|
71
|
-
if ENV[
|
72
|
-
Jekyll.logger.
|
83
|
+
if ENV["NOTION_TOKEN"].nil? || ENV["NOTION_TOKEN"].empty?
|
84
|
+
Jekyll.logger.warn("Jekyll Notion:", "NOTION_TOKEN not provided. Cannot read from Notion.")
|
73
85
|
return false
|
74
86
|
end
|
75
87
|
true
|
@@ -77,7 +89,7 @@ module JekyllNotion
|
|
77
89
|
|
78
90
|
def config?
|
79
91
|
if config.empty?
|
80
|
-
Jekyll.logger.
|
92
|
+
Jekyll.logger.warn("Jekyll Notion:", "No config provided.")
|
81
93
|
return false
|
82
94
|
end
|
83
95
|
true
|
@@ -7,36 +7,43 @@ module JekyllNotion
|
|
7
7
|
@config = config
|
8
8
|
end
|
9
9
|
|
10
|
-
def pages
|
10
|
+
def pages
|
11
|
+
return [] unless id?
|
12
|
+
|
11
13
|
@pages ||= @notion.database_query(query)[:results].map do |page|
|
12
|
-
NotionPage.new(page
|
14
|
+
NotionPage.new(:page => page, :layout => config["layout"])
|
13
15
|
end
|
14
|
-
|
15
|
-
return @pages unless block_given?
|
16
|
-
|
17
|
-
@pages.each(&block)
|
18
16
|
end
|
19
17
|
|
20
18
|
private
|
21
19
|
|
22
20
|
def config
|
23
|
-
@config[
|
21
|
+
@config["database"]
|
24
22
|
end
|
25
23
|
|
26
24
|
def filter
|
27
|
-
@config.dig(
|
25
|
+
@config.dig("database", "filter")
|
28
26
|
end
|
29
27
|
|
30
28
|
def sort
|
31
|
-
@config.dig(
|
29
|
+
@config.dig("database", "sort")
|
32
30
|
end
|
33
31
|
|
34
32
|
def id
|
35
|
-
@config.dig(
|
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
45
|
def query
|
39
|
-
{ id
|
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(
|
13
|
+
page.dig(:properties, :Name, :title).inject("") do |acc, slug|
|
14
14
|
acc + slug[:plain_text]
|
15
15
|
end
|
16
16
|
end
|
@@ -32,7 +32,7 @@ module JekyllNotion
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def created_datetime
|
35
|
-
DateTime.parse(page[
|
35
|
+
DateTime.parse(page["created_time"])
|
36
36
|
end
|
37
37
|
|
38
38
|
def updated_date
|
@@ -40,7 +40,7 @@ module JekyllNotion
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def updated_datetime
|
43
|
-
DateTime.parse(page[
|
43
|
+
DateTime.parse(page["last_edited_time"])
|
44
44
|
end
|
45
45
|
|
46
46
|
def url
|
data/lib/jekyll-notion.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
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[
|
13
|
+
config.token = ENV["NOTION_TOKEN"]
|
14
14
|
end
|
15
15
|
|
16
16
|
module JekyllNotion
|
17
|
-
autoload :DocumentWithoutAFile,
|
18
|
-
autoload :NotionDatabase,
|
19
|
-
autoload :NotionPage,
|
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.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2022-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -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:
|
149
|
+
version: '0'
|
122
150
|
requirements: []
|
123
151
|
rubyforge_project:
|
124
152
|
rubygems_version: 2.7.3
|