notion_to_md 2.3.0 → 2.4.0

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: bba453442621ce806b36625a5febfd14a2f75d8051c49923d845435535e11574
4
- data.tar.gz: bc8a6b8a8ba768728cbb88b88a5d4c4069aa173ac9275d5c6a9cb95a37827a43
3
+ metadata.gz: fb94bccdf9dca4374bfaeb42164cce77f3a1963048a96b83a53e238ff9768163
4
+ data.tar.gz: '039b7d197fc03a6a04ffaf1cb90f3f758dd597a7381a2002da677065d48f2d76'
5
5
  SHA512:
6
- metadata.gz: d7005a6bdfd26d3322a92ee49274ec8006549e90f850cc0d4fbc5907a0e0a9ecc526578b7c8964462563395e7980269a87d43d705fd6a2ccd8aaf26b240b6006
7
- data.tar.gz: 9c52fe4feff24a090c19c6b736d1af5daaefc8dd5ce0fbe994acf6b41c2c1bbf8631846d71c59b5757219dc72583d50d6c316fc73bb81a453e8e3a02270407d6
6
+ metadata.gz: ce0dd31c6a1eb871468b151e2374311799b802b0f58e6e450bcc24aaa76f586f9755ad63953f3b61b45e0102d1440fa3d8f66538c014dbc921fc8ecf01a69a6f
7
+ data.tar.gz: 1a008da641c3c449b401ede3e2d65608a47192cae908888bcebd96eba7162e70f7640e549a881c459e9010cd1703248c49fa8d65d3a516489601a80c48e0e87d
data/README.md CHANGED
@@ -102,6 +102,10 @@ created_time: 2022-01-23T12:31:00.000Z
102
102
  last_edited_time: 2022-01-23T12:31:00.000Z
103
103
  icon: 💥
104
104
  archived: false
105
+ created_by_id: db313571-0280-411f-a6de-70e826421d16
106
+ created_by_object: user
107
+ last_edited_by_id: db313571-0280-411f-a6de-70e826421d16
108
+ last_edited_by_object: user
105
109
  ---
106
110
  ```
107
111
 
@@ -11,11 +11,10 @@ module NotionToMd
11
11
  new(blocks: blocks).normalize
12
12
  end
13
13
 
14
- attr_reader :blocks, :normalized_blocks
14
+ attr_reader :normalized_blocks
15
15
 
16
16
  def initialize(blocks:)
17
- @blocks = blocks
18
- @normalized_blocks = blocks
17
+ @normalized_blocks = blocks.dup
19
18
  end
20
19
 
21
20
  def normalize
@@ -35,23 +34,23 @@ module NotionToMd
35
34
  # we need to normalize the blocks we've collected so far.
36
35
  # Then we add the current block to the new blocks array.
37
36
  # This is because we want to keep the order of the blocks.
38
- new_blocks << new_block_and_reset(type, blocks_to_normalize) unless blocks_to_normalize.empty?
37
+ new_blocks << new_block_and_reset_blocks_to_normalize(type) unless blocks_to_normalize.empty?
39
38
  new_blocks << block
40
39
  end
41
40
  end
42
41
 
43
- # If the last block is of the provided type, it won't be added to the new blocks array.
42
+ # If the last block is the provided type, it won't be added to the new blocks array.
44
43
  # So, we need to normalize the blocks we've collected so far.
45
- new_blocks << new_block_and_reset(type, blocks_to_normalize) unless blocks_to_normalize.empty?
44
+ new_blocks << new_block_and_reset_blocks_to_normalize(type) unless blocks_to_normalize.empty?
46
45
 
47
46
  normalized_blocks.replace(new_blocks)
48
47
  end
49
48
 
50
49
  private
51
50
 
52
- def new_block_and_reset(type, children)
53
- new_block = new_block_for(type, children)
54
- reset_blocks_to_normalize
51
+ def new_block_and_reset_blocks_to_normalize(type)
52
+ new_block = new_block_for(type, blocks_to_normalize)
53
+ @blocks_to_normalize = []
55
54
  new_block
56
55
  end
57
56
 
@@ -59,10 +58,6 @@ module NotionToMd
59
58
  @blocks_to_normalize ||= []
60
59
  end
61
60
 
62
- def reset_blocks_to_normalize
63
- @blocks_to_normalize = []
64
- end
65
-
66
61
  def new_block_for(type, children)
67
62
  case type
68
63
  when :bulleted_list_item
@@ -5,7 +5,7 @@ module NotionToMd
5
5
  class Types
6
6
  class << self
7
7
  def paragraph(block)
8
- return blank if block.rich_text.empty?
8
+ return blank if block[:rich_text].empty?
9
9
 
10
10
  convert_text(block)
11
11
  end
@@ -124,7 +124,7 @@ module NotionToMd
124
124
  href = text[:href]
125
125
  return content if href.nil?
126
126
 
127
- "[#{content}](#{href})"
127
+ "[#{content}](#{CGI.unescape(href)})"
128
128
  end
129
129
 
130
130
  def add_annotations(text, content)
@@ -29,11 +29,27 @@ module NotionToMd
29
29
  end
30
30
 
31
31
  def created_time
32
- DateTime.parse(page['created_time'])
32
+ page['created_time']
33
+ end
34
+
35
+ def created_by_object
36
+ page.dig(:created_by, :object)
37
+ end
38
+
39
+ def created_by_id
40
+ page.dig(:created_by, :id)
33
41
  end
34
42
 
35
43
  def last_edited_time
36
- DateTime.parse(page['last_edited_time'])
44
+ page['last_edited_time']
45
+ end
46
+
47
+ def last_edited_by_object
48
+ page.dig(:last_edited_by, :object)
49
+ end
50
+
51
+ def last_edited_by_id
52
+ page.dig(:last_edited_by, :id)
37
53
  end
38
54
 
39
55
  def url
@@ -77,12 +93,16 @@ module NotionToMd
77
93
  def default_props
78
94
  @default_props ||= {
79
95
  'id' => id,
80
- 'title' => title,
96
+ 'title' => title.dump,
81
97
  'created_time' => created_time,
82
98
  'cover' => cover,
83
99
  'icon' => icon,
84
100
  'last_edited_time' => last_edited_time,
85
- 'archived' => archived
101
+ 'archived' => archived,
102
+ 'created_by_object' => created_by_object,
103
+ 'created_by_id' => created_by_id,
104
+ 'last_edited_by_object' => last_edited_by_object,
105
+ 'last_edited_by_id' => last_edited_by_id
86
106
  }
87
107
  end
88
108
 
@@ -28,7 +28,7 @@ module NotionToMd
28
28
  end
29
29
 
30
30
  def select(prop)
31
- prop.dig(:select, :name)
31
+ prop.dig(:select, :name).dump
32
32
  rescue NoMethodError
33
33
  nil
34
34
  end
@@ -73,7 +73,16 @@ module NotionToMd
73
73
  # - end
74
74
  # - time_zone
75
75
  def date(prop)
76
- prop.dig(:date, :start)
76
+ date = prop.dig(:date, :start)
77
+
78
+ case date
79
+ when Date
80
+ date.to_time
81
+ when String
82
+ Time.parse(date)
83
+ else
84
+ date # Time or nil
85
+ end
77
86
  rescue NoMethodError
78
87
  nil
79
88
  end
@@ -85,7 +94,8 @@ module NotionToMd
85
94
  end
86
95
 
87
96
  def rich_text(prop)
88
- prop[:rich_text].map { |text| text[:plain_text] }.join
97
+ text = prop[:rich_text].map { |text| text[:plain_text] }.join
98
+ text.blank? ? nil : text.dump
89
99
  rescue NoMethodError
90
100
  nil
91
101
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionToMd
4
- VERSION = '2.3.0'
4
+ VERSION = '2.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_to_md
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.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: 2023-11-22 00:00:00.000000000 Z
11
+ date: 2023-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport