diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..cd39c4a --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/Gemfile b/Gemfile index f9fa1a6..bd0bf6a 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ group :development do gem 'liquid', '~> 2.3.0' gem 'tzinfo', '~> 0.3.35' gem 'rake-minify' + gem 'rdiscount', '~> 1.6.8' end gem 'sinatra', '~> 1.3.3' diff --git a/Gemfile.lock b/Gemfile.lock index bc8ff12..4a80a18 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,6 +37,7 @@ GEM jsmin (~> 1.0.1) rake (>= 0.8.7) rb-fsevent (0.9.3) + rdiscount (1.6.8) redcarpet (2.2.2) rubypants (0.2.0) sass (3.2.4) @@ -64,6 +65,7 @@ DEPENDENCIES rake (~> 10.0.3) rake-minify rb-fsevent (~> 0.9.3) + rdiscount redcarpet (~> 2.2.2) rubypants (~> 0.2.0) sinatra (~> 1.3.3) diff --git a/Rakefile b/Rakefile index 222b027..7c618a4 100644 --- a/Rakefile +++ b/Rakefile @@ -1,53 +1,39 @@ -require 'rubygems' -require 'bundler/setup' -require 'stringex' +$:.unshift File.expand_path("lib", File.dirname(__FILE__)) # For use/testing when no gem is installed + +require "rubygems" +require "bundler/setup" +require "stringex" require 'time' require 'tzinfo' require 'rake/minify' require 'time' +require 'yaml' +require 'octopress' -## -- Rsync Deploy config -- ## -# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file -ssh_user = "user@domain.com" -ssh_port = "22" -ssh_key = "" -document_root = "~/website.com/" -rsync_delete = false -rsync_args = "" # Any extra arguments to pass to rsync -deploy_default = "rsync" +### Configuring Octopress: +### Under _config/ you will find: +### site.yml, deploy.yml +### Here you can override Octopress's default configurations or add your own. +### This Rakefile uses those config settings to do what it does. +### Please do not change anything below if you want help -- +### otherwise, you're on your own ;-) -# This will be configured for you when you run config_deploy -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 +configuration = Octopress::Configuration.read_configuration 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| - 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' end # copy theme into working Jekyll directories theme = args.theme || 'classic' - puts "## Copying "+theme+" theme into ./#{source_dir} and ./sass" - mkdir_p source_dir - cp_r "#{themes_dir}/#{theme}/source/.", source_dir + puts "## Copying "+theme+" theme into ./#{configuration[:source]} and ./sass" + mkdir_p configuration[:source] + cp_r "#{configuration[:themes_dir]}/#{theme}/source/.", configuration[:source] mkdir_p "sass" - cp_r "#{themes_dir}/#{theme}/sass/.", "sass" - mkdir_p "#{source_dir}/#{posts_dir}" - mkdir_p public_dir + cp_r "#{configuration[:themes_dir]}/#{theme}/sass/.", "sass" + mkdir_p "#{configuration[:source]}/#{configuration[:posts_dir]}" + mkdir_p configuration[:destination] end ####################### @@ -57,19 +43,21 @@ end desc "Generate jekyll site" task :generate, :no_future do |t, args| 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" - system "compass compile --css-dir #{source_dir}/stylesheets" + system "compass compile --css-dir #{configuration[:source]}/stylesheets" Rake::Task['minify_and_combine'].execute 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? + Octopress::Configuration.remove_configs_for_generation end 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}" group(output_file) do @@ -103,14 +91,16 @@ end desc "Watch the site and regenerate when it changes" task :watch, :show_future do |t, args| 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." - system "compass compile --css-dir #{source_dir}/stylesheets" + system "compass compile --css-dir #{configuration[:source]}/stylesheets" Rake::Task['minify_and_combine'].execute jekyllPid = Process.spawn("jekyll --auto #{'--no-future' if future.nil?}") compassPid = Process.spawn("compass watch") trap("INT") { [jekyllPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH } + Octopress::Configuration.remove_configs_for_generation exit 0 } [jekyllPid, compassPid].each { |pid| Process.wait(pid) } @@ -119,15 +109,17 @@ end desc "preview the site in a web browser." task :preview, :show_future do |t, args| 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) - puts "Starting to watch source with Jekyll and Compass. Starting Rack, serving to http://#{server_host}:#{server_port}" - system "compass compile --css-dir #{source_dir}/stylesheets" + 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. 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?}") 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") { [jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH } + Octopress::Configuration.remove_configs_for_generation exit 0 } @@ -135,17 +127,17 @@ task :preview, :show_future do |t, args| end # 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| if args.title title = args.title else title = get_stdin("Enter a title for your post: ") 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) - mkdir_p "#{source_dir}/#{posts_dir}" - filename = "#{source_dir}/#{posts_dir}/#{time.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}" + mkdir_p "#{configuration[:source]}/#{configuration[:posts_dir]}" + filename = "#{configuration[:source]}/#{configuration[:posts_dir]}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{configuration[:new_post_ext]}" if File.exist?(filename) abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n' end @@ -163,11 +155,11 @@ task :new_post, :title do |t, args| 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") -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| - 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') - page_dir = [source_dir] + page_dir = [configuration[:source]] if args.filename.downcase =~ /(^.+\/)?(.+)/ filename, dot, extension = $2.rpartition('.').reject(&:empty?) # Get filename and extension title = filename @@ -176,7 +168,7 @@ task :new_page, :filename do |t, args| page_dir << filename filename = "index" end - extension ||= new_page_ext + extension ||= configuration[:new_page_ext] page_dir = page_dir.map! { |d| d = d.to_url }.join('/') # Sanitize path filename = filename.downcase.to_url @@ -210,22 +202,22 @@ task :isolate, :filename do |t, args| else filename = get_stdin("Enter a post file name: ") end - full_stash_dir = "#{source_dir}/#{stash_dir}" - FileUtils.mkdir(full_stash_dir) unless File.exist?(full_stash_dir) - Dir.glob("#{source_dir}/#{posts_dir}/*.*") do |post| - FileUtils.mv post, full_stash_dir unless post.include?(filename) + full_configuration[:stash_dir] = "#{configuration[:source]}/#{configuration[:stash_dir]}" + FileUtils.mkdir(full_configuration[:stash_dir]) unless File.exist?(full_configuration[:stash_dir]) + Dir.glob("#{configuration[:source]}/#{configuration[:posts_dir]}/*.*") do |post| + FileUtils.mv post, full_configuration[:stash_dir] unless post.include?(filename) end end desc "Move all stashed posts back into the posts directory, ready for site generation." 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 desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache" task :clean do [".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" puts "## Cleaned Sass, Pygments and Gist caches, removed generated stylesheets ##" end @@ -246,7 +238,7 @@ task :update_style, :theme do |t, args| end mv "sass", "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" puts "## Updated Sass ##" 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" task :update_source, :theme do |t, args| theme = args.theme || 'classic' - if File.directory?("#{source_dir}.old") - puts "## Removed existing #{source_dir}.old directory" - rm_r "#{source_dir}.old", :secure=>true + if File.directory?("#{configuration[:source]}.old") + puts "## Removed existing #{configuration[:source]}.old directory" + rm_r "#{configuration[:source]}.old", :secure=>true end - mkdir "#{source_dir}.old" - cp_r "#{source_dir}/.", "#{source_dir}.old" - puts "## Copied #{source_dir} into #{source_dir}.old/" - cp_r "#{themes_dir}/"+theme+"/source/.", source_dir, :remove_destination=>true - cp_r "#{source_dir}.old/_includes/custom/.", "#{source_dir}/_includes/custom/", :remove_destination=>true - mv "#{source_dir}/index.html", "#{blog_index_dir}", :force=>true if blog_index_dir != source_dir - cp "#{source_dir}.old/index.html", source_dir if blog_index_dir != source_dir && File.exists?("#{source_dir}.old/index.html") - if File.exists?("#{source_dir}/blog/archives/index.html") + mkdir "#{configuration[:source]}.old" + cp_r "#{configuration[:source]}/.", "#{configuration[:source]}.old" + puts "## Copied #{configuration[:source]} into #{configuration[:source]}.old/" + cp_r "#{configuration[:themes_dir]}/"+theme+"/source/.", configuration[:source], :remove_destination=>true + cp_r "#{configuration[:source]}.old/_includes/custom/.", "#{configuration[:source]}/_includes/custom/", :remove_destination=>true + mv "#{configuration[:source]}/index.html", "#{configuration[:blog_index_dir]}", :force=>true if configuration[:blog_index_dir] != configuration[:source] + 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?("#{configuration[:source]}/blog/archives/index.html") 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 = navigation.gsub(/(.*)\/blog(\/archives)(.*$)/m, '\1\2\3') File.open(file, 'w') do |f| f.write navigation end - rm_r "#{source_dir}/blog/archives" - rm_r "#{source_dir}/blog" if Dir.entries("#{source_dir}/blog").join == "..." + rm_r "#{configuration[:source]}/blog/archives" + rm_r "#{configuration[:source]}/blog" if Dir.entries("#{configuration[:source]}/blog").join == "..." end - puts "## Updated #{source_dir} ##" + puts "## Updated #{configuration[:source]} ##" end ############## @@ -286,7 +278,7 @@ end desc "Default deploy task" task :deploy do - Rake::Task["#{deploy_default}"].execute + Rake::Task["#{configuration[:deploy_default]}"].execute end desc "Generate website and deploy" @@ -300,29 +292,29 @@ task :rsync do exclude = "--exclude-from '#{File.expand_path('./rsync-exclude')}'" end 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 desc "deploy public directory to github pages" multitask :push do - if File.directory?(deploy_dir) + if File.directory?(configuration[:deploy_dir]) 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" - cd "#{deploy_dir}" do - system "git pull origin #{deploy_branch}" + cd "#{configuration[:deploy_dir]}" do + system "git pull origin #{configuration[:deploy_branch]}" end - puts "\n## copying #{public_dir} to #{deploy_dir}" - cp_r "#{public_dir}/.", deploy_dir - cd "#{deploy_dir}" do + puts "\n## copying #{configuration[:destination]} to #{configuration[:deploy_dir]}" + cp_r "#{configuration[:destination]}/.", configuration[:deploy_dir] + cd "#{configuration[:deploy_dir]}" do File.new(".nojekyll", "w").close system "git add ." system "git add -u" message = "Site updated at #{Time.now.utc}" puts "\n## Commiting: #{message}" system "git commit -m \"#{message}\"" - puts "\n## Pushing generated #{deploy_dir} website" - if system "git push origin #{deploy_branch}" + puts "\n## Pushing generated #{configuration[:deploy_dir]} website" + if system "git push origin #{configuration[:deploy_branch]}" puts "\n## GitHub Pages deploy complete" else remote = `git remote -v` @@ -355,28 +347,15 @@ task :set_root_dir, :dir do |t, args| else dir = "/" + args.dir.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, ''); end - rakefile = IO.read(__FILE__) - rakefile.sub!(/public_dir(\s*)=(\s*)(["'])[\w\-\/]*["']/, "public_dir\\1=\\2\\3public#{dir}\\3") - File.open(__FILE__, 'w') do |f| - f.write rakefile - end - compass_config = IO.read('config.rb') - 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") - compass_config.sub!(/http_fonts_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_fonts_path\\1=\\2\\3#{dir}/fonts\\3") - 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}" + # update personal configuration + site_configs = Octopress::Configuration.read_config('site.yml') + site_configs[:destination] = "public#{dir}" + site_configs[:subscribe_rss] = "#{dir}/atom.xml" + site_configs[:root] = "/#{dir.sub(/^\//, '')}" + Octopress::Configuration.write_config('site.yml', site_configs) + + rm_rf configuration[:destination] + mkdir_p site_configs[:destination] puts "\n========================================================" puts "Site's root directory is now '/#{dir.sub(/^\//, '')}'" 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" puts "Master branch renamed to 'source' for committing your blog source files" else - unless !public_dir.match("#{project}").nil? + unless !configuration[:destination].match("#{project}").nil? Rake::Task[:set_root_dir].invoke(project) end end end # Configure deployment repository - rm_rf deploy_dir - mkdir deploy_dir - cd "#{deploy_dir}" do + rm_rf configuration[:deploy_dir] + mkdir configuration[:deploy_dir] + cd "#{configuration[:deploy_dir]}" do system "git init" system "git remote add origin #{repo_url}" puts "Attempting to pull from repository" @@ -436,29 +415,23 @@ task :setup_github_pages, :repo do |t, args| end end - # Configure deployment setup in Rakefile - rakefile = IO.read(__FILE__) - rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{branch}\\3") - rakefile.sub!(/deploy_default(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_default\\1=\\2\\3push\\3") - File.open(__FILE__, 'w') do |f| - f.write rakefile - end + # Configure deployment setup in deploy.yml + deploy_configuration = Octopress::Configuration.read_config('deploy.yml') + deploy_configuration[:deploy_default] = "push" + deploy_configuration[:deploy_branch] = branch + deploy_configuration = Octopress::Configuration.read_config('defaults/deploy/gh_pages.yml').deep_merge(deploy_configuration) + puts deploy_configuration + Octopress::Configuration.write_config('deploy.yml', deploy_configuration) # Configure published url - jekyll_config = IO.read('_config.yml') - current_url = /^url:\s?(.*$)/.match(jekyll_config)[1] - has_cname = File.exists?("#{source_dir}/CNAME") - 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 + site_configuration = Octopress::Configuration.read_config('site.yml') + site_configuration[:url] = url if site_configuration.has_key?(:url) && site_configuration[:url] == 'http://yoursite.com' + site_configuration = Octopress::Configuration.read_config('defaults/jekyll.yml').deep_merge(site_configuration) puts "\n========================================================" + has_cname = File.exists?("#{configuration[:source]}/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] if cname != 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 else 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 "Finally, follow the guide at http://help.github.com/pages/#custom_domains for help pointing your domain to GitHub Pages" end @@ -481,7 +454,7 @@ end # usage rake list_posts or rake list_posts[pub|unpub] desc "List all unpublished/draft posts" task :list_drafts do - posts = Dir.glob("#{source_dir}/#{posts_dir}/*.*") + posts = Dir.glob("#{configuration[:source]}/#{configuration[:posts_dir]}/*.*") unpublished = get_unpublished(posts) puts unpublished.empty? ? "There are no posts currently in draft" : unpublished end diff --git a/_config.yml b/_config.yml deleted file mode 100644 index b7fcb5b..0000000 --- a/_config.yml +++ /dev/null @@ -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 →" # "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: "⚓ Permalink" -linklog_marker: "→" -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 diff --git a/_config/defaults/classic.yml b/_config/defaults/classic.yml new file mode 100644 index 0000000..b41de4a --- /dev/null +++ b/_config/defaults/classic.yml @@ -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 →" # "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 →" # "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: "⚓ Permalink" +linklog_marker: "→" +linklog_marker_position: after +linklog_marker_position_feed: after +standard_post_marker: diff --git a/_config/defaults/delicious_stream.yml b/_config/defaults/delicious_stream.yml new file mode 100644 index 0000000..94f99ce --- /dev/null +++ b/_config/defaults/delicious_stream.yml @@ -0,0 +1,3 @@ +# Delicious link stream +delicious_user: +delicious_count: 3 diff --git a/_config/defaults/deploy/gh_pages.yml b/_config/defaults/deploy/gh_pages.yml new file mode 100644 index 0000000..1e804ea --- /dev/null +++ b/_config/defaults/deploy/gh_pages.yml @@ -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: [] diff --git a/_config/defaults/deploy/rsync.yml b/_config/defaults/deploy/rsync.yml new file mode 100644 index 0000000..d06f044 --- /dev/null +++ b/_config/defaults/deploy/rsync.yml @@ -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: [] diff --git a/_config/defaults/disqus.yml b/_config/defaults/disqus.yml new file mode 100644 index 0000000..3924e0b --- /dev/null +++ b/_config/defaults/disqus.yml @@ -0,0 +1,7 @@ +--- +# --------------------------------- # +# Disqus Comments Configuration # +# --------------------------------- # + +disqus_short_name: +disqus_show_comment_count: false diff --git a/_config/defaults/gauges_analytics.yml b/_config/defaults/gauges_analytics.yml new file mode 100644 index 0000000..1fce9f4 --- /dev/null +++ b/_config/defaults/gauges_analytics.yml @@ -0,0 +1,6 @@ +--- +# ----------------------------------- # +# Gaug.es Analytics Configuration # +# ----------------------------------- # + +gauges_analytics_tracking_id: diff --git a/_config/defaults/github_repos_sidebar.yml b/_config/defaults/github_repos_sidebar.yml new file mode 100644 index 0000000..b495fa6 --- /dev/null +++ b/_config/defaults/github_repos_sidebar.yml @@ -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 diff --git a/_config/defaults/google_analytics.yml b/_config/defaults/google_analytics.yml new file mode 100644 index 0000000..6f85362 --- /dev/null +++ b/_config/defaults/google_analytics.yml @@ -0,0 +1,6 @@ +--- +# ---------------------------------- # +# Google Analytics Configuration # +# ---------------------------------- # + +google_analytics_tracking_id: diff --git a/_config/defaults/google_plus.yml b/_config/defaults/google_plus.yml new file mode 100644 index 0000000..609e464 --- /dev/null +++ b/_config/defaults/google_plus.yml @@ -0,0 +1,8 @@ +--- +# --------------------------------- # +# Google+ Profile Configuration # +# --------------------------------- # + +# Hidden: No visible button, just add author information to search results +googleplus_user: +googleplus_hidden: false \ No newline at end of file diff --git a/_config/defaults/jekyll.yml b/_config/defaults/jekyll.yml new file mode 100644 index 0000000..1076139 --- /dev/null +++ b/_config/defaults/jekyll.yml @@ -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 diff --git a/_config/defaults/pinboard_stream.yml b/_config/defaults/pinboard_stream.yml new file mode 100644 index 0000000..1586062 --- /dev/null +++ b/_config/defaults/pinboard_stream.yml @@ -0,0 +1,3 @@ +# Pinboard link stream +pinboard_user: +pinboard_count: 3 diff --git a/_config/defaults/sharing_buttons.yml b/_config/defaults/sharing_buttons.yml new file mode 100644 index 0000000..9f9b63d --- /dev/null +++ b/_config/defaults/sharing_buttons.yml @@ -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 diff --git a/_config/defaults/twitter_stream.yml b/_config/defaults/twitter_stream.yml new file mode 100644 index 0000000..a63aec0 --- /dev/null +++ b/_config/defaults/twitter_stream.yml @@ -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 diff --git a/_config/deploy.yml b/_config/deploy.yml new file mode 100644 index 0000000..190f637 --- /dev/null +++ b/_config/deploy.yml @@ -0,0 +1,6 @@ +--- +# -------------------------- # +# User Deployment Config # +# -------------------------- # + +deploy_default: rsync diff --git a/_config/site.yml b/_config/site.yml new file mode 100644 index 0000000..05e54ac --- /dev/null +++ b/_config/site.yml @@ -0,0 +1,5 @@ +--- +# --------------------------- # +# User Site Configuration # +# --------------------------- # + diff --git a/config.rb b/config.rb index f0d44d1..cffddb4 100644 --- a/config.rb +++ b/config.rb @@ -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 -# Publishing paths -http_path = "/" -http_images_path = "/images" -http_generated_images_path = "/images" -http_fonts_path = "/fonts" -css_dir = "public/stylesheets" +compass_http_path = config[:destination].gsub('public', '') +http_path = compass_http_path +http_images_path = "#{compass_http_path}/images" +http_generated_images_path = "#{compass_http_path}/images" +http_fonts_path = "#{compass_http_path}/fonts" +css_dir = "#{config[:destination]}/stylesheets" -# Local development paths sass_dir = "sass" -images_dir = "source/images" -fonts_dir = "source/fonts" -generated_images_dir = "source/images" +images_dir = "#{config[:source]}/images" +fonts_dir = "#{config[:source]}/fonts" +generated_images_dir = "#{config[:source]}/images" line_comments = false output_style = :compressed diff --git a/lib/octopress.rb b/lib/octopress.rb new file mode 100644 index 0000000..99e607d --- /dev/null +++ b/lib/octopress.rb @@ -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" diff --git a/lib/octopress/configuration.rb b/lib/octopress/configuration.rb new file mode 100644 index 0000000..68986c2 --- /dev/null +++ b/lib/octopress/configuration.rb @@ -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 + \ No newline at end of file diff --git a/lib/octopress/core_ext.rb b/lib/octopress/core_ext.rb new file mode 100644 index 0000000..bf7bd5b --- /dev/null +++ b/lib/octopress/core_ext.rb @@ -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 \ No newline at end of file