Class: Abqari::PublisherShowPage

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

Overview

Show page for a single externally-sourced publication / bundle / series. Looks like a regular Page to the rest of the engine — same frontmatter, title, description, collection interface — so templates iterate site.collection('publications') (etc.) and don't need to know whether a particular entry came from content/ or an external publisher.

The publisher's payload IS the frontmatter — the canonical schema (docs/publications.md) lines up with what the publisher emits, so no translation layer is needed.

Constant Summary collapse

KIND_TO_COLLECTION =

Map kind: to the collection name site.collection exposes.

{
  'publication' => 'publications',
  'bundle'      => 'bundles',
  'series'      => 'series'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, kind:, slug:, data:, layout:, url:) ⇒ PublisherShowPage

Returns a new instance of PublisherShowPage.



224
225
226
227
228
229
230
231
# File 'lib/abqari/publisher_pages.rb', line 224

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



222
223
224
# File 'lib/abqari/publisher_pages.rb', line 222

def data
  @data
end

#kindObject (readonly)

Returns the value of attribute kind.



222
223
224
# File 'lib/abqari/publisher_pages.rb', line 222

def kind
  @kind
end

#siteObject (readonly)

Returns the value of attribute site.



222
223
224
# File 'lib/abqari/publisher_pages.rb', line 222

def site
  @site
end

#slugObject (readonly)

Returns the value of attribute slug.



222
223
224
# File 'lib/abqari/publisher_pages.rb', line 222

def slug
  @slug
end

Instance Method Details

#bundle_imagesObject



331
332
333
# File 'lib/abqari/publisher_pages.rb', line 331

def bundle_images
  []
end

#collectionObject

Collection membership. Returns 'publications' / 'bundles' / 'series', which lets Site#collection(name) include this page in its iteration alongside manual Pages.



236
237
238
# File 'lib/abqari/publisher_pages.rb', line 236

def collection
  KIND_TO_COLLECTION[@kind.to_s]
end

#contentObject



261
262
263
# File 'lib/abqari/publisher_pages.rb', line 261

def content
  ''
end

#descriptionObject

Page short-summary text — used by sitemap, RSS, OG, JSON-LD. Per docs/publications.md: publications use tagline then excerpt; bundles + series use description. The first line keeps it summary-shaped.



251
252
253
254
255
256
257
258
259
# File 'lib/abqari/publisher_pages.rb', line 251

def description
  raw = case collection
        when 'publications'
          @data['tagline'] || @data['excerpt']
        else
          @data['description']
        end
  raw.to_s.lines.first&.strip
end

#folio_cache_pathObject

On-disk Folio cache backing this page's kind.

Derived from KIND_TO_COLLECTION rather than pluralising kind. "#{kind}s.yml" gets publications and bundles right and produces seriess.yml for series — a file that never exists, so series pages never noticed a stale cache (no re-render when Folio data changed) and fell through to the Time.now lastmod, restamping every series page's sitemap entry on every build. The determinism test couldn't catch it: both builds run on the same day.

The collection names ARE the cache basenames, so reusing the map keeps the two from drifting again.



324
325
326
327
328
329
# File 'lib/abqari/publisher_pages.rb', line 324

def folio_cache_path
  basename = KIND_TO_COLLECTION[@kind.to_s]
  return nil unless basename

  File.join(@site.site_root, 'vendor', 'folio', "#{basename}.yml")
end

#frontmatterObject

The data payload IS the frontmatter. No bookkeeping keys — the canonical schema covers everything templates need to know; templates can't and shouldn't care whether the data came from an external publisher.



269
270
271
# File 'lib/abqari/publisher_pages.rb', line 269

def frontmatter
  @data
end

#lastmodObject



307
308
309
310
# File 'lib/abqari/publisher_pages.rb', line 307

def lastmod
  cache_path = folio_cache_path
  cache_path && File.exist?(cache_path) ? File.mtime(cache_path) : Time.now
end

#layout_nameObject



287
288
289
# File 'lib/abqari/publisher_pages.rb', line 287

def layout_name
  @layout
end

#needs_render?Boolean

Returns:

  • (Boolean)


291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/abqari/publisher_pages.rb', line 291

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

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

  # If the publisher cache is newer than this page's output, re-render —
  # the underlying data may have changed since last build.
  cache_path = folio_cache_path
  cache_path && File.exist?(cache_path) && File.mtime(cache_path) > output_mtime
end

#output_pathObject

See PublisherIndexPage#output_path — same trust boundary, same routing.



278
279
280
# File 'lib/abqari/publisher_pages.rb', line 278

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

#titleObject

Publications use title; bundles + series use name (matches Folio's vocabulary — see docs/publications.md). Falls back to the slug so callers always get a string.



243
244
245
# File 'lib/abqari/publisher_pages.rb', line 243

def title
  @data['title'] || @data['name'] || @slug
end

#urlObject



273
274
275
# File 'lib/abqari/publisher_pages.rb', line 273

def url
  @url
end

#writeObject



282
283
284
285
# File 'lib/abqari/publisher_pages.rb', line 282

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