add content_for method

This commit is contained in:
Ben Balter 2016-03-01 15:51:17 -05:00
parent c6790bd8c9
commit 7e21d2a98f
1 changed files with 14 additions and 7 deletions

View File

@ -89,22 +89,29 @@ end
def siteify_file(file, front_matter = {}) def siteify_file(file, front_matter = {})
abort "You seem to have misplaced your #{file} file. I can haz?" unless File.exists?(file) abort "You seem to have misplaced your #{file} file. I can haz?" unless File.exists?(file)
contents = File.read(file) title = File.read(file).match(/\A# (.*)$/)[1]
title = contents.match(/\A# (.*)$/)[1] output_file = file.sub(/\.markdown\z/, ".md").downcase
output_file = file.sub(/\.markdown\z/, ".md").downcase slug = File.basename(output_file, ".md")
slug = File.basename(output_file, ".md")
front_matter = front_matter.merge({ front_matter = front_matter.merge({
"title" => title, "title" => title,
"layout" => "docs", "layout" => "docs",
"permalink" => "/docs/#{slug}/", "permalink" => "/docs/#{slug}/",
"note" => "This file is autogenerated. Edit /#{file} instead." "note" => "This file is autogenerated. Edit /#{file} instead."
}) })
contents.gsub!(/\A# #{title}\n\n?/, "") contents = "#{front_matter.to_yaml}---\n\n#{content_for(file)}"
contents = converted_history(contents) if output_file == "history.md"
contents = "#{front_matter.to_yaml}---\n\n#{contents}"
File.write("site/_docs/#{output_file}", contents) File.write("site/_docs/#{output_file}", contents)
end end
def content_for(file)
contents = File.read(file)
case file
when "HISTORY.markdown"
converted_history(contents)
else
contents.gsub!(/\A# .*\n\n?/, "")
end
end
############################################################################# #############################################################################
# #
# Standard tasks # Standard tasks