jekyll-notion 0.1.6 → 0.2.0
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 +54 -19
- data/lib/jekyll-notion/generator.rb +37 -25
- data/lib/jekyll-notion/notion_database.rb +19 -7
- data/lib/jekyll-notion/notion_page.rb +6 -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: '051289989a623c954ef76ca1299a79a4499649dea4b94dfe49ac75f9a67d4bbc'
|
4
|
+
data.tar.gz: 5de9f6860672c7eb8cdc355b5c5af3257fdc476cba3a5d20b4a420f330189f7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 211bcfcf58c3d5e0d1e9d684a7a8483e31882e9b2d81df5e8770a24a62ed7c82334d9481a9138dc6c3285fa3e0585facca6f2f68bcbb1b6d769595c5d9051774
|
7
|
+
data.tar.gz: 3d5d03c0223c1e891f5ba1102defb082638b67bd9e07cbfc56e2beeadc93e650ed8b2b758543a0a8afe6f8c36a2ad6ca33dd300955fbbc009b7260e509a7e21d
|
data/README.md
CHANGED
@@ -32,13 +32,44 @@ 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
|
+
notion:
|
49
|
+
databases:
|
50
|
+
- id: b0e688e1-99af-4295-ae80-b67eb52f2e2f
|
51
|
+
- id: 2190450d-4cb3-4739-a5c8-340c4110fe21
|
52
|
+
collection: recipes
|
53
|
+
- id: e42383cd-4975-4897-b967-ce453760499f
|
54
|
+
collection: films
|
55
|
+
```
|
56
|
+
|
57
|
+
When no collection is defined, the `posts` collection is used by default.
|
58
|
+
|
59
|
+
### Database options
|
60
|
+
|
61
|
+
Each dabatase support the following options.
|
62
|
+
|
63
|
+
* `id`: the notion database unique identifier,
|
64
|
+
* `collection`: the collection each page belongs to (posts by default),
|
65
|
+
* `filter`: the database query filter,
|
66
|
+
* `sort`: the database query sort,
|
67
|
+
* `frontmatter`: additional front matter to append to each page in the collection.
|
68
|
+
|
69
|
+
```yml
|
70
|
+
notion:
|
71
|
+
database:
|
72
|
+
id: e42383cd-4975-4897-b967-ce453760499f
|
42
73
|
collection: posts
|
43
74
|
filter: { "property": "Published", "checkbox": { "equals": true } }
|
44
75
|
sort: { "property": "Last ordered", "direction": "ascending" }
|
@@ -46,47 +77,51 @@ notion:
|
|
46
77
|
layout: post
|
47
78
|
```
|
48
79
|
|
49
|
-
|
80
|
+
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
81
|
|
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.
|
82
|
+
### Watch
|
57
83
|
|
58
|
-
|
84
|
+
By default, databases are only requested during the first build. Subsequent builds use the results from the cache.
|
85
|
+
|
86
|
+
Set `fetch_on_watch` to true to allow request on each rebuild.
|
87
|
+
|
88
|
+
```yml
|
89
|
+
notion:
|
90
|
+
fetch_on_watch: true
|
91
|
+
database:
|
92
|
+
id: e42383cd-4975-4897-b967-ce453760499f
|
93
|
+
```
|
59
94
|
|
60
95
|
And that's all. Each page in the notion database will be included in the selected collection.
|
61
96
|
|
62
97
|
## Notion properties
|
63
98
|
|
64
|
-
Below,
|
99
|
+
Below, default properties per notion page are set for each document front matter.
|
65
100
|
|
66
|
-
|
101
|
+
Notion properties include page `id`, `title`, `created_time`, `last_edited_time`, `icon` and `cover`.
|
67
102
|
|
68
103
|
```
|
69
104
|
---
|
70
|
-
id:
|
71
|
-
title:
|
105
|
+
id: e42383cd-4975-4897-b967-ce453760499f
|
106
|
+
title: An amazing post
|
72
107
|
cover: https://img.bank.sh/an_image.jpg
|
73
108
|
date: 2022-01-23T12:31:00.000Z
|
74
109
|
icon: \U0001F4A5
|
75
110
|
---
|
76
111
|
```
|
77
112
|
|
78
|
-
|
113
|
+
Default properties prevail over custom properties declared in the front matter config.
|
79
114
|
|
80
115
|
### Custom properties
|
81
116
|
|
82
117
|
In addition to default properties, custom properties are also supported.
|
83
118
|
|
84
|
-
Custom properties are appended to page frontmatter by default. Every property name
|
119
|
+
Custom properties are appended to the page frontmatter by default. Every property name are downcased and snake-cased.
|
85
120
|
For example, two properties named `Multiple Options` and `Tags` will be transformed to `multiple_options` and `tags`, respectively.
|
86
121
|
|
87
122
|
```
|
88
123
|
---
|
89
|
-
id:
|
124
|
+
id: 2190450d-4cb3-4739-a5c8-340c4110fe21
|
90
125
|
title: A title
|
91
126
|
cover: https://img.bank.sh/an_image.jpg
|
92
127
|
date: 2022-01-23T12:31:00.000Z
|
@@ -96,7 +131,7 @@ multiple_options: option1, option2
|
|
96
131
|
---
|
97
132
|
```
|
98
133
|
|
99
|
-
The supported
|
134
|
+
The supported property types are:
|
100
135
|
|
101
136
|
* `number`
|
102
137
|
* `select`
|
@@ -2,38 +2,47 @@
|
|
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
|
+
current_collection.docs << make_page
|
27
|
+
log_new_page
|
28
|
+
end
|
29
|
+
# Store current collection
|
30
|
+
collections[current_db.collection] = current_collection
|
25
31
|
end
|
26
|
-
@docs = collection.docs
|
27
32
|
end
|
28
33
|
|
29
|
-
def
|
30
|
-
|
34
|
+
def databases
|
35
|
+
config["databases"] || [config["database"]]
|
36
|
+
end
|
37
|
+
|
38
|
+
def collections
|
39
|
+
@collections ||= {}
|
31
40
|
end
|
32
41
|
|
33
42
|
def make_page
|
34
43
|
new_post = DocumentWithoutAFile.new(
|
35
|
-
"#{Dir.pwd}/_#{
|
36
|
-
{ :site => @site, :collection =>
|
44
|
+
"#{Dir.pwd}/_#{current_db.collection}/#{make_filename}",
|
45
|
+
{ :site => @site, :collection => current_collection }
|
37
46
|
)
|
38
47
|
new_post.content = "#{make_frontmatter}\n\n#{make_md}"
|
39
48
|
new_post.read
|
@@ -45,7 +54,7 @@ module JekyllNotion
|
|
45
54
|
end
|
46
55
|
|
47
56
|
def make_frontmatter
|
48
|
-
data = Jekyll::Utils.deep_merge_hashes(
|
57
|
+
data = Jekyll::Utils.deep_merge_hashes(current_db.frontmatter, page_frontmatter)
|
49
58
|
frontmatter = data.to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
|
50
59
|
<<~CONTENT
|
51
60
|
---
|
@@ -58,12 +67,8 @@ module JekyllNotion
|
|
58
67
|
Jekyll::Utils.deep_merge_hashes(current_page.custom_props, current_page.default_props)
|
59
68
|
end
|
60
69
|
|
61
|
-
def config_frontmatter
|
62
|
-
config.dig("database", "frontmatter") || {}
|
63
|
-
end
|
64
|
-
|
65
70
|
def make_filename
|
66
|
-
if
|
71
|
+
if current_db.collection == "posts"
|
67
72
|
"#{current_page.created_date}-#{Jekyll::Utils.slugify(current_page.title,
|
68
73
|
:mode => "latin")}.md"
|
69
74
|
else
|
@@ -71,12 +76,8 @@ module JekyllNotion
|
|
71
76
|
end
|
72
77
|
end
|
73
78
|
|
74
|
-
def
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
def collection
|
79
|
-
@site.collections[collection_name]
|
79
|
+
def current_collection
|
80
|
+
@site.collections[current_db.collection]
|
80
81
|
end
|
81
82
|
|
82
83
|
def config
|
@@ -102,5 +103,16 @@ module JekyllNotion
|
|
102
103
|
end
|
103
104
|
true
|
104
105
|
end
|
106
|
+
|
107
|
+
def log_new_page
|
108
|
+
Jekyll.logger.info("Jekyll Notion:", "Page => #{current_page.title}")
|
109
|
+
if @site.config.dig(
|
110
|
+
"collections", current_db.collection, "output"
|
111
|
+
)
|
112
|
+
Jekyll.logger.info("",
|
113
|
+
"Path => #{current_collection.docs.last.path}")
|
114
|
+
end
|
115
|
+
Jekyll.logger.debug("", "Props => #{page_frontmatter.keys.inspect}")
|
116
|
+
end
|
105
117
|
end
|
106
118
|
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:",
|
@@ -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
|
|
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.
|
4
|
+
version: 0.2.0
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|