jekyll-notion 0.0.0.pre → 0.1.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 +44 -5
- data/lib/jekyll-notion/generator.rb +8 -6
- data/lib/jekyll-notion/notion_page.rb +66 -0
- data/lib/jekyll-notion/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb54ec7b63c705b241d71a4f631e06ceeb423b3cb880154ff23c4d28b4dafb9c
|
4
|
+
data.tar.gz: 4de1c60b106d86fe042b1a05690c5095165ac173535a103493c85cac24961abf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2182b355e1732039b09838268c2decedf0498bf3ecb34db794267ad6c10455442f70c4de3219b07a777e2d0611628786b42a464e6fc914657694c5783f54410
|
7
|
+
data.tar.gz: ddbdb1b6caa7b1b19ecec525e9bc1e84df232db9ce1981dfa4daf87d4edc2302cd6bff92554c8f32f9a84567ce9b37d07be7fa4a213f3b6b31458fcd52a254ea
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ 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
|
```
|
@@ -61,13 +61,52 @@ Below, page notion default properties are set in each page frontmatter.
|
|
61
61
|
|
62
62
|
```
|
63
63
|
---
|
64
|
-
id:
|
65
|
-
title:
|
66
|
-
cover:
|
67
|
-
date:
|
64
|
+
id: b2998...
|
65
|
+
title: A title
|
66
|
+
cover: https://img.bank.sh/an_image.jpg
|
67
|
+
date: 2022-01-23T12:31:00.000Z
|
68
|
+
icon: \U0001F4A5
|
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
|
+
|
74
|
+
### Custom properties
|
75
|
+
|
76
|
+
In addition to default properties, custom properties are also supported.
|
77
|
+
|
78
|
+
Custom properties are appended to page frontmatter by default. Every property name is snake-cased.
|
79
|
+
For example, two properties named `Multiple Options` and `Tags` will be transformed to `multiple_options` and `tags`, respectively.
|
80
|
+
|
81
|
+
```
|
82
|
+
---
|
83
|
+
id: b2998...
|
84
|
+
title: A title
|
85
|
+
cover: https://img.bank.sh/an_image.jpg
|
86
|
+
date: 2022-01-23T12:31:00.000Z
|
87
|
+
icon: \U0001F4A5
|
88
|
+
tags: tag1, tag2, tag3
|
89
|
+
multiple_options: option1, option2
|
90
|
+
---
|
91
|
+
```
|
92
|
+
|
93
|
+
The supported properties are:
|
94
|
+
|
95
|
+
* `number`
|
96
|
+
* `select`
|
97
|
+
* `multi_select`
|
98
|
+
* `date`
|
99
|
+
* `people`
|
100
|
+
* `files`
|
101
|
+
* `checkbox`
|
102
|
+
* `url`
|
103
|
+
* `email`
|
104
|
+
* `phone_number`
|
105
|
+
|
106
|
+
`created_time`, `last_edited_time`, `created_by`, `last_edited_by`, `title`, `rich_text` as advanced types like `formula`, `relation` and `rollup` are not supported.
|
107
|
+
|
108
|
+
Check notion documentation about [property values](https://developers.notion.com/reference/property-value-object#all-property-values).
|
109
|
+
|
71
110
|
## Page filename
|
72
111
|
|
73
112
|
There are two kinds of collections: posts and others.
|
@@ -36,19 +36,21 @@ module JekyllNotion
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def make_frontmatter
|
39
|
+
data = Jekyll::Utils.deep_merge_hashes(config_frontmatter, page_frontmatter)
|
40
|
+
frontmatter = data.to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
|
39
41
|
<<~CONTENT
|
40
42
|
---
|
41
|
-
id: #{current_page.id}
|
42
|
-
title: #{current_page.title}
|
43
|
-
date: #{current_page.created_datetime}
|
44
|
-
cover: #{current_page.cover}
|
45
43
|
#{frontmatter}
|
46
44
|
---
|
47
45
|
CONTENT
|
48
46
|
end
|
49
47
|
|
50
|
-
def
|
51
|
-
|
48
|
+
def page_frontmatter
|
49
|
+
Jekyll::Utils.deep_merge_hashes(current_page.custom_props, current_page.default_props)
|
50
|
+
end
|
51
|
+
|
52
|
+
def config_frontmatter
|
53
|
+
config.dig("database", "frontmatter") || {}
|
52
54
|
end
|
53
55
|
|
54
56
|
def make_filename
|
@@ -46,5 +46,71 @@ module JekyllNotion
|
|
46
46
|
def url
|
47
47
|
page[:url]
|
48
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
|
+
prop.multi_select.map(&:name).join(", ")
|
77
|
+
end
|
78
|
+
|
79
|
+
def select(prop)
|
80
|
+
prop["select"].name
|
81
|
+
end
|
82
|
+
|
83
|
+
def people(prop)
|
84
|
+
prop.people.map(&:name).join(", ")
|
85
|
+
end
|
86
|
+
|
87
|
+
def files(prop)
|
88
|
+
prop.files.map { |f| f.file.url }.join(", ")
|
89
|
+
end
|
90
|
+
|
91
|
+
def phone_number(prop)
|
92
|
+
prop.phone_number
|
93
|
+
end
|
94
|
+
|
95
|
+
def number(prop)
|
96
|
+
prop.number
|
97
|
+
end
|
98
|
+
|
99
|
+
def email(prop)
|
100
|
+
prop.email
|
101
|
+
end
|
102
|
+
|
103
|
+
def checkbox(prop)
|
104
|
+
prop.checkbox.to_s
|
105
|
+
end
|
106
|
+
|
107
|
+
# date type properties not supported:
|
108
|
+
# - end
|
109
|
+
# - time_zone
|
110
|
+
def date(prop)
|
111
|
+
prop.date.start
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
49
115
|
end
|
50
116
|
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.
|
4
|
+
version: 0.1.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-01-
|
11
|
+
date: 2022-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -144,9 +144,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: 2.5.0
|
145
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
146
|
requirements:
|
147
|
-
- - "
|
147
|
+
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version:
|
149
|
+
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
152
|
rubygems_version: 2.7.3
|