Skip to content

Commit

Permalink
Add the ability to render the date of the post
Browse files Browse the repository at this point in the history
  • Loading branch information
danott committed Jan 14, 2024
1 parent 6c0949f commit 6ccd3ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/build_data.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
class BuildData
attr_reader :targets
attr_reader :current_page

def initialize(targets)
def initialize(targets, current_page = nil)
@targets = targets
@current_page = current_page
end

def for_current_page(next_current_page)
self.class.new(targets, next_current_page)
end

def all
Expand Down
2 changes: 1 addition & 1 deletion lib/html_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def hydrate
MagicCommentHydrator.new(
content: content,
includables: Build.includables,
data: Build.data
data: Build.data.for_current_page(data)
)
self.class.new(content: hydrator.hydrate.content, path: path, data: data)
end
Expand Down
11 changes: 10 additions & 1 deletion lib/includable/post_footer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
module Includable
class PostFooter
attr_reader :data

def initialize(string:, data:)
@data = data
end

def render
ERB.new(template).result_with_hash(date: data.current_page.fetch("date"))
end

def template
<<~HTML
<a href="/">← Home</a>
<hr />
<p>Published: <%= date %></p>
<p><a href="/">← Home</a></p>
HTML
end
end
Expand Down

0 comments on commit 6ccd3ca

Please sign in to comment.