Class: Jekyll::Endless::TagPage

Inherits:
Page
  • Object
show all
Defined in:
lib/jekyll-theme-endless/generate-tagpages.rb

Overview

TagPage is a subclass of Page It is used in the ‘TagPageGenerator`

Instance Method Summary collapse

Constructor Details

#initialize(site, base, dir, tag) ⇒ TagPage

Returns a new instance of TagPage.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/jekyll-theme-endless/generate-tagpages.rb', line 66

def initialize(site, base, dir, tag)
	# Define instance variables ('@') to make values available in the super-class `Page`.
	# The variables are available in the layout as e.g. `page.name`.
	@site = site
	@base = base
	@dir	= dir
	@name = 'index.html'

	self.process(@name)
	Jekyll.logger.debug("TagPageGenerator", "[DEBUG] Generating file in folder: #{dir}")
	self.read_yaml(File.join(base, '_layouts'), 'page-tag.html')

	# The prefix for the generated title is set via `tag_title_prefix` in `_config.yml` and defaults to `Tag: `
	tag_title_prefix = site.config['tag_title_prefix'] || 'Tag: '
	# Generates the title for the tag page and makes it available in the layout file as `page.title`
	# Since AsciiDoc escapes the title, the plugin must also escape the content of the title (otherwise the tag would be unescaped).
	self.data['title'] = CGI.escapeHTML("#{tag_title_prefix}#{tag}")
	Jekyll.logger.debug("TagPageGenerator", "[DEBUG] Generating title for tag page: #{self.data['title']}")
	# Makes `page.tag` available in the layout file
	self.data['tag'] = tag

	# Make `site.tags[tag]` available as `page.postlist` in the layout
	# The use of `uniq` ensures that an entry does not appear twice in the list of "posts tagged with this tag"
	# if a tag has been accidentally entered twice in the tag list of a post.
	self.data['postlist'] = (site.tags[tag] || []).uniq

	#Jekyll.logger.debug("TagPageGenerator", "[DEBUG] Loaded self.data: #{self.data.inspect}")
end