Class: JekyllNotion::NotionPage

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-notion/notion_page.rb

Defined Under Namespace

Classes: CustomProperty

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page:, layout:) ⇒ NotionPage

Returns a new instance of NotionPage.



7
8
9
10
# File 'lib/jekyll-notion/notion_page.rb', line 7

def initialize(page:, layout:)
  @page = page
  @layout = layout
end

Instance Attribute Details

#layoutObject (readonly)

Returns the value of attribute layout.



5
6
7
# File 'lib/jekyll-notion/notion_page.rb', line 5

def layout
  @layout
end

#pageObject (readonly)

Returns the value of attribute page.



5
6
7
# File 'lib/jekyll-notion/notion_page.rb', line 5

def page
  @page
end

Instance Method Details

#coverObject



18
19
20
# File 'lib/jekyll-notion/notion_page.rb', line 18

def cover
  page.dig(:cover, :external, :url)
end

#created_dateObject



30
31
32
# File 'lib/jekyll-notion/notion_page.rb', line 30

def created_date
  created_datetime.to_date
end

#created_datetimeObject



34
35
36
# File 'lib/jekyll-notion/notion_page.rb', line 34

def created_datetime
  DateTime.parse(page["created_time"])
end

#custom_propsObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jekyll-notion/notion_page.rb', line 50

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_propsObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/jekyll-notion/notion_page.rb', line 62

def default_props
  @default_props ||= {
    :id           => id,
    :title        => title,
    :date         => created_datetime,
    :cover        => cover,
    :icon         => icon,
    :updated_date => updated_datetime,
  }
end

#iconObject



22
23
24
# File 'lib/jekyll-notion/notion_page.rb', line 22

def icon
  page.dig(:icon, :emoji)
end

#idObject



26
27
28
# File 'lib/jekyll-notion/notion_page.rb', line 26

def id
  page[:id]
end

#titleObject



12
13
14
15
16
# File 'lib/jekyll-notion/notion_page.rb', line 12

def title
  page.dig(:properties, :Name, :title).inject("") do |acc, slug|
    acc + slug[:plain_text]
  end
end

#updated_dateObject



38
39
40
# File 'lib/jekyll-notion/notion_page.rb', line 38

def updated_date
  updated_datetime.to_date
end

#updated_datetimeObject



42
43
44
# File 'lib/jekyll-notion/notion_page.rb', line 42

def updated_datetime
  DateTime.parse(page["last_edited_time"])
end

#urlObject



46
47
48
# File 'lib/jekyll-notion/notion_page.rb', line 46

def url
  page[:url]
end