jekyll-notion 0.1.4 → 0.2.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 +4 -4
- data/README.md +58 -19
- data/lib/jekyll-notion/generator.rb +56 -33
- data/lib/jekyll-notion/notion_database.rb +20 -8
- data/lib/jekyll-notion/notion_page.rb +10 -6
- data/lib/jekyll-notion/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c220aa475033e8ddb50ef928b9104c3b8d5da793bbe777062783eb5fbd1491e
|
4
|
+
data.tar.gz: c99b1e1b3cebbc00420d8b857e545fa9ae6ac83aad4da110fabf780a0c42a816
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74c1c36de04d025b121fce5634bfdd739796880208114e1dcdac9f49ec2302b16188f54abb1f8bafc07b3911627a2753e6e6c8d750559384ea9bfb94f1c25cb0
|
7
|
+
data.tar.gz: a42ae853c9371cd60ffd6e4cd00cc47e02c9eee64d44579ec1ea88f1e4c0e64208a536cec7bc2fea0c6ab1b6ea00b6dcdde23d5aa1110190b48e7e3b6bceabc3
|
data/README.md
CHANGED
@@ -32,13 +32,48 @@ Export the notion secret token in an environment variable named `NOTION_TOKEN`.
|
|
32
32
|
$ export NOTION_TOKEN=<secret_...>
|
33
33
|
```
|
34
34
|
|
35
|
-
Once your notion database has been shared, specify the `id` in your `_config.yml` as follows.
|
35
|
+
Once your notion database has been shared, specify the database `id` in your `_config.yml` as follows.
|
36
36
|
|
37
37
|
```yml
|
38
38
|
notion:
|
39
|
-
fetch_on_watch: false
|
40
39
|
database:
|
41
|
-
id:
|
40
|
+
id: e42383cd-4975-4897-b967-ce453760499f
|
41
|
+
```
|
42
|
+
|
43
|
+
### Mutiple dabatases
|
44
|
+
|
45
|
+
You can also define multiple databases as follows.
|
46
|
+
|
47
|
+
```yml
|
48
|
+
collections:
|
49
|
+
- recipes
|
50
|
+
- films
|
51
|
+
|
52
|
+
notion:
|
53
|
+
databases:
|
54
|
+
- id: b0e688e1-99af-4295-ae80-b67eb52f2e2f
|
55
|
+
- id: 2190450d-4cb3-4739-a5c8-340c4110fe21
|
56
|
+
collection: recipes
|
57
|
+
- id: e42383cd-4975-4897-b967-ce453760499f
|
58
|
+
collection: films
|
59
|
+
```
|
60
|
+
|
61
|
+
When no collection is defined, the `posts` collection is used by default.
|
62
|
+
|
63
|
+
### Database options
|
64
|
+
|
65
|
+
Each dabatase support the following options.
|
66
|
+
|
67
|
+
* `id`: the notion database unique identifier,
|
68
|
+
* `collection`: the collection each page belongs to (posts by default),
|
69
|
+
* `filter`: the database query filter,
|
70
|
+
* `sort`: the database query sort,
|
71
|
+
* `frontmatter`: additional front matter to append to each page in the collection.
|
72
|
+
|
73
|
+
```yml
|
74
|
+
notion:
|
75
|
+
database:
|
76
|
+
id: e42383cd-4975-4897-b967-ce453760499f
|
42
77
|
collection: posts
|
43
78
|
filter: { "property": "Published", "checkbox": { "equals": true } }
|
44
79
|
sort: { "property": "Last ordered", "direction": "ascending" }
|
@@ -46,47 +81,51 @@ notion:
|
|
46
81
|
layout: post
|
47
82
|
```
|
48
83
|
|
49
|
-
|
84
|
+
Note that you can also use [front matter defaults](https://jekyllrb.com/docs/configuration/front-matter-defaults/) to declare common key value pairs per collection.
|
50
85
|
|
51
|
-
|
52
|
-
* `id`: the notion database unique identifier,
|
53
|
-
* `collection`: the collection each page belongs to (posts by default),
|
54
|
-
* `filter`: the database query filter,
|
55
|
-
* `sort`: the database query sort,
|
56
|
-
* `frontmatter`: additional frontmatter to append to each page in the collection.
|
86
|
+
### Watch
|
57
87
|
|
58
|
-
|
88
|
+
By default, databases are only requested during the first build. Subsequent builds use the results from the cache.
|
89
|
+
|
90
|
+
Set `fetch_on_watch` to true to allow request on each rebuild.
|
91
|
+
|
92
|
+
```yml
|
93
|
+
notion:
|
94
|
+
fetch_on_watch: true
|
95
|
+
database:
|
96
|
+
id: e42383cd-4975-4897-b967-ce453760499f
|
97
|
+
```
|
59
98
|
|
60
99
|
And that's all. Each page in the notion database will be included in the selected collection.
|
61
100
|
|
62
101
|
## Notion properties
|
63
102
|
|
64
|
-
Below,
|
103
|
+
Below, default properties per notion page are set for each document front matter.
|
65
104
|
|
66
|
-
|
105
|
+
Notion properties include page `id`, `title`, `created_time`, `last_edited_time`, `icon` and `cover`.
|
67
106
|
|
68
107
|
```
|
69
108
|
---
|
70
|
-
id:
|
71
|
-
title:
|
109
|
+
id: e42383cd-4975-4897-b967-ce453760499f
|
110
|
+
title: An amazing post
|
72
111
|
cover: https://img.bank.sh/an_image.jpg
|
73
112
|
date: 2022-01-23T12:31:00.000Z
|
74
113
|
icon: \U0001F4A5
|
75
114
|
---
|
76
115
|
```
|
77
116
|
|
78
|
-
|
117
|
+
Default properties prevail over custom properties declared in the front matter config.
|
79
118
|
|
80
119
|
### Custom properties
|
81
120
|
|
82
121
|
In addition to default properties, custom properties are also supported.
|
83
122
|
|
84
|
-
Custom properties are appended to page frontmatter by default. Every property name
|
123
|
+
Custom properties are appended to the page frontmatter by default. Every property name are downcased and snake-cased.
|
85
124
|
For example, two properties named `Multiple Options` and `Tags` will be transformed to `multiple_options` and `tags`, respectively.
|
86
125
|
|
87
126
|
```
|
88
127
|
---
|
89
|
-
id:
|
128
|
+
id: 2190450d-4cb3-4739-a5c8-340c4110fe21
|
90
129
|
title: A title
|
91
130
|
cover: https://img.bank.sh/an_image.jpg
|
92
131
|
date: 2022-01-23T12:31:00.000Z
|
@@ -96,7 +135,7 @@ multiple_options: option1, option2
|
|
96
135
|
---
|
97
136
|
```
|
98
137
|
|
99
|
-
The supported
|
138
|
+
The supported property types are:
|
100
139
|
|
101
140
|
* `number`
|
102
141
|
* `select`
|
@@ -2,50 +2,79 @@
|
|
2
2
|
|
3
3
|
module JekyllNotion
|
4
4
|
class Generator < Jekyll::Generator
|
5
|
-
attr_reader :current_page
|
5
|
+
attr_reader :current_page, :current_db
|
6
6
|
|
7
7
|
def generate(site)
|
8
8
|
@site = site
|
9
9
|
|
10
10
|
return unless notion_token? && config?
|
11
11
|
|
12
|
-
if fetch_on_watch? ||
|
12
|
+
if fetch_on_watch? || collections.empty?
|
13
13
|
read_notion_database
|
14
14
|
else
|
15
|
-
|
15
|
+
collections.each_pair { |key, val| @site.collections[key] = val }
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
protected
|
20
|
+
|
19
21
|
def read_notion_database
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
|
24
|
-
|
22
|
+
databases.each do |db_config|
|
23
|
+
@current_db = NotionDatabase.new(:config => db_config)
|
24
|
+
@current_db.pages.each do |page|
|
25
|
+
@current_page = page
|
26
|
+
next if file_exists?(make_path)
|
27
|
+
|
28
|
+
current_collection.docs << make_page
|
29
|
+
log_new_page
|
30
|
+
end
|
31
|
+
# Store current collection
|
32
|
+
collections[current_db.collection] = current_collection
|
25
33
|
end
|
26
|
-
@docs = collection.docs
|
27
34
|
end
|
28
35
|
|
29
|
-
def
|
30
|
-
|
36
|
+
def databases
|
37
|
+
config["databases"] || [config["database"]]
|
38
|
+
end
|
39
|
+
|
40
|
+
def collections
|
41
|
+
@collections ||= {}
|
42
|
+
end
|
43
|
+
|
44
|
+
# Checks if a file already exists in the site source
|
45
|
+
def file_exists?(file_path)
|
46
|
+
File.exist? @site.in_source_dir(file_path)
|
31
47
|
end
|
32
48
|
|
33
49
|
def make_page
|
34
50
|
new_post = DocumentWithoutAFile.new(
|
35
|
-
|
36
|
-
{ :site => @site, :collection =>
|
51
|
+
make_path,
|
52
|
+
{ :site => @site, :collection => current_collection }
|
37
53
|
)
|
38
54
|
new_post.content = "#{make_frontmatter}\n\n#{make_md}"
|
39
55
|
new_post.read
|
40
56
|
new_post
|
41
57
|
end
|
42
58
|
|
59
|
+
def make_path
|
60
|
+
"_#{current_db.collection}/#{make_filename}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def make_filename
|
64
|
+
if current_db.collection == "posts"
|
65
|
+
"#{current_page.created_date}-#{Jekyll::Utils.slugify(current_page.title,
|
66
|
+
:mode => "latin")}.md"
|
67
|
+
else
|
68
|
+
"#{current_page.title.downcase.parameterize}.md"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
43
72
|
def make_md
|
44
73
|
NotionToMd::Converter.new(:page_id => current_page.id).convert
|
45
74
|
end
|
46
75
|
|
47
76
|
def make_frontmatter
|
48
|
-
data = Jekyll::Utils.deep_merge_hashes(
|
77
|
+
data = Jekyll::Utils.deep_merge_hashes(current_db.frontmatter, page_frontmatter)
|
49
78
|
frontmatter = data.to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
|
50
79
|
<<~CONTENT
|
51
80
|
---
|
@@ -58,25 +87,8 @@ module JekyllNotion
|
|
58
87
|
Jekyll::Utils.deep_merge_hashes(current_page.custom_props, current_page.default_props)
|
59
88
|
end
|
60
89
|
|
61
|
-
def
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
def make_filename
|
66
|
-
if collection_name == "posts"
|
67
|
-
"#{current_page.created_date}-#{Jekyll::Utils.slugify(current_page.title,
|
68
|
-
:mode => "latin")}.md"
|
69
|
-
else
|
70
|
-
"#{current_page.title.downcase.parameterize}.md"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def collection_name
|
75
|
-
config.dig("database", "collection") || "posts"
|
76
|
-
end
|
77
|
-
|
78
|
-
def collection
|
79
|
-
@site.collections[collection_name]
|
90
|
+
def current_collection
|
91
|
+
@site.collections[current_db.collection]
|
80
92
|
end
|
81
93
|
|
82
94
|
def config
|
@@ -102,5 +114,16 @@ module JekyllNotion
|
|
102
114
|
end
|
103
115
|
true
|
104
116
|
end
|
117
|
+
|
118
|
+
def log_new_page
|
119
|
+
Jekyll.logger.info("Jekyll Notion:", "Page => #{current_page.title}")
|
120
|
+
if @site.config.dig(
|
121
|
+
"collections", current_db.collection, "output"
|
122
|
+
)
|
123
|
+
Jekyll.logger.info("",
|
124
|
+
"Path => #{current_collection.docs.last.path}")
|
125
|
+
end
|
126
|
+
Jekyll.logger.debug("", "Props => #{page_frontmatter.keys.inspect}")
|
127
|
+
end
|
105
128
|
end
|
106
129
|
end
|
@@ -11,28 +11,40 @@ module JekyllNotion
|
|
11
11
|
return [] unless id?
|
12
12
|
|
13
13
|
@pages ||= @notion.database_query(query)[:results].map do |page|
|
14
|
-
NotionPage.new(:page => page, :layout =>
|
14
|
+
NotionPage.new(:page => page, :layout => layout)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
private
|
19
|
-
|
20
18
|
def config
|
21
|
-
@config
|
19
|
+
@config || {}
|
22
20
|
end
|
23
21
|
|
24
22
|
def filter
|
25
|
-
|
23
|
+
config["filter"]
|
26
24
|
end
|
27
25
|
|
28
26
|
def sort
|
29
|
-
|
27
|
+
config["sort"]
|
30
28
|
end
|
31
29
|
|
32
30
|
def id
|
33
|
-
|
31
|
+
config["id"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def frontmatter
|
35
|
+
config["frontmatter"] || {}
|
36
|
+
end
|
37
|
+
|
38
|
+
def collection
|
39
|
+
config["collection"] || "posts"
|
40
|
+
end
|
41
|
+
|
42
|
+
def layout
|
43
|
+
config["layout"]
|
34
44
|
end
|
35
45
|
|
46
|
+
private
|
47
|
+
|
36
48
|
def id?
|
37
49
|
if id.nil? || id.empty?
|
38
50
|
Jekyll.logger.warn("Jekyll Notion:",
|
@@ -43,7 +55,7 @@ module JekyllNotion
|
|
43
55
|
end
|
44
56
|
|
45
57
|
def query
|
46
|
-
{ :id => id, :filter => filter, :sort => sort }
|
58
|
+
{ :id => id, :filter => filter, :sort => sort }.compact
|
47
59
|
end
|
48
60
|
end
|
49
61
|
end
|
@@ -61,12 +61,12 @@ module JekyllNotion
|
|
61
61
|
|
62
62
|
def default_props
|
63
63
|
@default_props ||= {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
"id" => id,
|
65
|
+
"title" => title,
|
66
|
+
"date" => created_datetime,
|
67
|
+
"cover" => cover,
|
68
|
+
"icon" => icon,
|
69
|
+
"updated_date" => updated_datetime,
|
70
70
|
}
|
71
71
|
end
|
72
72
|
|
@@ -113,6 +113,10 @@ module JekyllNotion
|
|
113
113
|
def date(prop)
|
114
114
|
prop.date.start
|
115
115
|
end
|
116
|
+
|
117
|
+
def url(prop)
|
118
|
+
prop.url
|
119
|
+
end
|
116
120
|
end
|
117
121
|
end
|
118
122
|
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.1
|
4
|
+
version: 0.2.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-02-
|
11
|
+
date: 2022-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|