jekyll-notion 0.0.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -5
- data/lib/jekyll-notion/generator.rb +6 -12
- data/lib/jekyll-notion/notion_page.rb +69 -0
- data/lib/jekyll-notion/version.rb +1 -1
- data/lib/jekyll-notion.rb +1 -0
- 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: e49bed0932098925103231f77ac375ff0d86562ffb762c058c41b4db5e6ca091
|
4
|
+
data.tar.gz: 22e172d0c20d1b4dd9bbd4c926010a06492be08f247abe18f99795182ce1f319
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f9a68ae342fb7c23c24b9b744afc1c562a7f33bd270207bb8b4b0cd52306d393c95ed4b4e9571605437dd3c1d4bc2a44f0ec029889158dd54fbe4932aaea9d7
|
7
|
+
data.tar.gz: eb5e8580bbd76add336f6fb0f2ee68efe3c4a807ddfbf3657054088288ebd787803babb3d7e00b0a392eb2feee14aca6629071924352a4e378672b52547409d6
|
data/README.md
CHANGED
@@ -59,18 +59,56 @@ And that's all. Each page in the notion database will be included in the selecte
|
|
59
59
|
|
60
60
|
Below, page notion default properties are set in each page frontmatter.
|
61
61
|
|
62
|
+
Default properties include `title`, created_time`, `last_edited_time`, `icon` and `cover.
|
63
|
+
|
62
64
|
```
|
63
65
|
---
|
64
|
-
id:
|
65
|
-
title:
|
66
|
-
cover:
|
67
|
-
date:
|
68
|
-
icon:
|
66
|
+
id: b2998...
|
67
|
+
title: A title
|
68
|
+
cover: https://img.bank.sh/an_image.jpg
|
69
|
+
date: 2022-01-23T12:31:00.000Z
|
70
|
+
icon: \U0001F4A5
|
69
71
|
---
|
70
72
|
```
|
71
73
|
|
72
74
|
Any property provided in the frontmatter config that matches a default property will be overwritten by the default value.
|
73
75
|
|
76
|
+
### Custom properties
|
77
|
+
|
78
|
+
In addition to default properties, custom properties are also supported.
|
79
|
+
|
80
|
+
Custom properties are appended to page frontmatter by default. Every property name is snake-cased.
|
81
|
+
For example, two properties named `Multiple Options` and `Tags` will be transformed to `multiple_options` and `tags`, respectively.
|
82
|
+
|
83
|
+
```
|
84
|
+
---
|
85
|
+
id: b2998...
|
86
|
+
title: A title
|
87
|
+
cover: https://img.bank.sh/an_image.jpg
|
88
|
+
date: 2022-01-23T12:31:00.000Z
|
89
|
+
icon: \U0001F4A5
|
90
|
+
tags: tag1, tag2, tag3
|
91
|
+
multiple_options: option1, option2
|
92
|
+
---
|
93
|
+
```
|
94
|
+
|
95
|
+
The supported properties are:
|
96
|
+
|
97
|
+
* `number`
|
98
|
+
* `select`
|
99
|
+
* `multi_select`
|
100
|
+
* `date`
|
101
|
+
* `people`
|
102
|
+
* `files`
|
103
|
+
* `checkbox`
|
104
|
+
* `url`
|
105
|
+
* `email`
|
106
|
+
* `phone_number`
|
107
|
+
|
108
|
+
`created_by`, `last_edited_by`, `rich_text` as advanced types like `formula`, `relation` and `rollup` are not supported.
|
109
|
+
|
110
|
+
Check notion documentation about [property values](https://developers.notion.com/reference/property-value-object#all-property-values).
|
111
|
+
|
74
112
|
## Page filename
|
75
113
|
|
76
114
|
There are two kinds of collections: posts and others.
|
@@ -36,23 +36,17 @@ module JekyllNotion
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def make_frontmatter
|
39
|
-
data = Jekyll::Utils.deep_merge_hashes(config_frontmatter,
|
40
|
-
|
39
|
+
data = Jekyll::Utils.deep_merge_hashes(config_frontmatter, page_frontmatter)
|
40
|
+
frontmatter = data.to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
|
41
41
|
<<~CONTENT
|
42
42
|
---
|
43
|
-
#{
|
43
|
+
#{frontmatter}
|
44
44
|
---
|
45
45
|
CONTENT
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
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
|
-
}
|
48
|
+
def page_frontmatter
|
49
|
+
Jekyll::Utils.deep_merge_hashes(current_page.custom_props, current_page.default_props)
|
56
50
|
end
|
57
51
|
|
58
52
|
def config_frontmatter
|
@@ -72,7 +66,7 @@ module JekyllNotion
|
|
72
66
|
end
|
73
67
|
|
74
68
|
def collection
|
75
|
-
@
|
69
|
+
@site.collections[collection_name]
|
76
70
|
end
|
77
71
|
|
78
72
|
def config
|
@@ -46,5 +46,74 @@ 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
|
+
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
|
+
end
|
117
|
+
end
|
49
118
|
end
|
50
119
|
end
|
data/lib/jekyll-notion.rb
CHANGED
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.3
|
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-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|