class NotionToMd::Page
Attributes
blocks[R]
page[R]
Public Class Methods
new(page:, blocks:)
click to toggle source
# File lib/notion_to_md/page.rb, line 7 def initialize(page:, blocks:) @page = page @blocks = blocks end
Public Instance Methods
archived()
click to toggle source
# File lib/notion_to_md/page.rb, line 42 def archived page[:archived] end
body()
click to toggle source
# File lib/notion_to_md/page.rb, line 46 def body @body ||= blocks[:results].map do |block| next Block.blank if block[:type] == 'paragraph' && block.dig(:paragraph, :rich_text).empty? block_type = block[:type].to_sym begin Block.send(block_type, block[block_type]) rescue StandardError Logger.info("Unsupported block type: #{block_type}") next nil end end.compact.join("\n\n") end
cover()
click to toggle source
# File lib/notion_to_md/page.rb, line 18 def cover page.dig(:cover, :external, :url) end
created_time()
click to toggle source
# File lib/notion_to_md/page.rb, line 30 def created_time DateTime.parse(page['created_time']) end
custom_props()
click to toggle source
# File lib/notion_to_md/page.rb, line 75 def custom_props @custom_props ||= page.properties.each_with_object({}) do |prop, memo| name = prop.first value = prop.last # Notion::Messages::Message type = value.type next memo unless CustomProperty.respond_to?(type.to_sym) memo[name.parameterize.underscore] = CustomProperty.send(type, value) end.reject { |_k, v| v.presence.nil? } end
default_props()
click to toggle source
# File lib/notion_to_md/page.rb, line 87 def default_props @default_props ||= { 'id' => id, 'title' => title, 'created_time' => created_time, 'cover' => cover, 'icon' => icon, 'last_edited_time' => last_edited_time, 'archived' => archived } end
frontmatter()
click to toggle source
# File lib/notion_to_md/page.rb, line 61 def frontmatter @frontmatter ||= <<~CONTENT --- #{props.to_a.map do |k, v| "#{k}: #{v}" end.join("\n")} --- CONTENT end
icon()
click to toggle source
# File lib/notion_to_md/page.rb, line 22 def icon page.dig(:icon, :emoji) end
id()
click to toggle source
# File lib/notion_to_md/page.rb, line 26 def id page[:id] end
last_edited_time()
click to toggle source
# File lib/notion_to_md/page.rb, line 34 def last_edited_time DateTime.parse(page['last_edited_time']) end
props()
click to toggle source
# File lib/notion_to_md/page.rb, line 71 def props @props ||= custom_props.deep_merge(default_props) end
title()
click to toggle source
# File lib/notion_to_md/page.rb, line 12 def title page.dig(:properties, :Name, :title).inject('') do |acc, slug| acc + slug[:plain_text] end end
url()
click to toggle source
# File lib/notion_to_md/page.rb, line 38 def url page[:url] end