Created
May 31, 2020 09:16
-
-
Save miyohide/7d1c95d592cb392476e60a835c1f92b6 to your computer and use it in GitHub Desktop.
create Atom feed for middleman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
layout: false | |
--- | |
require 'open3' | |
xml.instruct! | |
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do | |
xml.title "Sample Site" | |
xml.link "href" => "http://example.com" | |
xml.updated Time.now | |
# gitのコミットの日付で更新日付を設定するようにし、ソートする | |
resources = sitemap.resources.sort_by do |resource| | |
# see. https://git-scm.com/docs/git-log#Documentation/git-log.txt-emcIem | |
o, e, s = Open3.capture3("git log --pretty=format:%cI -n1 #{resource.source_file}") | |
resource.add_metadata({updated: o}) | |
o | |
end.reverse | |
resources.each do |resource| | |
xml.entry do | |
xml.title resource.metadata[:page][:title] | |
xml.link "href" => "http://example.com#{resource.url}" | |
xml.updated resource.metadata[:updated] | |
end if resource.destination_path =~ /\.html$/ | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment