Merge 2.1 with new-configs

This commit is contained in:
Parker Moore 2013-01-20 23:20:45 -05:00
commit c3479dca4a
24 changed files with 419 additions and 267 deletions

6
.travis.yml Normal file
View File

@ -0,0 +1,6 @@
language: ruby
rvm:
- 1.9.3
- 1.9.2
- 1.8.7
script: bundle exec rake install; bundle exec rake generate

View File

@ -15,6 +15,7 @@ group :development do
gem 'liquid', '~> 2.3.0' gem 'liquid', '~> 2.3.0'
gem 'tzinfo', '~> 0.3.35' gem 'tzinfo', '~> 0.3.35'
gem 'rake-minify' gem 'rake-minify'
gem 'rdiscount', '~> 1.6.8'
end end
gem 'sinatra', '~> 1.3.3' gem 'sinatra', '~> 1.3.3'

View File

@ -37,6 +37,7 @@ GEM
jsmin (~> 1.0.1) jsmin (~> 1.0.1)
rake (>= 0.8.7) rake (>= 0.8.7)
rb-fsevent (0.9.3) rb-fsevent (0.9.3)
rdiscount (1.6.8)
redcarpet (2.2.2) redcarpet (2.2.2)
rubypants (0.2.0) rubypants (0.2.0)
sass (3.2.4) sass (3.2.4)
@ -64,6 +65,7 @@ DEPENDENCIES
rake (~> 10.0.3) rake (~> 10.0.3)
rake-minify rake-minify
rb-fsevent (~> 0.9.3) rb-fsevent (~> 0.9.3)
rdiscount
redcarpet (~> 2.2.2) redcarpet (~> 2.2.2)
rubypants (~> 0.2.0) rubypants (~> 0.2.0)
sinatra (~> 1.3.3) sinatra (~> 1.3.3)

241
Rakefile
View File

@ -1,53 +1,39 @@
require 'rubygems' $:.unshift File.expand_path("lib", File.dirname(__FILE__)) # For use/testing when no gem is installed
require 'bundler/setup'
require 'stringex' require "rubygems"
require "bundler/setup"
require "stringex"
require 'time' require 'time'
require 'tzinfo' require 'tzinfo'
require 'rake/minify' require 'rake/minify'
require 'time' require 'time'
require 'yaml'
require 'octopress'
## -- Rsync Deploy config -- ## ### Configuring Octopress:
# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file ### Under _config/ you will find:
ssh_user = "user@domain.com" ### site.yml, deploy.yml
ssh_port = "22" ### Here you can override Octopress's default configurations or add your own.
ssh_key = "" ### This Rakefile uses those config settings to do what it does.
document_root = "~/website.com/" ### Please do not change anything below if you want help --
rsync_delete = false ### otherwise, you're on your own ;-)
rsync_args = "" # Any extra arguments to pass to rsync
deploy_default = "rsync"
# This will be configured for you when you run config_deploy configuration = Octopress::Configuration.read_configuration
deploy_branch = "gh-pages"
## -- Misc Configs -- ##
public_dir = "public" # compiled site directory
source_dir = "source" # source file directory
blog_index_dir = "source" # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog')
deploy_dir = "_deploy" # deploy directory (for GitHub pages deployment)
stash_dir = "_stash" # directory to stash posts for speedy generation
posts_dir = "_posts" # directory for blog files
themes_dir = ".themes" # directory for blog files
new_post_ext = "markdown" # default new post file extension when using the new_post task
new_page_ext = "markdown" # default new page file extension when using the new_page task
timezone = "local" # default time and date used to local timezone. Timezones (under TZ column): http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
server_host = ENV['OCTOPRESS_IP'] || '0.0.0.0' # host ip address for preview server
server_port = ENV['OCTOPRESS_PORT'] || '4000' # port for preview server eg. localhost:4000
desc "Initial setup for Octopress: copies the default theme into the path of Jekyll's generator. Rake install defaults to rake install[classic] to install a different theme run rake install[some_theme_name]" desc "Initial setup for Octopress: copies the default theme into the path of Jekyll's generator. Rake install defaults to rake install[classic] to install a different theme run rake install[some_theme_name]"
task :install, :theme do |t, args| task :install, :theme do |t, args|
if File.directory?(source_dir) || File.directory?("sass") if File.directory?(configuration[:source]) || File.directory?("sass")
abort("rake aborted!") if ask("A theme is already installed, proceeding will overwrite existing files. Are you sure?", ['y', 'n']) == 'n' abort("rake aborted!") if ask("A theme is already installed, proceeding will overwrite existing files. Are you sure?", ['y', 'n']) == 'n'
end end
# copy theme into working Jekyll directories # copy theme into working Jekyll directories
theme = args.theme || 'classic' theme = args.theme || 'classic'
puts "## Copying "+theme+" theme into ./#{source_dir} and ./sass" puts "## Copying "+theme+" theme into ./#{configuration[:source]} and ./sass"
mkdir_p source_dir mkdir_p configuration[:source]
cp_r "#{themes_dir}/#{theme}/source/.", source_dir cp_r "#{configuration[:themes_dir]}/#{theme}/source/.", configuration[:source]
mkdir_p "sass" mkdir_p "sass"
cp_r "#{themes_dir}/#{theme}/sass/.", "sass" cp_r "#{configuration[:themes_dir]}/#{theme}/sass/.", "sass"
mkdir_p "#{source_dir}/#{posts_dir}" mkdir_p "#{configuration[:source]}/#{configuration[:posts_dir]}"
mkdir_p public_dir mkdir_p configuration[:destination]
end end
####################### #######################
@ -57,19 +43,21 @@ end
desc "Generate jekyll site" desc "Generate jekyll site"
task :generate, :no_future do |t, args| task :generate, :no_future do |t, args|
future = args.no_future future = args.no_future
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(configuration[:source])
Octopress::Configuration.write_configs_for_generation
puts "## Generating Site with Jekyll" puts "## Generating Site with Jekyll"
system "compass compile --css-dir #{source_dir}/stylesheets" system "compass compile --css-dir #{configuration[:source]}/stylesheets"
Rake::Task['minify_and_combine'].execute Rake::Task['minify_and_combine'].execute
system "jekyll --no-server --no-auto #{'--no-future' if future.nil?}" system "jekyll --no-server --no-auto #{'--no-future' if future.nil?}"
unpublished = get_unpublished(Dir.glob("#{source_dir}/#{posts_dir}/*.*"), {no_future: future.nil?, message: "\nThese posts were not generated:"}) unpublished = get_unpublished(Dir.glob("#{configuration[:source]}/#{configuration[:posts_dir]}/*.*"), {no_future: future.nil?, message: "\nThese posts were not generated:"})
puts unpublished unless unpublished.empty? puts unpublished unless unpublished.empty?
Octopress::Configuration.remove_configs_for_generation
end end
Rake::Minify.new(:minify_and_combine) do Rake::Minify.new(:minify_and_combine) do
files = FileList.new("#{source_dir}/javascripts/group/*.*") files = FileList.new("#{configuration[:source]}/javascripts/group/*.*")
output_file = "#{source_dir}/javascripts/octopress.min.js" output_file = "#{configuration[:source]}/javascripts/octopress.min.js"
puts "BEGIN Minifying #{output_file}" puts "BEGIN Minifying #{output_file}"
group(output_file) do group(output_file) do
@ -103,14 +91,16 @@ end
desc "Watch the site and regenerate when it changes" desc "Watch the site and regenerate when it changes"
task :watch, :show_future do |t, args| task :watch, :show_future do |t, args|
future = args.show_future future = args.show_future
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(configuration[:source])
Octopress::Configuration.write_configs_for_generation
puts "Starting to watch source with Jekyll and Compass." puts "Starting to watch source with Jekyll and Compass."
system "compass compile --css-dir #{source_dir}/stylesheets" system "compass compile --css-dir #{configuration[:source]}/stylesheets"
Rake::Task['minify_and_combine'].execute Rake::Task['minify_and_combine'].execute
jekyllPid = Process.spawn("jekyll --auto #{'--no-future' if future.nil?}") jekyllPid = Process.spawn("jekyll --auto #{'--no-future' if future.nil?}")
compassPid = Process.spawn("compass watch") compassPid = Process.spawn("compass watch")
trap("INT") { trap("INT") {
[jekyllPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH } [jekyllPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
Octopress::Configuration.remove_configs_for_generation
exit 0 exit 0
} }
[jekyllPid, compassPid].each { |pid| Process.wait(pid) } [jekyllPid, compassPid].each { |pid| Process.wait(pid) }
@ -119,15 +109,17 @@ end
desc "preview the site in a web browser." desc "preview the site in a web browser."
task :preview, :show_future do |t, args| task :preview, :show_future do |t, args|
future = args.show_future future = args.show_future
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(configuration[:source])
puts "Starting to watch source with Jekyll and Compass. Starting Rack, serving to http://#{server_host}:#{server_port}" Octopress::Configuration.write_configs_for_generation
system "compass compile --css-dir #{source_dir}/stylesheets" puts "Starting to watch source with Jekyll and Compass. Starting Rack, serving to http://#{configuration[:server_host]}:#{configuration[:server_port]}"
system "compass compile --css-dir #{configuration[:source]}/stylesheets"
jekyllPid = Process.spawn("jekyll --auto #{'--no-future' if future.nil?}") jekyllPid = Process.spawn("jekyll --auto #{'--no-future' if future.nil?}")
compassPid = Process.spawn("compass watch") compassPid = Process.spawn("compass watch")
rackupPid = Process.spawn("rackup --host #{server_host} --port #{server_port}") rackupPid = Process.spawn("rackup --host #{configuration[:server_host]} --port #{configuration[:server_port]}")
trap("INT") { trap("INT") {
[jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH } [jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
Octopress::Configuration.remove_configs_for_generation
exit 0 exit 0
} }
@ -135,17 +127,17 @@ task :preview, :show_future do |t, args|
end end
# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post") # usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
desc "Begin a new post in #{source_dir}/#{posts_dir}" desc "Begin a new post in #{configuration[:source]}/#{configuration[:posts_dir]}"
task :new_post, :title do |t, args| task :new_post, :title do |t, args|
if args.title if args.title
title = args.title title = args.title
else else
title = get_stdin("Enter a title for your post: ") title = get_stdin("Enter a title for your post: ")
end end
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(configuration[:source])
time = now_in_timezone(timezone) time = now_in_timezone(timezone)
mkdir_p "#{source_dir}/#{posts_dir}" mkdir_p "#{configuration[:source]}/#{configuration[:posts_dir]}"
filename = "#{source_dir}/#{posts_dir}/#{time.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}" filename = "#{configuration[:source]}/#{configuration[:posts_dir]}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{configuration[:new_post_ext]}"
if File.exist?(filename) if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n' abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end end
@ -163,11 +155,11 @@ task :new_post, :title do |t, args|
end end
# usage rake new_page[my-new-page] or rake new_page[my-new-page.html] or rake new_page (defaults to "new-page.markdown") # usage rake new_page[my-new-page] or rake new_page[my-new-page.html] or rake new_page (defaults to "new-page.markdown")
desc "Create a new page in #{source_dir}/(filename)/index.#{new_page_ext}" desc "Create a new page in #{configuration[:source]}/(filename)/index.#{configuration[:new_page_ext]}"
task :new_page, :filename do |t, args| task :new_page, :filename do |t, args|
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(configuration[:source])
args.with_defaults(:filename => 'new-page') args.with_defaults(:filename => 'new-page')
page_dir = [source_dir] page_dir = [configuration[:source]]
if args.filename.downcase =~ /(^.+\/)?(.+)/ if args.filename.downcase =~ /(^.+\/)?(.+)/
filename, dot, extension = $2.rpartition('.').reject(&:empty?) # Get filename and extension filename, dot, extension = $2.rpartition('.').reject(&:empty?) # Get filename and extension
title = filename title = filename
@ -176,7 +168,7 @@ task :new_page, :filename do |t, args|
page_dir << filename page_dir << filename
filename = "index" filename = "index"
end end
extension ||= new_page_ext extension ||= configuration[:new_page_ext]
page_dir = page_dir.map! { |d| d = d.to_url }.join('/') # Sanitize path page_dir = page_dir.map! { |d| d = d.to_url }.join('/') # Sanitize path
filename = filename.downcase.to_url filename = filename.downcase.to_url
@ -210,22 +202,22 @@ task :isolate, :filename do |t, args|
else else
filename = get_stdin("Enter a post file name: ") filename = get_stdin("Enter a post file name: ")
end end
full_stash_dir = "#{source_dir}/#{stash_dir}" full_configuration[:stash_dir] = "#{configuration[:source]}/#{configuration[:stash_dir]}"
FileUtils.mkdir(full_stash_dir) unless File.exist?(full_stash_dir) FileUtils.mkdir(full_configuration[:stash_dir]) unless File.exist?(full_configuration[:stash_dir])
Dir.glob("#{source_dir}/#{posts_dir}/*.*") do |post| Dir.glob("#{configuration[:source]}/#{configuration[:posts_dir]}/*.*") do |post|
FileUtils.mv post, full_stash_dir unless post.include?(filename) FileUtils.mv post, full_configuration[:stash_dir] unless post.include?(filename)
end end
end end
desc "Move all stashed posts back into the posts directory, ready for site generation." desc "Move all stashed posts back into the posts directory, ready for site generation."
task :integrate do task :integrate do
FileUtils.mv Dir.glob("#{source_dir}/#{stash_dir}/*.*"), "#{source_dir}/#{posts_dir}/" FileUtils.mv Dir.glob("#{configuration[:source]}/#{configuration[:stash_dir]}/*.*"), "#{configuration[:source]}/#{configuration[:posts_dir]}/"
end end
desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache" desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache"
task :clean do task :clean do
[".pygments-cache/**", ".gist-cache/**"].each { |dir| rm_rf Dir.glob(dir) } [".pygments-cache/**", ".gist-cache/**"].each { |dir| rm_rf Dir.glob(dir) }
rm "#{source_dir}/stylesheets/screen.css" if File.exists?("#{source_dir}/stylesheets/screen.css") rm "#{configuration[:source]}/stylesheets/screen.css" if File.exists?("#{configuration[:source]}/stylesheets/screen.css")
system "compass clean" system "compass clean"
puts "## Cleaned Sass, Pygments and Gist caches, removed generated stylesheets ##" puts "## Cleaned Sass, Pygments and Gist caches, removed generated stylesheets ##"
end end
@ -246,7 +238,7 @@ task :update_style, :theme do |t, args|
end end
mv "sass", "sass.old" mv "sass", "sass.old"
puts "## Moved styles into sass.old/" puts "## Moved styles into sass.old/"
cp_r "#{themes_dir}/"+theme+"/sass/", "sass" cp_r "#{configuration[:themes_dir]}/"+theme+"/sass/", "sass"
cp_r "sass.old/custom/.", "sass/custom" cp_r "sass.old/custom/.", "sass/custom"
puts "## Updated Sass ##" puts "## Updated Sass ##"
rm_r ".sass-cache", :secure=>true if File.directory?(".sass-cache") rm_r ".sass-cache", :secure=>true if File.directory?(".sass-cache")
@ -255,29 +247,29 @@ end
desc "Move source to source.old, install source theme updates, replace source/_includes/navigation.html with source.old's navigation" desc "Move source to source.old, install source theme updates, replace source/_includes/navigation.html with source.old's navigation"
task :update_source, :theme do |t, args| task :update_source, :theme do |t, args|
theme = args.theme || 'classic' theme = args.theme || 'classic'
if File.directory?("#{source_dir}.old") if File.directory?("#{configuration[:source]}.old")
puts "## Removed existing #{source_dir}.old directory" puts "## Removed existing #{configuration[:source]}.old directory"
rm_r "#{source_dir}.old", :secure=>true rm_r "#{configuration[:source]}.old", :secure=>true
end end
mkdir "#{source_dir}.old" mkdir "#{configuration[:source]}.old"
cp_r "#{source_dir}/.", "#{source_dir}.old" cp_r "#{configuration[:source]}/.", "#{configuration[:source]}.old"
puts "## Copied #{source_dir} into #{source_dir}.old/" puts "## Copied #{configuration[:source]} into #{configuration[:source]}.old/"
cp_r "#{themes_dir}/"+theme+"/source/.", source_dir, :remove_destination=>true cp_r "#{configuration[:themes_dir]}/"+theme+"/source/.", configuration[:source], :remove_destination=>true
cp_r "#{source_dir}.old/_includes/custom/.", "#{source_dir}/_includes/custom/", :remove_destination=>true cp_r "#{configuration[:source]}.old/_includes/custom/.", "#{configuration[:source]}/_includes/custom/", :remove_destination=>true
mv "#{source_dir}/index.html", "#{blog_index_dir}", :force=>true if blog_index_dir != source_dir mv "#{configuration[:source]}/index.html", "#{configuration[:blog_index_dir]}", :force=>true if configuration[:blog_index_dir] != configuration[:source]
cp "#{source_dir}.old/index.html", source_dir if blog_index_dir != source_dir && File.exists?("#{source_dir}.old/index.html") cp "#{configuration[:source]}.old/index.html", configuration[:source] if configuration[:blog_index_dir] != configuration[:source] && File.exists?("#{configuration[:source]}.old/index.html")
if File.exists?("#{source_dir}/blog/archives/index.html") if File.exists?("#{configuration[:source]}/blog/archives/index.html")
puts "## Moving blog/archives to /archives (standard location as of 2.1) ##" puts "## Moving blog/archives to /archives (standard location as of 2.1) ##"
file = "#{source_dir}/_includes/custom/navigation.html" file = "#{configuration[:source]}/_includes/custom/navigation.html"
navigation = IO.read(file) navigation = IO.read(file)
navigation = navigation.gsub(/(.*)\/blog(\/archives)(.*$)/m, '\1\2\3') navigation = navigation.gsub(/(.*)\/blog(\/archives)(.*$)/m, '\1\2\3')
File.open(file, 'w') do |f| File.open(file, 'w') do |f|
f.write navigation f.write navigation
end end
rm_r "#{source_dir}/blog/archives" rm_r "#{configuration[:source]}/blog/archives"
rm_r "#{source_dir}/blog" if Dir.entries("#{source_dir}/blog").join == "..." rm_r "#{configuration[:source]}/blog" if Dir.entries("#{configuration[:source]}/blog").join == "..."
end end
puts "## Updated #{source_dir} ##" puts "## Updated #{configuration[:source]} ##"
end end
############## ##############
@ -286,7 +278,7 @@ end
desc "Default deploy task" desc "Default deploy task"
task :deploy do task :deploy do
Rake::Task["#{deploy_default}"].execute Rake::Task["#{configuration[:deploy_default]}"].execute
end end
desc "Generate website and deploy" desc "Generate website and deploy"
@ -300,29 +292,29 @@ task :rsync do
exclude = "--exclude-from '#{File.expand_path('./rsync-exclude')}'" exclude = "--exclude-from '#{File.expand_path('./rsync-exclude')}'"
end end
puts "## Deploying website via Rsync" puts "## Deploying website via Rsync"
ok_failed system("rsync -avze 'ssh -p #{ssh_port} #{'-i' + ssh_key unless ssh_key.empty?}' #{exclude} #{rsync_args} #{"--delete" unless rsync_delete == false} #{public_dir}/ #{ssh_user}:#{document_root}") ok_failed system("rsync -avze 'ssh -p #{configuration[:ssh_port]} #{'-i' + configuration[:ssh_key] unless configuration[:ssh_key].empty?}' #{exclude} #{configuration[:rsync_args]} #{"--delete" unless configuration[:rsync_delete] == false} #{configuration[:destination]}/ #{configuration[:ssh_user]}:#{configuration[:document_root]}")
end end
desc "deploy public directory to github pages" desc "deploy public directory to github pages"
multitask :push do multitask :push do
if File.directory?(deploy_dir) if File.directory?(configuration[:deploy_dir])
puts "## Deploying branch to GitHub Pages " puts "## Deploying branch to GitHub Pages "
(Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) } (Dir["#{configuration[:deploy_dir]}/*"]).each { |f| rm_rf(f) }
puts "Attempting pull, to sync local deployment repository" puts "Attempting pull, to sync local deployment repository"
cd "#{deploy_dir}" do cd "#{configuration[:deploy_dir]}" do
system "git pull origin #{deploy_branch}" system "git pull origin #{configuration[:deploy_branch]}"
end end
puts "\n## copying #{public_dir} to #{deploy_dir}" puts "\n## copying #{configuration[:destination]} to #{configuration[:deploy_dir]}"
cp_r "#{public_dir}/.", deploy_dir cp_r "#{configuration[:destination]}/.", configuration[:deploy_dir]
cd "#{deploy_dir}" do cd "#{configuration[:deploy_dir]}" do
File.new(".nojekyll", "w").close File.new(".nojekyll", "w").close
system "git add ." system "git add ."
system "git add -u" system "git add -u"
message = "Site updated at #{Time.now.utc}" message = "Site updated at #{Time.now.utc}"
puts "\n## Commiting: #{message}" puts "\n## Commiting: #{message}"
system "git commit -m \"#{message}\"" system "git commit -m \"#{message}\""
puts "\n## Pushing generated #{deploy_dir} website" puts "\n## Pushing generated #{configuration[:deploy_dir]} website"
if system "git push origin #{deploy_branch}" if system "git push origin #{configuration[:deploy_branch]}"
puts "\n## GitHub Pages deploy complete" puts "\n## GitHub Pages deploy complete"
else else
remote = `git remote -v` remote = `git remote -v`
@ -355,28 +347,15 @@ task :set_root_dir, :dir do |t, args|
else else
dir = "/" + args.dir.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, ''); dir = "/" + args.dir.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, '');
end end
rakefile = IO.read(__FILE__) # update personal configuration
rakefile.sub!(/public_dir(\s*)=(\s*)(["'])[\w\-\/]*["']/, "public_dir\\1=\\2\\3public#{dir}\\3") site_configs = Octopress::Configuration.read_config('site.yml')
File.open(__FILE__, 'w') do |f| site_configs[:destination] = "public#{dir}"
f.write rakefile site_configs[:subscribe_rss] = "#{dir}/atom.xml"
end site_configs[:root] = "/#{dir.sub(/^\//, '')}"
compass_config = IO.read('config.rb') Octopress::Configuration.write_config('site.yml', site_configs)
compass_config.sub!(/http_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_path\\1=\\2\\3#{dir}/\\3")
compass_config.sub!(/http_images_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_images_path\\1=\\2\\3#{dir}/images\\3") rm_rf configuration[:destination]
compass_config.sub!(/http_fonts_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_fonts_path\\1=\\2\\3#{dir}/fonts\\3") mkdir_p site_configs[:destination]
compass_config.sub!(/css_dir(\s*)=(\s*)(["'])[\w\-\/]*["']/, "css_dir\\1=\\2\\3public#{dir}/stylesheets\\3")
File.open('config.rb', 'w') do |f|
f.write compass_config
end
jekyll_config = IO.read('_config.yml')
jekyll_config.sub!(/^destination:.+$/, "destination: public#{dir}")
jekyll_config.sub!(/^subscribe_rss:\s*\/.+$/, "subscribe_rss: #{dir}/atom.xml")
jekyll_config.sub!(/^root:.*$/, "root: /#{dir.sub(/^\//, '')}")
File.open('_config.yml', 'w') do |f|
f.write jekyll_config
end
rm_rf public_dir
mkdir_p "#{public_dir}#{dir}"
puts "\n========================================================" puts "\n========================================================"
puts "Site's root directory is now '/#{dir.sub(/^\//, '')}'" puts "Site's root directory is now '/#{dir.sub(/^\//, '')}'"
puts "Don't forget to update your url in _config.yml" puts "Don't forget to update your url in _config.yml"
@ -414,16 +393,16 @@ task :setup_github_pages, :repo do |t, args|
system "git branch -m master source" system "git branch -m master source"
puts "Master branch renamed to 'source' for committing your blog source files" puts "Master branch renamed to 'source' for committing your blog source files"
else else
unless !public_dir.match("#{project}").nil? unless !configuration[:destination].match("#{project}").nil?
Rake::Task[:set_root_dir].invoke(project) Rake::Task[:set_root_dir].invoke(project)
end end
end end
end end
# Configure deployment repository # Configure deployment repository
rm_rf deploy_dir rm_rf configuration[:deploy_dir]
mkdir deploy_dir mkdir configuration[:deploy_dir]
cd "#{deploy_dir}" do cd "#{configuration[:deploy_dir]}" do
system "git init" system "git init"
system "git remote add origin #{repo_url}" system "git remote add origin #{repo_url}"
puts "Attempting to pull from repository" puts "Attempting to pull from repository"
@ -436,29 +415,23 @@ task :setup_github_pages, :repo do |t, args|
end end
end end
# Configure deployment setup in Rakefile # Configure deployment setup in deploy.yml
rakefile = IO.read(__FILE__) deploy_configuration = Octopress::Configuration.read_config('deploy.yml')
rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{branch}\\3") deploy_configuration[:deploy_default] = "push"
rakefile.sub!(/deploy_default(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_default\\1=\\2\\3push\\3") deploy_configuration[:deploy_branch] = branch
File.open(__FILE__, 'w') do |f| deploy_configuration = Octopress::Configuration.read_config('defaults/deploy/gh_pages.yml').deep_merge(deploy_configuration)
f.write rakefile puts deploy_configuration
end Octopress::Configuration.write_config('deploy.yml', deploy_configuration)
# Configure published url # Configure published url
jekyll_config = IO.read('_config.yml') site_configuration = Octopress::Configuration.read_config('site.yml')
current_url = /^url:\s?(.*$)/.match(jekyll_config)[1] site_configuration[:url] = url if site_configuration.has_key?(:url) && site_configuration[:url] == 'http://yoursite.com'
has_cname = File.exists?("#{source_dir}/CNAME") site_configuration = Octopress::Configuration.read_config('defaults/jekyll.yml').deep_merge(site_configuration)
if current_url == 'http://yoursite.com'
jekyll_config.sub!(/^url:.*$/, "url: #{url}")
File.open('_config.yml', 'w') do |f|
f.write jekyll_config
end
current_url = url
end
puts "\n========================================================" puts "\n========================================================"
has_cname = File.exists?("#{configuration[:source]}/CNAME")
if has_cname if has_cname
cname = IO.read("#{source_dir}/CNAME").chomp cname = IO.read("#{configuration[:source]}/CNAME").chomp
current_short_url = /\/{2}(.*$)/.match(current_url)[1] current_short_url = /\/{2}(.*$)/.match(current_url)[1]
if cname != current_short_url if cname != current_short_url
puts "!! WARNING: Your CNAME points to #{cname} but your _config.yml url is set to #{current_short_url} !!" puts "!! WARNING: Your CNAME points to #{cname} but your _config.yml url is set to #{current_short_url} !!"
@ -468,7 +441,7 @@ task :setup_github_pages, :repo do |t, args|
end end
else else
puts "GitHub Pages will host your site at #{url}." puts "GitHub Pages will host your site at #{url}."
puts "To host at \"your-site.com\", configure a CNAME: `echo \"your-domain.com\" > #{source_dir}/CNAME`" puts "To host at \"your-site.com\", configure a CNAME: `echo \"your-domain.com\" > #{configuration[:source]}/CNAME`"
puts "Then change the url in _config.yml from #{current_url} to http://your-domain.com" puts "Then change the url in _config.yml from #{current_url} to http://your-domain.com"
puts "Finally, follow the guide at http://help.github.com/pages/#custom_domains for help pointing your domain to GitHub Pages" puts "Finally, follow the guide at http://help.github.com/pages/#custom_domains for help pointing your domain to GitHub Pages"
end end
@ -481,7 +454,7 @@ end
# usage rake list_posts or rake list_posts[pub|unpub] # usage rake list_posts or rake list_posts[pub|unpub]
desc "List all unpublished/draft posts" desc "List all unpublished/draft posts"
task :list_drafts do task :list_drafts do
posts = Dir.glob("#{source_dir}/#{posts_dir}/*.*") posts = Dir.glob("#{configuration[:source]}/#{configuration[:posts_dir]}/*.*")
unpublished = get_unpublished(posts) unpublished = get_unpublished(posts)
puts unpublished.empty? ? "There are no posts currently in draft" : unpublished puts unpublished.empty? ? "There are no posts currently in draft" : unpublished
end end

View File

@ -1,122 +0,0 @@
# ----------------------- #
# Main Configs #
# ----------------------- #
url: http://yoursite.com
title: My Octopress Blog
subtitle: A blogging framework for hackers.
author: Your Name
simple_search: http://google.com/search
description:
# Default date format is "ordinal" (resulting in "July 22nd 2007")
# You can customize the format as defined in
# http://www.ruby-doc.org/core-1.9.2/Time.html#method-i-strftime
# Additionally, %o will give you the ordinal representation of the day
date_format: "ordinal"
# RSS / Email (optional) subscription links (change if using something like Feedburner)
subscribe_rss: /atom.xml
subscribe_email:
category_feeds: false
# RSS feeds can list your email address if you like
email:
# ----------------------- #
# Jekyll & Plugins #
# ----------------------- #
# If publishing to a subdirectory as in http://site.com/project set 'root: /project'
root: /
permalink: /:year/:month/:day/:title/
source: source
destination: public
plugins: plugins
code_dir: downloads/code
category_dir: blog/categories
include:
- .htaccess
markdown: redcarpet
redcarpet:
extensions:
- no_intra_emphasis
- strikethrough
- autolink
- superscript
- smart
pygments: false # Jekyll's default Python Pygments have been replaced by pygments.rb. Set to true to use Albino + Pythong Pygments
paginate: 10 # Posts per page on the blog index
pagination_dir: blog # Directory base for pagination URLs eg. /blog/page/2/
recent_posts: 5 # Posts in the sidebar Recent Posts section
excerpt_link: "Read on &rarr;" # "Continue reading" link text at the bottom of excerpted articles
excerpt_in_feed: false # Truncate excerpted articles in the atom feed
permalink_label: "Permalink"
permalink_label_feed: "&#9875; Permalink"
linklog_marker: "&rarr;"
linklog_marker_position: after
linklog_marker_position_feed: after
standard_post_marker:
titlecase: true # Converts page and post titles to titlecase
# To change the layout's default sidebar Add a new sidebar source/_includes/sidebars/your_sidebar.html
# then make changes below, eg. post_sidebar: your_sidebar.html
blog_index_sidebar: blog_index_default.html
page_sidebar: page_default.html
post_sidebar: post_default.html
# ----------------------- #
# 3rd Party Settings #
# ----------------------- #
# Javascript social buttons often generate lots of http requests and may track your viewer's browsing history
# Show respect for privacy and bandwidth with simple links for Twitter, Facebook and Google Plus.
respectfully_social: true
# Github repositories
github_user:
github_repo_count: 0
github_show_profile_link: true
github_skip_forks: true
# Twitter
twitter_user:
twitter_tweet_count: 4
twitter_show_replies: false
twitter_follow_button: true
twitter_show_follower_count: false
twitter_tweet_button: true
# Google +1
google_plus_one: false
google_plus_one_size: medium
# Google Plus Profile
# Hidden: No visible button, just add author information to search results
google_plus_user:
google_plus_hidden: false
google_plus_image_size: 32
# Pinboard
pinboard_user:
pinboard_count: 3
# Delicious
delicious_user:
delicious_count: 3
# Disqus Comments
disqus_short_name:
disqus_show_comment_count: false
disqus_developer: 0
# Google Analytics
google_analytics_tracking_id:
# Gaug.es Analytics
gauges_analytics_tracking_id:
# Facebook Like
facebook_like: false

View File

@ -0,0 +1,39 @@
---
# ------------------------------- #
# Classic Theme Configuration #
# ------------------------------- #
url: http://yoursite.com
title: My Octopress Blog
subtitle: A blogging framework for hackers.
author: Your Name
simple_search: http://google.com/search
description:
# Default date format is "ordinal" (resulting in "July 22nd 2007")
# You can customize the format as defined in
# http://www.ruby-doc.org/core-1.9.2/Time.html#method-i-strftime
# Additionally, %o will give you the ordinal representation of the day
date_format: "ordinal"
# RSS / Email (optional) subscription links (change if using something like Feedburner)
subscribe_rss: /atom.xml
subscribe_email:
category_feeds: false
# RSS feeds can list your email address if you like
email:
excerpt_link: "Read on &rarr;" # "Continue reading" link text at the bottom of excerpted articles
titlecase: true # Converts page and post titles to titlecase
paginate: 10 # Posts per page on the blog index
pagination_dir: blog # Directory base for pagination URLs eg. /blog/page/2/
recent_posts: 5 # Posts in the sidebar Recent Posts section
excerpt_link: "Read on &rarr;" # "Continue reading" link text at the bottom of excerpted articles
excerpt_in_feed: false # Truncate excerpted articles in the atom feed
permalink_label: "Permalink"
permalink_label_feed: "&#9875; Permalink"
linklog_marker: "&rarr;"
linklog_marker_position: after
linklog_marker_position_feed: after
standard_post_marker:

View File

@ -0,0 +1,3 @@
# Delicious link stream
delicious_user:
delicious_count: 3

View File

@ -0,0 +1,12 @@
---
# ----------------------- #
# GitHub Pages Config #
# deploy_default: push #
# ----------------------- #
# This will be configured for you when you run config_deploy
deploy_branch: "gh-pages"
deploy_dir: "_deploy"
# Hidden "dot" files that should be included with the deployed site (see task copydot)
copy_dot_files: []

View File

@ -0,0 +1,16 @@
---
# ------------------------ #
# RSync Config #
# deploy_default: rsync #
# ------------------------ #
# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
ssh_user: "user@domain.com"
ssh_port: "22"
document_root: "~/website.com/"
rsync_delete: false
rsync_args: "" # Any extra arguments to pass to rsync
deploy_dir: "_deploy"
# Hidden "dot" files that should be included with the deployed site (see task copydot)
copy_dot_files: []

View File

@ -0,0 +1,7 @@
---
# --------------------------------- #
# Disqus Comments Configuration #
# --------------------------------- #
disqus_short_name:
disqus_show_comment_count: false

View File

@ -0,0 +1,6 @@
---
# ----------------------------------- #
# Gaug.es Analytics Configuration #
# ----------------------------------- #
gauges_analytics_tracking_id:

View File

@ -0,0 +1,10 @@
---
# --------------------------------------- #
# Github Sidebar Repos Listing Plugin #
# --------------------------------------- #
# Github repositories
github_user:
github_repo_count: 0
github_show_profile_link: true
github_skip_forks: true

View File

@ -0,0 +1,6 @@
---
# ---------------------------------- #
# Google Analytics Configuration #
# ---------------------------------- #
google_analytics_tracking_id:

View File

@ -0,0 +1,8 @@
---
# --------------------------------- #
# Google+ Profile Configuration #
# --------------------------------- #
# Hidden: No visible button, just add author information to search results
googleplus_user:
googleplus_hidden: false

View File

@ -0,0 +1,25 @@
---
# ------------------------ #
# Jekyll Configuration #
# ------------------------ #
# If publishing to a subdirectory as in http://site.com/project set 'root: /project'
root: /
permalink: /:year/:month/:day/:title/
source: source # source file directory
destination: public # compiled site directory
plugins: plugins
code_dir: downloads/code
category_dir: blog/categories
markdown: rdiscount
pygments: false # Jekyll's default Python Pygments have been replaced by pygments.rb.
# Set to true to use Albino + Python Pygments
blog_index_dir: source # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog')
stash_dir: _stash # directory to stash posts for speedy generation
posts_dir: _posts # directory for blog files
themes_dir: .themes # directory for blog files
new_post_ext: markdown # default new post file extension when using the new_post task
new_page_ext: markdown # default new page file extension when using the new_page task
server_host: 0.0.0.0 # host ip address for preview server
server_port: 4000 # port for preview server eg. localhost:4000

View File

@ -0,0 +1,3 @@
# Pinboard link stream
pinboard_user:
pinboard_count: 3

View File

@ -0,0 +1,14 @@
---
# --------------------------------- #
# Post/Page Share Configuration #
# --------------------------------- #
# Facebook Like
facebook_like: false
# Google+
google_plus_one: false
google_plus_one_size: medium
# Twitter
twitter_tweet_button: true

View File

@ -0,0 +1,10 @@
---
# -------------------------------- #
# Tweet Sidebar Plugin Configs #
# -------------------------------- #
twitter_user:
twitter_tweet_count: 4
twitter_show_replies: false
twitter_follow_button: true
twitter_show_follower_count: false

6
_config/deploy.yml Normal file
View File

@ -0,0 +1,6 @@
---
# -------------------------- #
# User Deployment Config #
# -------------------------- #
deploy_default: rsync

5
_config/site.yml Normal file
View File

@ -0,0 +1,5 @@
---
# --------------------------- #
# User Site Configuration #
# --------------------------- #

View File

@ -1,18 +1,21 @@
# Require any additional compass plugins here. $:.unshift File.expand_path(File.dirname(__FILE__), %w{ lib }) # For use/testing when no gem is installed
require "octopress"
config = Octopress::Configuration.read_configuration
project_type = :stand_alone project_type = :stand_alone
# Publishing paths compass_http_path = config[:destination].gsub('public', '')
http_path = "/" http_path = compass_http_path
http_images_path = "/images" http_images_path = "#{compass_http_path}/images"
http_generated_images_path = "/images" http_generated_images_path = "#{compass_http_path}/images"
http_fonts_path = "/fonts" http_fonts_path = "#{compass_http_path}/fonts"
css_dir = "public/stylesheets" css_dir = "#{config[:destination]}/stylesheets"
# Local development paths
sass_dir = "sass" sass_dir = "sass"
images_dir = "source/images" images_dir = "#{config[:source]}/images"
fonts_dir = "source/fonts" fonts_dir = "#{config[:source]}/fonts"
generated_images_dir = "source/images" generated_images_dir = "#{config[:source]}/images"
line_comments = false line_comments = false
output_style = :compressed output_style = :compressed

7
lib/octopress.rb Normal file
View File

@ -0,0 +1,7 @@
$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
module Octopress
end
require "octopress/core_ext"
require "octopress/configuration"

View File

@ -0,0 +1,86 @@
require 'yaml'
class Octopress::Configuration
def self.config_dir(*subdirs)
File.absolute_path(File.join(File.dirname(__FILE__), '../', '../' '_config', *subdirs))
end
# Static: Reads the configuration of the specified file
#
# path - the String path to the configuration file, relative to ./_config
#
# Returns a Hash of the items in the configuration file (symbol keys)
def self.read_config(path)
full_path = self.config_dir(path)
if File.exists? full_path
begin
configs = YAML.load(File.open(full_path))
if configs.nil?
configs
else
configs.to_symbol_keys
end
rescue => e
puts "Error reading configuration file '#{full_path}':"
puts e.message, e.backtrace
exit(-1)
end
else
raise ArgumentError, "File at '#{full_path}' does not exist."
end
end
# Static: Writes the contents of a set of configurations to a path in the config directory
#
# path - the String path to the configuration file, relative to ./_config
# obj - the object to be dumped into the specified file in YAML form
#
# Returns
def self.write_config(path, obj)
YAML.dump(obj.to_string_keys, File.open(self.config_dir(path), 'w'))
end
# Static: Reads all the configuration files into one hash
#
# Returns a Hash of all the configuration files, with each key being a symbol
def self.read_configuration
configs = {}
Dir.glob(self.config_dir('defaults', '**', '*.yml')) do |filename|
file_yaml = YAML.load(File.read(filename))
unless file_yaml.nil?
configs = file_yaml.deep_merge(configs)
end
end
Dir.glob(self.config_dir('*.yml')) do |filename|
file_yaml = YAML.load(File.read(filename))
unless file_yaml.nil?
configs = file_yaml.deep_merge(configs)
end
end
configs.to_symbol_keys
end
# Static: Writes configuration files necessary for generation of the Jekyll site
#
# Returns a Hash of the items which were written to the Jekyll configuration file
def self.write_configs_for_generation
config = self.read_configuration
jekyll_configs = {}
File.open("_config.yml", "w") do |f|
jekyll_configs = config.to_string_keys.to_yaml :canonical => false
f.write(jekyll_configs)
end
jekyll_configs
end
# Static: Removes configuration files required for site generation
#
# Returns the number of files deleted
def self.remove_configs_for_generation
File.unlink("_config.yml")
end
end

26
lib/octopress/core_ext.rb Normal file
View File

@ -0,0 +1,26 @@
class Hash
# Merges self with another hash, recursively.
#
# This code was lovingly stolen from some random gem:
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
#
# Thanks to whoever made it.
def deep_merge(hash)
target = dup
hash.keys.each do |key|
if hash[key].is_a? Hash and self[key].is_a? Hash
target[key] = target[key].deep_merge(hash[key])
next
end
target[key] = hash[key]
end
target
end
def to_symbol_keys
inject({}) { |memo,(k,v)| memo[k.to_sym] = v; memo }
end
def to_string_keys
inject({}) { |memo,(k,v)| memo[k.to_s] = v; memo }
end
end