Class: JekyllNotion::NotionPage
- Inherits:
-
Object
- Object
- JekyllNotion::NotionPage
- Defined in:
- lib/jekyll-notion/notion_page.rb
Defined Under Namespace
Classes: CustomProperty
Instance Attribute Summary collapse
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #cover ⇒ Object
- #created_date ⇒ Object
- #created_datetime ⇒ Object
- #custom_props ⇒ Object
- #default_props ⇒ Object
- #icon ⇒ Object
- #id ⇒ Object
-
#initialize(page:, layout:) ⇒ NotionPage
constructor
A new instance of NotionPage.
- #title ⇒ Object
- #updated_date ⇒ Object
- #updated_datetime ⇒ Object
- #url ⇒ Object
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
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
5 6 7 |
# File 'lib/jekyll-notion/notion_page.rb', line 5 def layout @layout end |
#page ⇒ Object (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
#cover ⇒ Object
18 19 20 |
# File 'lib/jekyll-notion/notion_page.rb', line 18 def cover page.dig(:cover, :external, :url) end |
#created_date ⇒ Object
30 31 32 |
# File 'lib/jekyll-notion/notion_page.rb', line 30 def created_date created_datetime.to_date end |
#created_datetime ⇒ Object
34 35 36 |
# File 'lib/jekyll-notion/notion_page.rb', line 34 def created_datetime DateTime.parse(page["created_time"]) end |
#custom_props ⇒ Object
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_props ⇒ Object
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 |
#icon ⇒ Object
22 23 24 |
# File 'lib/jekyll-notion/notion_page.rb', line 22 def icon page.dig(:icon, :emoji) end |
#id ⇒ Object
26 27 28 |
# File 'lib/jekyll-notion/notion_page.rb', line 26 def id page[:id] end |
#title ⇒ Object
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_date ⇒ Object
38 39 40 |
# File 'lib/jekyll-notion/notion_page.rb', line 38 def updated_date updated_datetime.to_date end |
#updated_datetime ⇒ Object
42 43 44 |
# File 'lib/jekyll-notion/notion_page.rb', line 42 def updated_datetime DateTime.parse(page["last_edited_time"]) end |
#url ⇒ Object
46 47 48 |
# File 'lib/jekyll-notion/notion_page.rb', line 46 def url page[:url] end |