Class: Abqari::PaginatedShard
- Inherits:
-
Object
- Object
- Abqari::PaginatedShard
- Defined in:
- lib/abqari/paginated_shard.rb
Instance Attribute Summary collapse
-
#paginator ⇒ Object
readonly
Returns the value of attribute paginator.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #bundle_images ⇒ Object
- #content ⇒ Object
- #date ⇒ Object
- #description ⇒ Object
- #frontmatter ⇒ Object
-
#initialize(source_page, paginator) ⇒ PaginatedShard
constructor
A new instance of PaginatedShard.
-
#lastmod ⇒ Object
Reflect the latest update across the posts this page lists.
-
#layout_name ⇒ Object
Incremental rendering — re-render when shared deps change or any post on this shard was modified more recently than the output.
- #needs_render? ⇒ Boolean
- #output_path ⇒ Object
- #post? ⇒ Boolean
- #tags ⇒ Object
- #title ⇒ Object
- #url ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(source_page, paginator) ⇒ PaginatedShard
Returns a new instance of PaginatedShard.
9 10 11 12 13 |
# File 'lib/abqari/paginated_shard.rb', line 9 def initialize(source_page, paginator) @source = source_page @paginator = paginator @site = source_page.site end |
Instance Attribute Details
#paginator ⇒ Object (readonly)
Returns the value of attribute paginator.
7 8 9 |
# File 'lib/abqari/paginated_shard.rb', line 7 def paginator @paginator end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
7 8 9 |
# File 'lib/abqari/paginated_shard.rb', line 7 def site @site end |
Instance Method Details
#bundle_images ⇒ Object
56 57 58 |
# File 'lib/abqari/paginated_shard.rb', line 56 def bundle_images [] end |
#content ⇒ Object
23 24 25 |
# File 'lib/abqari/paginated_shard.rb', line 23 def content @source.content end |
#date ⇒ Object
39 40 41 |
# File 'lib/abqari/paginated_shard.rb', line 39 def date nil end |
#description ⇒ Object
19 20 21 |
# File 'lib/abqari/paginated_shard.rb', line 19 def description @source.description end |
#frontmatter ⇒ Object
27 28 29 |
# File 'lib/abqari/paginated_shard.rb', line 27 def frontmatter @source.frontmatter end |
#lastmod ⇒ Object
Reflect the latest update across the posts this page lists.
52 53 54 |
# File 'lib/abqari/paginated_shard.rb', line 52 def lastmod @paginator.posts.map(&:lastmod).compact.max end |
#layout_name ⇒ Object
Incremental rendering — re-render when shared deps change or any post
on this shard was modified more recently than the output.
Mirror the source page's layout resolution — layout_name falls
back to the collection's default layout before application, so
shards render through the same layout as page 1. Shared by
render and needs_render? so the staleness check can't drift
from what's actually rendered.
67 68 69 70 71 72 73 |
# File 'lib/abqari/paginated_shard.rb', line 67 def layout_name if @source.respond_to?(:layout_name) @source.layout_name else @source.frontmatter['layout'] || 'application' end end |
#needs_render? ⇒ Boolean
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/abqari/paginated_shard.rb', line 75 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, and # only Page consulted them — so editing an archive layout left # every shard stale on the dev server. return true if @site.layout_deps_mtime(layout_name) > output_mtime @paginator.posts.any? { |post| (post.lastmod || Time.now) > output_mtime } end |
#output_path ⇒ Object
47 48 49 |
# File 'lib/abqari/paginated_shard.rb', line 47 def output_path File.join(@site.output_dir, relative_base, 'page', @paginator.page.to_s, 'index.html') end |
#post? ⇒ Boolean
35 36 37 |
# File 'lib/abqari/paginated_shard.rb', line 35 def post? false end |
#tags ⇒ Object
31 32 33 |
# File 'lib/abqari/paginated_shard.rb', line 31 def [] end |
#title ⇒ Object
15 16 17 |
# File 'lib/abqari/paginated_shard.rb', line 15 def title "#{@source.title} · Page #{@paginator.page}" end |
#url ⇒ Object
43 44 45 |
# File 'lib/abqari/paginated_shard.rb', line 43 def url "#{absolute_base}page/#{@paginator.page}/" end |
#write ⇒ Object
88 89 90 91 |
# File 'lib/abqari/paginated_shard.rb', line 88 def write FileUtils.mkdir_p(File.dirname(output_path)) File.write(output_path, @site.post_process(render, page: self)) end |