better file copying

This commit is contained in:
Ben Balter 2016-02-27 14:06:11 -05:00
parent d4cf0dbb0c
commit 2a2326aea3
6 changed files with 36 additions and 33 deletions

View File

@ -1,4 +1,4 @@
# Contributor Code of Conduct # Code of Conduct
As contributors and maintainers of this project, and in the interest of As contributors and maintainers of this project, and in the interest of
fostering an open and welcoming community, we pledge to respect all people who fostering an open and welcoming community, we pledge to respect all people who

View File

@ -1,3 +1,5 @@
# History
## HEAD ## HEAD
### Development Fixes ### Development Fixes

View File

@ -87,6 +87,25 @@ def converted_history(markdown)
normalize_bullets(markdown))))) normalize_bullets(markdown)))))
end 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")
default_frontmatter = {
"title" => title,
"layout" => "docs",
"permalink" => "/docs/#{slug}/",
"note" => "This file is autogenerated. Edit /#{file} instead."
}
front_matter = front_matter.merge(default_frontmatter)
contents.gsub!(/\A# #{title}\n\n?/, "")
contents = converted_history(contents) if output_file == "history.md"
contents = "#{front_matter.to_yaml}---\n\n#{contents}"
File.write("site/_docs/#{output_file}", contents)
end
############################################################################# #############################################################################
# #
# Standard tasks # Standard tasks

View File

@ -5,7 +5,7 @@
############################################################################# #############################################################################
namespace :site do namespace :site do
task :generated_pages => [:history, :version_file, :conduct] task :generated_pages => [:history, :version_file, :conduct, :contributing]
desc "Generate and view the site locally" desc "Generate and view the site locally"
task :preview => :generated_pages do task :preview => :generated_pages do
@ -103,41 +103,21 @@ namespace :site do
desc "Create a nicely formatted history page for the jekyll site based on the repo history." desc "Create a nicely formatted history page for the jekyll site based on the repo history."
task :history do task :history do
if File.exist?("History.markdown") siteify_file('History.markdown')
history_file = File.read("History.markdown")
front_matter = {
"layout" => "docs",
"title" => "History",
"permalink" => "/docs/history/"
}
Dir.chdir('site/_docs/') do
File.open("history.md", "w") do |file|
file.write("#{front_matter.to_yaml}---\n\n")
file.write(converted_history(history_file))
end
end
else
abort "You seem to have misplaced your History.markdown file. I can haz?"
end
end end
desc "Copy the Code of Conduct" desc "Copy the Code of Conduct"
task :conduct do task :conduct do
code_of_conduct = File.read("CONDUCT.markdown")
header, _, body = code_of_conduct.partition("\n\n")
front_matter = { front_matter = {
"layout" => "docs",
"title" => header.sub('# Contributor ', ''),
"permalink" => "/docs/conduct/",
"redirect_from" => "/conduct/index.html", "redirect_from" => "/conduct/index.html",
"editable" => false "editable" => false
} }
Dir.chdir('site/_docs') do siteify_file('CONDUCT.markdown', front_matter)
File.open("conduct.md", "w") do |file| end
file.write("#{front_matter.to_yaml}---\n\n")
file.write(body) desc "Copy the contributing file"
end task :contributing do
end siteify_file('CONTRIBUTING.markdown')
end end
desc "Write the site latest_version.txt file" desc "Write the site latest_version.txt file"

View File

@ -1,9 +1,10 @@
--- ---
layout: docs
title: Code of Conduct
permalink: "/docs/conduct/"
redirect_from: "/conduct/index.html" redirect_from: "/conduct/index.html"
editable: false editable: false
title: Contributor Code of Conduct
layout: docs
permalink: "/docs/conduct/"
note: This file is autogenerated. Edit /CONDUCT.markdown instead.
--- ---
As contributors and maintainers of this project, and in the interest of As contributors and maintainers of this project, and in the interest of

View File

@ -1,7 +1,8 @@
--- ---
layout: docs
title: History title: History
layout: docs
permalink: "/docs/history/" permalink: "/docs/history/"
note: This file is autogenerated. Edit /History.markdown instead.
--- ---
## 3.1.2 / 2016-02-19 ## 3.1.2 / 2016-02-19