jekyll-notion 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -43
- data/lib/jekyll-notion/collection_generator.rb +67 -0
- data/lib/jekyll-notion/generator.rb +5 -72
- data/lib/jekyll-notion/notion_database.rb +1 -9
- data/lib/jekyll-notion/version.rb +1 -1
- data/lib/jekyll-notion.rb +1 -3
- metadata +3 -17
- data/lib/jekyll-notion/notion_page.rb +0 -123
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f85b870a3e8c0aa6ea64575b8ef8541f61183fa25ced6f41570384057a3a36dd
|
4
|
+
data.tar.gz: c66f6d831e8352f029fc1f81608f751aac1ed2b5959b6c2ee19f861eafcdb6f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26fda79bcfce19d75fda17e6f3e1a90080089c05132359b50f00ec3a4d54d844e6ef583bb558c961209d5818465c6ada865413a33f22fea15fdf943ecd213d8d
|
7
|
+
data.tar.gz: 430aa7ef405283f1568eacf4062a90a60fc0e086ae6c7d68cd96cd1eac5f8208d57d8cdebc02b0e98c653d0bff62b119c4ec6ceb4af31777c2a4a28121e0eb55
|
data/README.md
CHANGED
@@ -68,7 +68,6 @@ Each dabatase support the following options.
|
|
68
68
|
* `collection`: the collection each page belongs to (posts by default),
|
69
69
|
* `filter`: the database query filter,
|
70
70
|
* `sort`: the database query sort,
|
71
|
-
* `frontmatter`: additional front matter to append to each page in the collection.
|
72
71
|
|
73
72
|
```yml
|
74
73
|
notion:
|
@@ -77,12 +76,8 @@ notion:
|
|
77
76
|
collection: posts
|
78
77
|
filter: { "property": "Published", "checkbox": { "equals": true } }
|
79
78
|
sort: { "property": "Last ordered", "direction": "ascending" }
|
80
|
-
frontmatter:
|
81
|
-
layout: post
|
82
79
|
```
|
83
80
|
|
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.
|
85
|
-
|
86
81
|
### Watch
|
87
82
|
|
88
83
|
By default, databases are only requested during the first build. Subsequent builds use the results from the cache.
|
@@ -102,7 +97,7 @@ And that's all. Each page in the notion database will be included in the selecte
|
|
102
97
|
|
103
98
|
Below, default properties per notion page are set for each document front matter.
|
104
99
|
|
105
|
-
Notion properties
|
100
|
+
Notion page properties are `id`, `title`, `created_time`, `last_edited_time`, `icon`, `cover` and `archived`.
|
106
101
|
|
107
102
|
```
|
108
103
|
---
|
@@ -110,47 +105,14 @@ id: e42383cd-4975-4897-b967-ce453760499f
|
|
110
105
|
title: An amazing post
|
111
106
|
cover: https://img.bank.sh/an_image.jpg
|
112
107
|
date: 2022-01-23T12:31:00.000Z
|
113
|
-
icon:
|
114
|
-
|
115
|
-
```
|
116
|
-
|
117
|
-
Default properties prevail over custom properties declared in the front matter config.
|
118
|
-
|
119
|
-
### Custom properties
|
120
|
-
|
121
|
-
In addition to default properties, custom properties are also supported.
|
122
|
-
|
123
|
-
Custom properties are appended to the page frontmatter by default. Every property name are downcased and snake-cased.
|
124
|
-
For example, two properties named `Multiple Options` and `Tags` will be transformed to `multiple_options` and `tags`, respectively.
|
125
|
-
|
126
|
-
```
|
127
|
-
---
|
128
|
-
id: 2190450d-4cb3-4739-a5c8-340c4110fe21
|
129
|
-
title: A title
|
130
|
-
cover: https://img.bank.sh/an_image.jpg
|
131
|
-
date: 2022-01-23T12:31:00.000Z
|
132
|
-
icon: \U0001F4A5
|
133
|
-
tags: tag1, tag2, tag3
|
134
|
-
multiple_options: option1, option2
|
108
|
+
icon: 💥
|
109
|
+
archived: false
|
135
110
|
---
|
136
111
|
```
|
137
112
|
|
138
|
-
|
139
|
-
|
140
|
-
* `number`
|
141
|
-
* `select`
|
142
|
-
* `multi_select`
|
143
|
-
* `date`
|
144
|
-
* `people`
|
145
|
-
* `files`
|
146
|
-
* `checkbox`
|
147
|
-
* `url`
|
148
|
-
* `email`
|
149
|
-
* `phone_number`
|
150
|
-
|
151
|
-
`created_by`, `last_edited_by`, `rich_text` as advanced types like `formula`, `relation` and `rollup` are not supported.
|
113
|
+
In addition to default properties, custom properties are also appended to front matter.
|
152
114
|
|
153
|
-
|
115
|
+
Please, refer to the [notion_to_md](https://github.com/emoriarty/notion_to_md/) gem to learn more.
|
154
116
|
|
155
117
|
## Page filename
|
156
118
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module JekyllNotion
|
2
|
+
class CollectionGenerator
|
3
|
+
def initialize(db:, site:)
|
4
|
+
@db = db
|
5
|
+
@site = site
|
6
|
+
end
|
7
|
+
|
8
|
+
def generate
|
9
|
+
@db.pages.each do |page|
|
10
|
+
next if file_exists?(make_path(page))
|
11
|
+
|
12
|
+
collection.docs << make_doc(page)
|
13
|
+
log_new_page(page)
|
14
|
+
end
|
15
|
+
collection
|
16
|
+
end
|
17
|
+
|
18
|
+
def collection
|
19
|
+
@site.collections[@db.collection]
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Checks if a file already exists in the site source
|
25
|
+
def file_exists?(file_path)
|
26
|
+
File.exist? @site.in_source_dir(file_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def make_doc(page)
|
30
|
+
new_post = DocumentWithoutAFile.new(
|
31
|
+
make_path(page),
|
32
|
+
{ :site => @site, :collection => collection }
|
33
|
+
)
|
34
|
+
new_post.content = make_md(page)
|
35
|
+
new_post.read
|
36
|
+
new_post
|
37
|
+
end
|
38
|
+
|
39
|
+
def make_path(page)
|
40
|
+
"_#{@db.collection}/#{make_filename(page)}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def make_filename(page)
|
44
|
+
if @db.collection == "posts"
|
45
|
+
"#{page.created_time.to_date}-#{Jekyll::Utils.slugify(page.title,
|
46
|
+
:mode => "latin")}.md"
|
47
|
+
else
|
48
|
+
"#{page.title.downcase.parameterize}.md"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def make_md(page)
|
53
|
+
NotionToMd::Converter.new(:page_id => page.id).convert(:frontmatter => true)
|
54
|
+
end
|
55
|
+
|
56
|
+
def log_new_page(page)
|
57
|
+
Jekyll.logger.info("Jekyll Notion:", "Page => #{page.title}")
|
58
|
+
if @site.config.dig(
|
59
|
+
"collections", @db.collection, "output"
|
60
|
+
)
|
61
|
+
Jekyll.logger.info("",
|
62
|
+
"Path => #{collection.docs.last.path}")
|
63
|
+
end
|
64
|
+
Jekyll.logger.debug("", "Props => #{collection.docs.last.data.keys.inspect}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -20,16 +20,10 @@ module JekyllNotion
|
|
20
20
|
|
21
21
|
def read_notion_database
|
22
22
|
databases.each do |db_config|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
current_collection.docs << make_page
|
29
|
-
log_new_page
|
30
|
-
end
|
31
|
-
# Store current collection
|
32
|
-
collections[current_db.collection] = current_collection
|
23
|
+
db = NotionDatabase.new(:config => db_config)
|
24
|
+
new_collection = CollectionGenerator.new(:db => db, :site => @site).generate
|
25
|
+
# Caching current collection
|
26
|
+
collections[db.collection] = new_collection
|
33
27
|
end
|
34
28
|
end
|
35
29
|
|
@@ -41,62 +35,12 @@ module JekyllNotion
|
|
41
35
|
@collections ||= {}
|
42
36
|
end
|
43
37
|
|
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)
|
47
|
-
end
|
48
|
-
|
49
|
-
def make_page
|
50
|
-
new_post = DocumentWithoutAFile.new(
|
51
|
-
make_path,
|
52
|
-
{ :site => @site, :collection => current_collection }
|
53
|
-
)
|
54
|
-
new_post.content = "#{make_frontmatter}\n\n#{make_md}"
|
55
|
-
new_post.read
|
56
|
-
new_post
|
57
|
-
end
|
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
|
-
|
72
|
-
def make_md
|
73
|
-
NotionToMd::Converter.new(:page_id => current_page.id).convert
|
74
|
-
end
|
75
|
-
|
76
|
-
def make_frontmatter
|
77
|
-
data = Jekyll::Utils.deep_merge_hashes(current_db.frontmatter, page_frontmatter)
|
78
|
-
frontmatter = data.to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
|
79
|
-
<<~CONTENT
|
80
|
-
---
|
81
|
-
#{frontmatter}
|
82
|
-
---
|
83
|
-
CONTENT
|
84
|
-
end
|
85
|
-
|
86
|
-
def page_frontmatter
|
87
|
-
Jekyll::Utils.deep_merge_hashes(current_page.custom_props, current_page.default_props)
|
88
|
-
end
|
89
|
-
|
90
|
-
def current_collection
|
91
|
-
@site.collections[current_db.collection]
|
92
|
-
end
|
93
|
-
|
94
38
|
def config
|
95
39
|
@config ||= @site.config["notion"] || {}
|
96
40
|
end
|
97
41
|
|
98
42
|
def fetch_on_watch?
|
99
|
-
config["fetch_on_watch"]
|
43
|
+
config["fetch_on_watch"] == true
|
100
44
|
end
|
101
45
|
|
102
46
|
def notion_token?
|
@@ -114,16 +58,5 @@ module JekyllNotion
|
|
114
58
|
end
|
115
59
|
true
|
116
60
|
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
|
128
61
|
end
|
129
62
|
end
|
@@ -11,7 +11,7 @@ module JekyllNotion
|
|
11
11
|
return [] unless id?
|
12
12
|
|
13
13
|
@pages ||= @notion.database_query(query)[:results].map do |page|
|
14
|
-
|
14
|
+
NotionToMd::Page.new(:page => page)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -31,18 +31,10 @@ module JekyllNotion
|
|
31
31
|
config["id"]
|
32
32
|
end
|
33
33
|
|
34
|
-
def frontmatter
|
35
|
-
config["frontmatter"] || {}
|
36
|
-
end
|
37
|
-
|
38
34
|
def collection
|
39
35
|
config["collection"] || "posts"
|
40
36
|
end
|
41
37
|
|
42
|
-
def layout
|
43
|
-
config["layout"]
|
44
|
-
end
|
45
|
-
|
46
38
|
private
|
47
39
|
|
48
40
|
def id?
|
data/lib/jekyll-notion.rb
CHANGED
@@ -4,8 +4,6 @@ require "jekyll"
|
|
4
4
|
require "notion"
|
5
5
|
require "notion_to_md"
|
6
6
|
require "logger"
|
7
|
-
require "active_support/inflector"
|
8
|
-
require "active_support/core_ext/object/blank"
|
9
7
|
require "jekyll-notion/generator"
|
10
8
|
|
11
9
|
NotionToMd::Logger.level = Logger::ERROR
|
@@ -15,7 +13,7 @@ Notion.configure do |config|
|
|
15
13
|
end
|
16
14
|
|
17
15
|
module JekyllNotion
|
16
|
+
autoload :CollectionGenerator, "jekyll-notion/collection_generator"
|
18
17
|
autoload :DocumentWithoutAFile, "jekyll-notion/document_without_a_file"
|
19
18
|
autoload :NotionDatabase, "jekyll-notion/notion_database"
|
20
|
-
autoload :NotionPage, "jekyll-notion/notion_page"
|
21
19
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-notion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '6'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '6'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: jekyll
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,10 +110,10 @@ extra_rdoc_files:
|
|
124
110
|
files:
|
125
111
|
- README.md
|
126
112
|
- lib/jekyll-notion.rb
|
113
|
+
- lib/jekyll-notion/collection_generator.rb
|
127
114
|
- lib/jekyll-notion/document_without_a_file.rb
|
128
115
|
- lib/jekyll-notion/generator.rb
|
129
116
|
- lib/jekyll-notion/notion_database.rb
|
130
|
-
- lib/jekyll-notion/notion_page.rb
|
131
117
|
- lib/jekyll-notion/version.rb
|
132
118
|
homepage: https://github.com/emoriarty/jekyll-notion
|
133
119
|
licenses:
|
@@ -1,123 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module JekyllNotion
|
4
|
-
class NotionPage
|
5
|
-
attr_reader :page, :layout
|
6
|
-
|
7
|
-
def initialize(page:, layout:)
|
8
|
-
@page = page
|
9
|
-
@layout = layout
|
10
|
-
end
|
11
|
-
|
12
|
-
def title
|
13
|
-
page.dig(:properties, :Name, :title).inject("") do |acc, slug|
|
14
|
-
acc + slug[:plain_text]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def cover
|
19
|
-
page.dig(:cover, :external, :url)
|
20
|
-
end
|
21
|
-
|
22
|
-
def icon
|
23
|
-
page.dig(:icon, :emoji)
|
24
|
-
end
|
25
|
-
|
26
|
-
def id
|
27
|
-
page[:id]
|
28
|
-
end
|
29
|
-
|
30
|
-
def created_date
|
31
|
-
created_datetime.to_date
|
32
|
-
end
|
33
|
-
|
34
|
-
def created_datetime
|
35
|
-
DateTime.parse(page["created_time"])
|
36
|
-
end
|
37
|
-
|
38
|
-
def updated_date
|
39
|
-
updated_datetime.to_date
|
40
|
-
end
|
41
|
-
|
42
|
-
def updated_datetime
|
43
|
-
DateTime.parse(page["last_edited_time"])
|
44
|
-
end
|
45
|
-
|
46
|
-
def url
|
47
|
-
page[:url]
|
48
|
-
end
|
49
|
-
|
50
|
-
def custom_props
|
51
|
-
@custom_props ||= page.properties.each_with_object({}) do |prop, memo|
|
52
|
-
name = prop.first
|
53
|
-
value = prop.last # Notion::Messages::Message
|
54
|
-
type = value.type
|
55
|
-
|
56
|
-
next memo unless CustomProperty.respond_to?(type.to_sym)
|
57
|
-
|
58
|
-
memo[name.parameterize.underscore] = CustomProperty.send(type, value)
|
59
|
-
end.reject { |_k, v| v.presence.nil? }
|
60
|
-
end
|
61
|
-
|
62
|
-
def default_props
|
63
|
-
@default_props ||= {
|
64
|
-
"id" => id,
|
65
|
-
"title" => title,
|
66
|
-
"date" => created_datetime,
|
67
|
-
"cover" => cover,
|
68
|
-
"icon" => icon,
|
69
|
-
"updated_date" => updated_datetime,
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
class CustomProperty
|
74
|
-
class << self
|
75
|
-
def multi_select(prop)
|
76
|
-
multi_select = prop.multi_select.map(&:name).join(", ")
|
77
|
-
"[#{multi_select}]"
|
78
|
-
end
|
79
|
-
|
80
|
-
def select(prop)
|
81
|
-
prop["select"].name
|
82
|
-
end
|
83
|
-
|
84
|
-
def people(prop)
|
85
|
-
people = prop.people.map(&:name).join(", ")
|
86
|
-
"[#{people}]"
|
87
|
-
end
|
88
|
-
|
89
|
-
def files(prop)
|
90
|
-
files = prop.files.map { |f| "\"#{f.file.url}\"" }.join(", ")
|
91
|
-
"[#{files}]"
|
92
|
-
end
|
93
|
-
|
94
|
-
def phone_number(prop)
|
95
|
-
prop.phone_number
|
96
|
-
end
|
97
|
-
|
98
|
-
def number(prop)
|
99
|
-
prop.number
|
100
|
-
end
|
101
|
-
|
102
|
-
def email(prop)
|
103
|
-
prop.email
|
104
|
-
end
|
105
|
-
|
106
|
-
def checkbox(prop)
|
107
|
-
prop.checkbox.to_s
|
108
|
-
end
|
109
|
-
|
110
|
-
# date type properties not supported:
|
111
|
-
# - end
|
112
|
-
# - time_zone
|
113
|
-
def date(prop)
|
114
|
-
prop.date.start
|
115
|
-
end
|
116
|
-
|
117
|
-
def url(prop)
|
118
|
-
prop.url
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|