Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 5df1a6f

Browse files
committed
Add last_modified_at to MRG generator and align with other hooks
1 parent 9b02406 commit 5df1a6f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

_plugins/generators/mrg_pages.rb

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def generate(site)
4949
)
5050
mrg_topic.content = metadata['content']
5151
mrg_topic.data['title'] = metadata['title']
52+
mrg_topic.data['last_modified_at'] = metadata['last_modified_at']
5253
mrg_topic.process("#{mod}.md")
5354

5455
# Add the newly constructed page object to the rest of pages

_plugins/page-params/github-path.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
# The parameter contains a file path relative to its repository.
88
#
99
Jekyll::Hooks.register :pages, :post_init do |page|
10+
11+
# Skip virtual pages like MRG topics
12+
next if page.kind_of? Jekyll::PageWithoutAFile
1013
# Process only files with 'md' and 'html' extensions
1114
next unless File.extname(page.path).match?(/md|html/)
12-
# Do nothing for redirects
15+
# Skip redirects
1316
next if page.name == 'redirect.html'
1417

1518
dir = File.dirname page.path

_plugins/page-params/last-modified-at.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#
44
# This custom plugin dynamically sets the 'last_modified_at' parameter
55
# for each page except 'redirect.html' pages.
6-
# A value of the pararmeter is available as {{ page.last_modified_at }}.
6+
# A value of the parameter is available as {{ page.last_modified_at }}.
77
# The parameter contains date and time of the last commit that changed
88
# the original file.
99
# For available date formats, refer to https://git-scm.com/docs/git-log#git-log---dateltformatgt
1010
#
11-
Jekyll::Hooks.register :pages, :post_init do |page|
11+
Jekyll::Hooks.register :pages, :pre_render do |page|
1212
# Do nothing in serving mode
1313
next if page.site.config['serving']
1414
# Do nothing if the date is already set
@@ -23,7 +23,7 @@
2323
dir = File.dirname real_filepath
2424
filename = File.basename real_filepath
2525

26-
# Read date of the last committ and assign it to last_modified_at parameter
26+
# Read date of the last commit and assign it to last_modified_at parameter
2727
# of the page.
2828
page.data['last_modified_at'] =
2929
`cd #{dir} && git log -1 --format=%cd --date=iso -- #{filename}`.strip

0 commit comments

Comments
 (0)