notion_to_md 0.2.1 → 1.0.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: ce6b39ba9cc39e1428bc8a654532d16b9ea99054e3fbd96cf30edd56cbed28a8
4
- data.tar.gz: 6e38131568bb150a9ca7904f383fd8ade5721ccc5affe2949672b597b948ffe3
3
+ metadata.gz: 924eafad078f99447e1a9d88403d48448e5011c87a9d2ae32b527a9e4a201f85
4
+ data.tar.gz: 791bf46ea8cfbb49958cc80862fe63047e1158f4845f21665ce21d20b37628ad
5
5
  SHA512:
6
- metadata.gz: 3ccfa65a6877fd1bcdc9a36f72094cc8374934a2713abfc10441b23348b919818539c286469afad699f69594dc854a12f884299d2c335ff6cd9bc17d920bbcb6
7
- data.tar.gz: fd638c9a53e8c6f6cf644e2e471fc7ecf8150bb1ef371d9f6f41215e4d1bd953d1929113c25dc703dd66647165adf84bbf9f7bddcb6494d8b0bcea5bd06f2741
6
+ metadata.gz: e50e6688db3930ecca7c808d357fe07799465dfa5274a6b0141d97de5adb204f361782240c35152c21165eb8e68cdbf44a04e696006cd345293948825a2a74da
7
+ data.tar.gz: 349e89d00109d05b7dfe24499a80dc0318cf6895524e527b025ef02325bc27f06775544f20a995166cef1229b62aacd6344c1331c2c7549eb01f3be5181198cb
@@ -10,43 +10,15 @@ module NotionToMd
10
10
  end
11
11
 
12
12
  def convert(frontmatter: false)
13
+ md_page = Page.new(page: page, blocks: page_blocks)
13
14
  <<~MD
14
- #{parse_frontmatter if frontmatter}
15
- #{parse_content}
15
+ #{md_page.frontmatter if frontmatter}
16
+ #{md_page.body}
16
17
  MD
17
18
  end
18
19
 
19
20
  private
20
21
 
21
- def parse_content
22
- md = page_blocks[:results].map do |block|
23
- next Block.blank if block[:type] == 'paragraph' && block.dig(:paragraph, :text).empty?
24
-
25
- block_type = block[:type].to_sym
26
-
27
- begin
28
- Block.send(block_type, block[block_type])
29
- rescue StandardError
30
- Logger.info("Unsupported block type: #{block_type}")
31
- next nil
32
- end
33
- end
34
- Logger.info("Notion page #{page_id} converted to markdown")
35
- md.compact.join("\n\n")
36
- end
37
-
38
- def parse_frontmatter
39
- notion_page = Page.new(page: page)
40
- frontmatter = notion_page.props.to_a.map do |k, v|
41
- "#{k}: #{v}"
42
- end.join("\n")
43
- <<~CONTENT
44
- ---
45
- #{frontmatter}
46
- ---
47
- CONTENT
48
- end
49
-
50
22
  def page
51
23
  @page ||= @notion.page(id: page_id)
52
24
  end
@@ -2,10 +2,11 @@
2
2
 
3
3
  module NotionToMd
4
4
  class Page
5
- attr_reader :page
5
+ attr_reader :page, :blocks
6
6
 
7
- def initialize(page:)
7
+ def initialize(page:, blocks:)
8
8
  @page = page
9
+ @blocks = blocks
9
10
  end
10
11
 
11
12
  def title
@@ -42,6 +43,31 @@ module NotionToMd
42
43
  page[:archived]
43
44
  end
44
45
 
46
+ def body
47
+ @body ||= blocks[:results].map do |block|
48
+ next Block.blank if block[:type] == 'paragraph' && block.dig(:paragraph, :text).empty?
49
+
50
+ block_type = block[:type].to_sym
51
+
52
+ begin
53
+ Block.send(block_type, block[block_type])
54
+ rescue StandardError
55
+ Logger.info("Unsupported block type: #{block_type}")
56
+ next nil
57
+ end
58
+ end.compact.join("\n\n")
59
+ end
60
+
61
+ def frontmatter
62
+ @frontmatter ||= <<~CONTENT
63
+ ---
64
+ #{props.to_a.map do |k, v|
65
+ "#{k}: #{v}"
66
+ end.join("\n")}
67
+ ---
68
+ CONTENT
69
+ end
70
+
45
71
  def props
46
72
  @props ||= custom_props.deep_merge(default_props)
47
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionToMd
4
- VERSION = '0.2.1'
4
+ VERSION = '1.0.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: 0.2.1
4
+ version: 1.0.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-02-26 00:00:00.000000000 Z
11
+ date: 2022-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport