Class: Sawsge::Home

Inherits:
Page show all
Defined in:
lib/home.rb

Overview

The homepage

Instance Attribute Summary

Attributes inherited from Page

#title

Attributes inherited from Resource

#path

Instance Method Summary collapse

Methods inherited from Page

#build

Methods inherited from Resource

#build

Constructor Details

#initialize(path, posts) ⇒ Home

Returns a new instance of Home.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/home.rb', line 6

def initialize(path, posts)
  super(path)
  posts.each do |post|
    # Adds collapseable summary of each post on the front
    # page
    summary_fragment = Nokogiri::HTML5.fragment <<~HTML
      <details open>
        <summary>
          <a href=\"/#{File.dirname(post.path)}\">#{post.title}</a> <date>#{post.date}</date>
        </summary>
        <p>#{post.summary}</p>
        <a href=\"#{File.dirname(post.path)}\">Read more</a>
      </details>
    HTML
    @document.at_css('footer').add_previous_sibling summary_fragment
  end
end