Skip to content

Instantly share code, notes, and snippets.

@miyohide
Created May 31, 2020 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyohide/7d1c95d592cb392476e60a835c1f92b6 to your computer and use it in GitHub Desktop.
Save miyohide/7d1c95d592cb392476e60a835c1f92b6 to your computer and use it in GitHub Desktop.
create Atom feed for middleman
---
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