Class: Abqari::RelatedIndexPage

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, related_items)
  @source_page = source_page
  @site = site
  @related_items = related_items
end

Instance Attribute Details

Returns the value of attribute related_items.



16
17
18
# File 'lib/abqari/related_index_page.rb', line 16

def related_items
  @related_items
end

#siteObject (readonly)

Returns the value of attribute site.



16
17
18
# File 'lib/abqari/related_index_page.rb', line 16

def site
  @site
end

#source_pageObject (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_imagesObject



56
57
58
# File 'lib/abqari/related_index_page.rb', line 56

def bundle_images
  []
end

#contentObject



32
33
34
# File 'lib/abqari/related_index_page.rb', line 32

def content
  ''
end

#descriptionObject



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

#frontmatterObject



36
37
38
# File 'lib/abqari/related_index_page.rb', line 36

def frontmatter
  {}
end

#lastmodObject



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.

Returns:

  • (Boolean)


64
65
66
# File 'lib/abqari/related_index_page.rb', line 64

def needs_render?
  true
end

#output_pathObject



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

#tagsObject



40
41
42
# File 'lib/abqari/related_index_page.rb', line 40

def tags
  []
end

#titleObject



24
25
26
# File 'lib/abqari/related_index_page.rb', line 24

def title
  "Related to #{@source_page.title}"
end

#urlObject



44
45
46
# File 'lib/abqari/related_index_page.rb', line 44

def url
  "#{@source_page.url.chomp('/')}/related/"
end

#writeObject



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