Class: Jekyll::ArchivesV2::Archive
- Inherits:
-
Page
- Object
- Page
- Jekyll::ArchivesV2::Archive
- Defined in:
- lib/jekyll-archives-v2/archive.rb
Constant Summary collapse
- ATTRIBUTES_FOR_LIQUID =
Attributes for Liquid templates
%w( collection_name documents type title date name path url permalink ).freeze
Instance Attribute Summary collapse
-
#collection_name ⇒ Object
Returns the value of attribute collection_name.
-
#documents ⇒ Object
Returns the value of attribute documents.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#date ⇒ Object
Produce a date object if a date-based archive.
-
#initialize(site, title, type, collection_name, documents) ⇒ Archive
constructor
Initialize a new Archive page.
-
#inspect ⇒ Object
Returns the object as a debug String.
-
#layout ⇒ Object
The layout to use for rendering.
- #permalink ⇒ Object
-
#relative_path ⇒ Object
Obtain the write path relative to the destination directory.
-
#template ⇒ Object
The template of the permalink.
-
#title ⇒ Object
Produce a title object suitable for Liquid based on type of archive.
-
#to_liquid ⇒ Object
The Liquid representation of this page.
-
#url ⇒ Object
The generated relative url of this page.
-
#url_placeholders ⇒ Object
Returns a hash of URL placeholder names (as symbols) mapping to the desired placeholder replacements.
Constructor Details
#initialize(site, title, type, collection_name, documents) ⇒ Archive
Initialize a new Archive page
site - The Site object. title - The name of the tag/category or a Hash of the year/month/day in case of date.
e.g. { :year => 2014, :month => 08 } or "my-category" or "my-tag".
type - The type of archive. Can be one of “year”, “month”, “day”, “category”, or “tag” collection_name - The name of the collection. documents - The array of documents that belong in this archive.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll-archives-v2/archive.rb', line 29 def initialize(site, title, type, collection_name, documents) @site = site @documents = documents @type = type @title = title @collection_name = collection_name @config = site.config["jekyll-archives"][collection_name] @slug = slugify_string_title # Use ".html" for file extension and url for path @ext = File.extname(relative_path) @path = relative_path @name = File.basename(relative_path, @ext) @data = { "layout" => layout, } @content = "" end |
Instance Attribute Details
#collection_name ⇒ Object
Returns the value of attribute collection_name.
6 7 8 |
# File 'lib/jekyll-archives-v2/archive.rb', line 6 def collection_name @collection_name end |
#documents ⇒ Object
Returns the value of attribute documents.
6 7 8 |
# File 'lib/jekyll-archives-v2/archive.rb', line 6 def documents @documents end |
#slug ⇒ Object
Returns the value of attribute slug.
6 7 8 |
# File 'lib/jekyll-archives-v2/archive.rb', line 6 def slug @slug end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/jekyll-archives-v2/archive.rb', line 6 def type @type end |
Instance Method Details
#date ⇒ Object
Produce a date object if a date-based archive
Returns a Date.
101 102 103 104 105 106 107 108 |
# File 'lib/jekyll-archives-v2/archive.rb', line 101 def date return unless @title.is_a?(Hash) @date ||= begin args = @title.values.map(&:to_i) Date.new(*args) end end |
#inspect ⇒ Object
Returns the object as a debug String.
122 123 124 |
# File 'lib/jekyll-archives-v2/archive.rb', line 122 def inspect "#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>" end |
#layout ⇒ Object
The layout to use for rendering
Returns the layout as a String
59 60 61 |
# File 'lib/jekyll-archives-v2/archive.rb', line 59 def layout @config.dig("layouts", type) || @config["layout"] end |
#permalink ⇒ Object
86 87 88 |
# File 'lib/jekyll-archives-v2/archive.rb', line 86 def permalink data&.is_a?(Hash) && data["permalink"] end |
#relative_path ⇒ Object
Obtain the write path relative to the destination directory
Returns the destination relative path String.
113 114 115 116 117 118 119 |
# File 'lib/jekyll-archives-v2/archive.rb', line 113 def relative_path @relative_path ||= begin path = URL.unescape_path(url).gsub(%r!^/!, "") path = File.join(path, "index.html") if url.end_with?("/") path end end |
#template ⇒ Object
The template of the permalink.
Returns the template String.
52 53 54 |
# File 'lib/jekyll-archives-v2/archive.rb', line 52 def template @config.dig("permalinks", type) end |
#title ⇒ Object
Produce a title object suitable for Liquid based on type of archive.
Returns a String (for tag and category archives) and nil for date-based archives.
94 95 96 |
# File 'lib/jekyll-archives-v2/archive.rb', line 94 def title @title if @title.is_a? String end |
#to_liquid ⇒ Object
The Liquid representation of this page.
127 128 129 |
# File 'lib/jekyll-archives-v2/archive.rb', line 127 def to_liquid @to_liquid ||= Jekyll::ArchivesV2::PageDrop.new(self) end |
#url ⇒ Object
The generated relative url of this page. e.g. /about.html.
Returns the String url.
76 77 78 79 80 81 82 83 84 |
# File 'lib/jekyll-archives-v2/archive.rb', line 76 def url @url ||= URL.new( :template => template, :placeholders => url_placeholders, :permalink => nil ).to_s rescue ArgumentError raise ArgumentError, "Template \"#{template}\" provided is invalid." end |
#url_placeholders ⇒ Object
Returns a hash of URL placeholder names (as symbols) mapping to the desired placeholder replacements. For details see “url.rb”.
65 66 67 68 69 70 71 |
# File 'lib/jekyll-archives-v2/archive.rb', line 65 def url_placeholders if @title.is_a? Hash @title.merge(:collection => @collection_name, :type => @type) else { :collection => @collection_name, :name => @slug, :type => @type } end end |