Skip to content

Instantly share code, notes, and snippets.

@ls-lukebowerman
Created September 8, 2012 17:24
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ls-lukebowerman/3677503 to your computer and use it in GitHub Desktop.
Save ls-lukebowerman/3677503 to your computer and use it in GitHub Desktop.
IndexTank/JSON Sitemap Generator for Middleman
<%
entries = []
pages = sitemap.resources
pages = pages.find_all{|p| p.source_file.match(/\.html/) && !p.directory_index? && p.data.hide_listing != true }
pages.each do |article|
file = File.open(article.source_file,'r')
file_contents = file.read.split('---').last.gsub(/\t|\n/,' ')
content = Nokogiri::HTML(file_contents).xpath("//text()").to_s
revision_date = article.data.revisions ? article.data.revisions.collect{|r,d| r}.max : nil
entry = {
:title => article.data.title,
:timestamp => revision_date,
:description => article.data.description,
:url => article.destination_path.gsub(/help\/|\/index\.html/,''),
:content => content
}
entries << entry
end
%><%=entries.to_json %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment