From 7e21d2a98f608e1caaed18402e6305c259510128 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Tue, 1 Mar 2016 15:51:17 -0500 Subject: [PATCH] add content_for method --- Rakefile | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 6b70c955..aee5747e 100644 --- a/Rakefile +++ b/Rakefile @@ -89,22 +89,29 @@ 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] - output_file = file.sub(/\.markdown\z/, ".md").downcase - slug = File.basename(output_file, ".md") + 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({ "title" => title, "layout" => "docs", "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