Class: Abqari::PublisherIndexPage

Inherits:
Object
  • Object
show all
Defined in:
lib/abqari/publisher_pages.rb

Overview

Index page for a kind (publications / bundles / series). Renders the matching collection-index layout, which iterates the merged site.collection(name) (manual + externally-sourced).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, kind, layout, url) ⇒ PublisherIndexPage

Returns a new instance of PublisherIndexPage.



134
135
136
137
138
139
# File 'lib/abqari/publisher_pages.rb', line 134

def initialize(site, kind, layout, url)
  @site   = site
  @kind   = kind
  @layout = layout
  @url    = url
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



132
133
134
# File 'lib/abqari/publisher_pages.rb', line 132

def kind
  @kind
end

#siteObject (readonly)

Returns the value of attribute site.



132
133
134
# File 'lib/abqari/publisher_pages.rb', line 132

def site
  @site
end

Instance Method Details

#bundle_imagesObject



193
194
195
# File 'lib/abqari/publisher_pages.rb', line 193

def bundle_images
  []
end

#contentObject



149
150
151
# File 'lib/abqari/publisher_pages.rb', line 149

def content
  ''
end

#descriptionObject



145
146
147
# File 'lib/abqari/publisher_pages.rb', line 145

def description
  "All #{@kind}."
end

#frontmatterObject



153
154
155
# File 'lib/abqari/publisher_pages.rb', line 153

def frontmatter
  {}
end

#lastmodObject



189
190
191
# File 'lib/abqari/publisher_pages.rb', line 189

def lastmod
  Time.now
end

#layout_nameObject



174
175
176
# File 'lib/abqari/publisher_pages.rb', line 174

def layout_name
  @layout
end

#needs_render?Boolean

Returns:

  • (Boolean)


178
179
180
181
182
183
184
185
186
187
# File 'lib/abqari/publisher_pages.rb', line 178

def needs_render?
  return true unless File.exist?(output_path)

  output_mtime = File.mtime(output_path)
  return true if output_mtime < @site.shared_deps_mtime
  # Layouts are tracked per-page rather than in GLOBAL_DEP_GLOBS —
  # without this, editing `publications_index.html.erb` left the
  # index stale on the dev server.
  @site.layout_deps_mtime(layout_name) > output_mtime
end

#output_pathObject

Bounded-trust external data per docs/security.md §1. The slug flows into this URL — route through PathSafe so a hostile or accidental "slug": "../../etc" raises a build error instead of writing outside _site/.



165
166
167
# File 'lib/abqari/publisher_pages.rb', line 165

def output_path
  PathSafe.join_under(@site.output_dir, @url.sub(%r{\A/}, '').chomp('/'), 'index.html')
end

#titleObject



141
142
143
# File 'lib/abqari/publisher_pages.rb', line 141

def title
  @kind.capitalize
end

#urlObject



157
158
159
# File 'lib/abqari/publisher_pages.rb', line 157

def url
  @url
end

#writeObject



169
170
171
172
# File 'lib/abqari/publisher_pages.rb', line 169

def write
  FileUtils.mkdir_p(File.dirname(output_path))
  File.write(output_path, @site.post_process(render, page: self))
end