Class: JekyllIndexPages::IndexPage

Inherits:
Jekyll::Page
  • Object
show all
Defined in:
lib/jekyll-index-pages/index-page.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, base, dir, config, label, pager) ⇒ IndexPage

Returns a new instance of IndexPage.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jekyll-index-pages/index-page.rb', line 3

def initialize(site, base, dir, config, label, pager)
  @site = site
  @base = base
  @dir = dir
  @name = "index.md"

  title = config["title"] || ":label"
  excerpt = config["excerpt"] || ":label"

  self.process(@name)

  self.content = ""
  self.data = {}

  if config.key?("data") and config["data"].is_a?(Hash)
    config["data"].each do |key, value|
      self.data[key] = value
    end
  end

  self.data["title"] = title.sub(":label", label)
  self.data["layout"] = config["layout"]
  self.data["excerpt"] = excerpt.sub(":label", label)

  self.data["pager"] = Hash.new
  self.data["pager"]["docs"] = pager.docs
  self.data["pager"]["total_pages"] = pager.total_pages
  self.data["pager"]["current_page"] = pager.current_page
  self.data["pager"]["prev_page"] = pager.prev_page
  self.data["pager"]["next_page"] = pager.next_page
  self.data["pager"]["prev_page_url"] =
    if (pager.prev_page == 1)
      File.join(dir.sub(%r{/\d+}, ""), "/")
    elsif (pager.prev_page > 1)
      File.join(dir.sub(%r{/\d+}, ""), pager.prev_page.to_s << "/")
    else
      ""
    end
  self.data["pager"]["next_page_url"] =
    if (pager.next_page > 0)
      File.join(dir.sub(%r{/\d+}, ""), pager.next_page.to_s << "/")
    else
      ""
    end

  Jekyll::Hooks.trigger :pages, :post_init, self
end