Class: Jekyll::Itafroma::ArchivePage

Inherits:
Page
  • Object
show all
Defined in:
lib/jekyll/itafroma/archive_page.rb

Overview

Represents an archive listing page.

Instance Method Summary collapse

Constructor Details

#initialize(site, base, layout, path, title, posts) ⇒ ArchivePage

Initalize a new ArchivePage.

site - The site. base - The path to the site’s root layout - The layout to use for the archive page path - The path to use for the archive page title - The tokenized title to use for the archive page date_pattern - The pattern of the date the posts are collated on posts - The posts to be added to the ArchivePage.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jekyll/itafroma/archive_page.rb', line 26

def initialize(site, base, layout, path, title, posts)
  @site = site
  @posts = posts

  @layout = layout
  @path = path
  @title = title
  @base = base
  @dir = dir
  @name = 'index.html'

  process(@name)

  read_yaml(File.join(base, '_layouts'), "#{@layout}.html")

  populate_data!
end

Instance Method Details

#dateObject

Generate the start date of the archive.

The date of the first post is used for the start date.

Returns a DateTime containing the archive’s start date.



49
50
51
# File 'lib/jekyll/itafroma/archive_page.rb', line 49

def date
  @posts.first.date
end

#populate_data!Object

Add the ArchivePage-specific data to the regular Page data.

Returns nothing.



70
71
72
73
74
75
76
# File 'lib/jekyll/itafroma/archive_page.rb', line 70

def populate_data!
  data.merge!('date' => date,
              'title' => title,
              'archive' => {
                'posts' => @posts
              })
end

#titleObject

Generate the ArchivePage title.

Returns a String containing the ArchivePage title.



56
57
58
# File 'lib/jekyll/itafroma/archive_page.rb', line 56

def title
  ArchiveSubstitution.new(@posts.first).translate(@title)
end

#urlObject

Generate the ArchivePage url.

Returns a String containing the ArchivePage url.



63
64
65
# File 'lib/jekyll/itafroma/archive_page.rb', line 63

def url
  File.join(ArchiveSubstitution.new(@posts.first).url(@path).to_s, 'index.html')
end