jekyll-notion 0.0.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d1ccb2f2f5451b3eaf6d80dd8f8fed62cd2d5fd582d1cce09fbf10a494b54ac
4
- data.tar.gz: f651dd2f6e3c5404b33af0abdb11274eacc34296c6301e9d79d76f38ccb8f1e6
3
+ metadata.gz: ad5bd5565352088d6d5d4048155a6abfb38bb0136437159ed7fdfd7d0aaf27a1
4
+ data.tar.gz: 57d4da4ceec1869150d33c9bdc10825a636de18409798725bf1ae891d1459b50
5
5
  SHA512:
6
- metadata.gz: f87ce41674b28e289e7b69a0d4a40ac64fc0c9e9384ce5fdfb9b82312ba439ba60c5b7bab2a8ead2d1075adffd4a852bbae7534acc67d5317221c5fe236b52bf
7
- data.tar.gz: 9ac472cd2c48b0affd89825b8d08a11fb8e562ac8da05193111bcc85f219196352345f4c6ebd6ff0b9721c847f00e30fc0820190fa8dd6950758355b24aafbd5
6
+ metadata.gz: 5749b831d1884f5d88b344d92ff924dc474813098b05dedfc0862a38dceada9ac8e31c9fd5a80ff418a3974d8ff61fd8879a2c7522dfb1bff2c02b133e82d83f
7
+ data.tar.gz: c10de414ceb372b5e2c2a29ba06878f69aaa6f01cc7d37b0a1a8f50078a55b92d4d63a2709e963f2da625ac73878008ae33a0c74c375ecf06f67b5b08c02a0cc
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: { "propery": "Last ordered", "direction": "ascending" }
43
+ sort: { "property": "Last ordered", "direction": "ascending" }
44
44
  frontmatter:
45
45
  layout: post
46
46
  ```
@@ -59,17 +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: id
65
- title: properties > Name > title > plain_text
66
- cover: cover > external > url
67
- date: created_time
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
68
71
  ---
69
72
  ```
70
73
 
71
74
  Any property provided in the frontmatter config that matches a default property will be overwritten by the default value.
72
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
+
73
112
  ## Page filename
74
113
 
75
114
  There are two kinds of collections: posts and others.
@@ -36,22 +36,17 @@ module JekyllNotion
36
36
  end
37
37
 
38
38
  def make_frontmatter
39
- data = Jekyll::Utils.deep_merge_hashes(config_frontmatter, notion_frontmatter)
40
- page_frontmatter = data.to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
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
- #{page_frontmatter}
43
+ #{frontmatter}
44
44
  ---
45
45
  CONTENT
46
46
  end
47
47
 
48
- def notion_frontmatter
49
- {
50
- :id => current_page.id,
51
- :title => current_page.title,
52
- :date => current_page.created_datetime,
53
- :cover => current_page.cover,
54
- }
48
+ def page_frontmatter
49
+ Jekyll::Utils.deep_merge_hashes(current_page.custom_props, current_page.default_props)
55
50
  end
56
51
 
57
52
  def config_frontmatter
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllNotion
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/jekyll-notion.rb CHANGED
@@ -5,6 +5,7 @@ require "notion"
5
5
  require "notion_to_md"
6
6
  require "logger"
7
7
  require "active_support/inflector"
8
+ require "active_support/core_ext/object/blank"
8
9
  require "jekyll-notion/generator"
9
10
 
10
11
  NotionToMd::Logger.level = Logger::ERROR
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.0.1
4
+ version: 0.1.2
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-22 00:00:00.000000000 Z
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport