jekyll-notion 0.0.0 → 0.1.1

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: 72643f8e9760b1f45a30fd87a8448cf16b1f85a63bcec6c83b4d4b3dea8b4c21
4
- data.tar.gz: 95b0c61bdfc5e7c6dc018798474dcd40e6ec0728c0836d552249b9b7da8213bf
3
+ metadata.gz: ea3659b155864441e1d6eb08111597ce11ffec1891011ed9f7c7724dcbc7d186
4
+ data.tar.gz: 2e6ecac50f3d6aaae6e3af587d362f5470054452552e2dc1691d25e1abead605
5
5
  SHA512:
6
- metadata.gz: daf22fba12e6385aaa5842103c390ee6f58c093bf5ee1b199700c769a45d7736f04600f71cc0bcdedd77018a547024f8bdaf517a842cd88d58f13af4a77d57c9
7
- data.tar.gz: 4d28a3d8319345e1a936ac3112009568a1d693cbd3314783fdea12d4c1cca38da33f701b25d870eb1cebf0fc11347f849979fcfee94a9d98173d33e376e50bec
6
+ metadata.gz: 5698ea2735469d130cbec72aee61facd213589f1e349dd7d29588214896f931d2d8c740a36f5d7d2f36d83ca9a9b5fd976806c3c135eca7e201eac13f4b98d97
7
+ data.tar.gz: 7cad325c6ce2cf4e3216f086693b40ead4cc7b176826c1f26efb33b98e342d92ee285d9ed22f9d84b6e4eced090a227ef88bbf5139dc662c2067c9bec79f08f0
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
  ```
@@ -61,13 +61,52 @@ Below, page notion default properties are set in each page frontmatter.
61
61
 
62
62
  ```
63
63
  ---
64
- id: id
65
- title: properties > Name > title > plain_text
66
- cover: cover > external > url
67
- date: created_time
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 frontmatter
51
- config.dig("database", "frontmatter").to_a.map { |k, v| "#{k}: #{v}" }.join("\n")
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllNotion
4
- VERSION = "0.0.0"
4
+ VERSION = "0.1.1"
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.0
4
+ version: 0.1.1
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-19 00:00:00.000000000 Z
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport