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,8 +89,7 @@ end
def siteify_file(file, front_matter = {})
abort "You seem to have misplaced your #{file} file. I can haz?" unless File.exists?(file)
contents = File.read(file)
title = contents.match(/\A# (.*)$/)[1]
title = File.read(file).match(/\A# (.*)$/)[1]
output_file = file.sub(/\.markdown\z/, ".md").downcase
slug = File.basename(output_file, ".md")
front_matter = front_matter.merge({
@ -99,12 +98,20 @@ def siteify_file(file, front_matter = {})
"permalink" => "/docs/#{slug}/",
"note" => "This file is autogenerated. Edit /#{file} instead."
})
contents.gsub!(/\A# #{title}\n\n?/, "")
contents = converted_history(contents) if output_file == "history.md"
contents = "#{front_matter.to_yaml}---\n\n#{contents}"
contents = "#{front_matter.to_yaml}---\n\n#{content_for(file)}"
File.write("site/_docs/#{output_file}", contents)
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