Class: Abqari::PaginatedShard

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#paginatorObject (readonly)

Returns the value of attribute paginator.



7
8
9
# File 'lib/abqari/paginated_shard.rb', line 7

def paginator
  @paginator
end

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



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

def bundle_images
  []
end

#contentObject



23
24
25
# File 'lib/abqari/paginated_shard.rb', line 23

def content
  @source.content
end

#dateObject



39
40
41
# File 'lib/abqari/paginated_shard.rb', line 39

def date
  nil
end

#descriptionObject



19
20
21
# File 'lib/abqari/paginated_shard.rb', line 19

def description
  @source.description
end

#frontmatterObject



27
28
29
# File 'lib/abqari/paginated_shard.rb', line 27

def frontmatter
  @source.frontmatter
end

#lastmodObject

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_nameObject

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

Returns:

  • (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_pathObject



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

Returns:

  • (Boolean)


35
36
37
# File 'lib/abqari/paginated_shard.rb', line 35

def post?
  false
end

#tagsObject



31
32
33
# File 'lib/abqari/paginated_shard.rb', line 31

def tags
  []
end

#titleObject



15
16
17
# File 'lib/abqari/paginated_shard.rb', line 15

def title
  "#{@source.title} · Page #{@paginator.page}"
end

#urlObject



43
44
45
# File 'lib/abqari/paginated_shard.rb', line 43

def url
  "#{absolute_base}page/#{@paginator.page}/"
end

#writeObject



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