Class: Abqari::RelatedIndexPage
- Inherits:
-
Object
- Object
- Abqari::RelatedIndexPage
- Defined in:
- lib/abqari/related_index_page.rb
Overview
Auto-generated index page that lists ALL related items for a source
page, used when there are more matches than fit in the show-view's
related.limit block. URL is /<source url>related/, e.g.
/posts/writing-in-markdown/related/.
Generated only when total_related > limit — pages with zero or
few related items don't get an index page (the show-view block
already shows everything). Site#generate_related_pages handles the
decision and creation.
Instance Attribute Summary collapse
-
#related_items ⇒ Object
readonly
Returns the value of attribute related_items.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#source_page ⇒ Object
readonly
Returns the value of attribute source_page.
Instance Method Summary collapse
- #bundle_images ⇒ Object
- #content ⇒ Object
- #description ⇒ Object
- #frontmatter ⇒ Object
-
#initialize(source_page, site, related_items) ⇒ RelatedIndexPage
constructor
A new instance of RelatedIndexPage.
- #lastmod ⇒ Object
-
#needs_render? ⇒ Boolean
Re-render when shared deps change or when the source page or any related item has been touched.
- #output_path ⇒ Object
- #tags ⇒ Object
- #title ⇒ Object
- #url ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(source_page, site, related_items) ⇒ RelatedIndexPage
Returns a new instance of RelatedIndexPage.
18 19 20 21 22 |
# File 'lib/abqari/related_index_page.rb', line 18 def initialize(source_page, site, ) @source_page = source_page @site = site @related_items = end |
Instance Attribute Details
#related_items ⇒ Object (readonly)
Returns the value of attribute related_items.
16 17 18 |
# File 'lib/abqari/related_index_page.rb', line 16 def @related_items end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
16 17 18 |
# File 'lib/abqari/related_index_page.rb', line 16 def site @site end |
#source_page ⇒ Object (readonly)
Returns the value of attribute source_page.
16 17 18 |
# File 'lib/abqari/related_index_page.rb', line 16 def source_page @source_page end |
Instance Method Details
#bundle_images ⇒ Object
56 57 58 |
# File 'lib/abqari/related_index_page.rb', line 56 def bundle_images [] end |
#content ⇒ Object
32 33 34 |
# File 'lib/abqari/related_index_page.rb', line 32 def content '' end |
#description ⇒ Object
28 29 30 |
# File 'lib/abqari/related_index_page.rb', line 28 def description "All items related to '#{@source_page.title}' — ranked by tag, series, and category overlap." end |
#frontmatter ⇒ Object
36 37 38 |
# File 'lib/abqari/related_index_page.rb', line 36 def frontmatter {} end |
#lastmod ⇒ Object
52 53 54 |
# File 'lib/abqari/related_index_page.rb', line 52 def lastmod @related_items.map(&:lastmod).compact.max || @source_page.lastmod end |
#needs_render? ⇒ Boolean
Re-render when shared deps change or when the source page or any related item has been touched. Conservatively: always re-render when shared deps change — the related list could shift if any post in the collection changed its tags/series.
64 65 66 |
# File 'lib/abqari/related_index_page.rb', line 64 def needs_render? true end |
#output_path ⇒ Object
48 49 50 |
# File 'lib/abqari/related_index_page.rb', line 48 def output_path File.join(@site.output_dir, url.sub(%r{\A/}, '').chomp('/'), 'index.html') end |
#tags ⇒ Object
40 41 42 |
# File 'lib/abqari/related_index_page.rb', line 40 def [] end |
#title ⇒ Object
24 25 26 |
# File 'lib/abqari/related_index_page.rb', line 24 def title "Related to #{@source_page.title}" end |
#url ⇒ Object
44 45 46 |
# File 'lib/abqari/related_index_page.rb', line 44 def url "#{@source_page.url.chomp('/')}/related/" end |
#write ⇒ Object
68 69 70 71 |
# File 'lib/abqari/related_index_page.rb', line 68 def write FileUtils.mkdir_p(File.dirname(output_path)) File.write(output_path, @site.post_process(render, page: self)) end |