diff --git a/.gitignore b/.gitignore index d0174fbbb1..7d68ba4c9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ _site/* _theme_packages/* +.idea/* Thumbs.db .DS_Store diff --git a/README.md b/README.md index 6a90c819b5..168a5d5567 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Jekyll-Bootstrap +Kris's Blog -The quickest way to start and publish your Jekyll powered blog. 100% compatible with GitHub pages +Based on ## Usage @@ -8,7 +8,7 @@ For all usage and documentation please see: ## Version -0.3.0 - stable and versioned using [semantic versioning](http://semver.org/). +0.3.2 - stable and versioned using [semantic versioning](http://semver.org/). **NOTE:** 0.3.0 introduces a new theme which is not backwards compatible in the sense it won't _look_ like the old version. However, the actual API has not changed at all. diff --git a/Rakefile b/Rakefile index 176c94b5c8..3cff16924c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,28 +1,29 @@ -require "rubygems" +require 'rubygems' require 'rake' require 'yaml' require 'time' -SOURCE = "." +SOURCE = '.' CONFIG = { - 'version' => "0.3.0", - 'themes' => File.join(SOURCE, "_includes", "themes"), - 'layouts' => File.join(SOURCE, "_layouts"), - 'posts' => File.join(SOURCE, "_posts"), - 'post_ext' => "md", - 'theme_package_version' => "0.1.0" + :version => '0.3.1', + :themes => File.join(SOURCE, '_includes', 'themes'), + :layouts => File.join(SOURCE, '_layouts'), + :posts => File.join(SOURCE, '_posts'), + :drafts => File.join(SOURCE, '_drafts'), + :post_ext => 'md', + :theme_package_version => '0.1.0' } # Path configuration helper module JB class Path - SOURCE = "." + SOURCE = '.' Paths = { - :layouts => "_layouts", - :themes => "_includes/themes", - :theme_assets => "assets/themes", - :theme_packages => "_theme_packages", - :posts => "_posts" + :layouts => '_layouts', + :themes => '_includes/themes', + :theme_assets => 'assets/themes', + :theme_packages => '_theme_packages', + :posts => '_posts' } def self.base @@ -32,7 +33,7 @@ module JB # build a path relative to configured path settings. def self.build(path, opts = {}) opts[:root] ||= SOURCE - path = "#{opts[:root]}/#{Paths[path.to_sym]}/#{opts[:node]}".split("/") + path = "#{opts[:root]}/#{Paths[path.to_sym]}/#{opts[:node]}".split('/') path.compact! File.__send__ :join, path end @@ -40,115 +41,202 @@ module JB end #Path end #JB -# Usage: rake post title="A Title" [date="2012-02-09"] [tags=[tag1,tag2]] [category="category"] -desc "Begin a new post in #{CONFIG['posts']}" +desc 'Usage' +task :default do + puts "Usage\n" + puts "rake post title=\"title\" [date=\"date\"]\n" + puts "rake draft [title=\"A Title\"] [tags=[tag1, tag2]]" + puts 'rake preview [drafts=true]' + puts "rake publish [title=\"A Title\"] [date=\"date\"]" + puts "rake page [name=\"Page Name\"]" + puts "rake theme:switch name=\"the-program\" (alias switch_theme)" + puts "rake theme:install git=\"https://github.com/jekyllbootstrap/theme-twitter.git\"" +end + +# Usage: rake post title="A Title" [date="2012-02-09"] [tags=[tag1, tag2]] +desc "Begin a new post in #{CONFIG[:posts]}" task :post do - abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts']) - title = ENV["title"] || "new-post" - tags = ENV["tags"] || "[]" - category = ENV["category"] || "" + abort("rake aborted: '#{CONFIG[:posts]}' directory not found.") unless FileTest.directory?(CONFIG[:posts]) + title = ENV['title'] || 'new-post' + tags = ENV['tags'] || '[]' slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') begin date = (ENV['date'] ? Time.parse(ENV['date']) : Time.now).strftime('%Y-%m-%d') rescue => e - puts "Error - date format must be YYYY-MM-DD, please check you typed it correctly!" + puts 'Error - date format must be YYYY-MM-DD, please check you typed it correctly!' exit -1 end - filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}") + filename = File.join(CONFIG[:posts], "#{date}-#{slug}.#{CONFIG[:post_ext]}") 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?", %w(y n)) == 'n' end puts "Creating new post: #{filename}" open(filename, 'w') do |post| - post.puts "---" - post.puts "layout: post" + post.puts '---' + post.puts 'layout: post' post.puts "title: \"#{title.gsub(/-/,' ')}\"" post.puts 'description: ""' - post.puts "category: \"#{category.gsub(/-/,' ')}\"" + post.puts 'category: ' post.puts "tags: #{tags}" - post.puts "---" - post.puts "{% include JB/setup %}" + post.puts '---' + post.puts '{% include JB/setup %}' end end # task :post +# Usage: rake draft [title="A Title"] [tags=[tag1, tag2]] +# if you have no title it becomes new-post which will be the default draft to publish with the draft command +desc "Begin a new draft in #{CONFIG[:drafts]}" +task :draft do + puts "Begin a new draft in #{CONFIG[:drafts]}" + unless FileTest.directory?(CONFIG[:drafts]) + FileUtils.mkdir_p(CONFIG[:drafts]) + end + + title = ENV['title'] || 'new-post' + tags = ENV['tags'] || '[]' + slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') + filename = File.join(CONFIG[:drafts], "#{slug}.#{CONFIG[:post_ext]}") + if File.exist?(filename) + abort('rake aborted!') if ask("#{filename} already exists. Do you want to overwrite?", %w(y n)) == 'n' + end + + puts "Creating new draft: #{filename}" + open(filename, 'w') do |post| + + post.puts '---' + post.puts 'layout: post' + post.puts "title: \"#{title.gsub(/-/, ' ')}\"" + post.puts 'description: ""' + + post.puts 'category: ' + post.puts "tags: #{tags}" + post.puts '---' + post.puts '{% include JB/setup %}' + end +end # task :draft + +# Usage: rake publish [title="A Title"] [date="2012-02-09"] +# if you give no title it will try to publish "new post". +desc "Publish a draft in #{CONFIG[:posts]}" +task :publish do + abort("rake aborted: '#{CONFIG[:drafts]}' directory not found.") unless FileTest.directory?(CONFIG[:drafts]) + + title = ENV['title'] || 'new-post' + slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') + filename = File.join(CONFIG[:drafts], "#{slug}.#{CONFIG[:post_ext]}") + + unless File.exists?(filename) + filename = File.join(CONFIG[:drafts], "new-post..#{CONFIG[:post_ext]}") + end + abort("rake aborted: no draft #{filename}' not found.") unless File.exist?(filename) + if title == 'new-post' + + text=File.open(filename).read + text.gsub!(/\r\n?/, "\n") + text.each_line do |line| + res = /^title: "([^"]+)"/.match(line) + if res + slug = res[1].downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') + break + end + end + end + + begin + date = (ENV['date'] ? Time.parse(ENV['date']) : Time.now).strftime('%Y-%m-%d') + rescue => e + puts 'Error - date format must be YYYY-MM-DD, please check you typed it correctly!' + exit -1 + end + + put_filename = File.join(CONFIG[:posts], "#{date}-#{slug}.#{CONFIG[:post_ext]}") + + puts "Publish draft: #{filename} to #{put_filename}" + + FileUtils.cp(filename, put_filename) + FileUtils.rm(filename) + +end # task :publish + # Usage: rake page name="about.html" # You can also specify a sub-directory path. -# If you don't specify a file extention we create an index.html at the path specified -desc "Create a new page." +# If you don't specify a file extension we create an index.html at the path specified +desc 'Create a new page.' task :page do - name = ENV["name"] || "new-page.md" + name = ENV['name'] || 'new-page.md' filename = File.join(SOURCE, "#{name}") - filename = File.join(filename, "index.html") if File.extname(filename) == "" - title = File.basename(filename, File.extname(filename)).gsub(/[\W\_]/, " ").gsub(/\b\w/){$&.upcase} + filename = File.join(filename, 'index.html') if File.extname(filename) == '' + title = File.basename(filename, File.extname(filename)).gsub(/[\W_]/, ' ').gsub(/\b\w/){$&.upcase } 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?", %w(y n)) == 'n' end mkdir_p File.dirname(filename) puts "Creating new page: #{filename}" open(filename, 'w') do |post| - post.puts "---" - post.puts "layout: page" + post.puts '---' + post.puts 'layout: page' post.puts "title: \"#{title}\"" post.puts 'description: ""' - post.puts "---" - post.puts "{% include JB/setup %}" + post.puts '---' + post.puts '{% include JB/setup %}' end end # task :page -desc "Launch preview environment" +desc 'Launch preview environment' task :preview do - system "jekyll serve -w" + drafts = ENV['drafts'].to_s.empty? ? '' : ' --drafts' + system "jekyll serve --watch#{drafts}" end # task :preview -# Public: Alias - Maintains backwards compatability for theme switching. -task :switch_theme => "theme:switch" +# Public: Alias - Maintains backwards compatibility for theme switching. +task :switch_theme => 'theme:switch' namespace :theme do # Public: Switch from one theme to another for your blog. # # name - String, Required. name of the theme you want to switch to. - # The theme must be installed into your JB framework. + # The the theme must be installed into your JB framework. # # Examples # # rake theme:switch name="the-program" # # Returns Success/failure messages. - desc "Switch between Jekyll-bootstrap themes." + desc 'Switch between Jekyll-bootstrap themes.' task :switch do - theme_name = ENV["name"].to_s - theme_path = File.join(CONFIG['themes'], theme_name) - settings_file = File.join(theme_path, "settings.yml") - non_layout_files = ["settings.yml"] + theme_name = ENV['name'].to_s + theme_path = File.join(CONFIG[:themes], theme_name) + settings_file = File.join(theme_path, 'settings.yml') + non_layout_files = ['settings.yml'] - abort("rake aborted: name cannot be blank") if theme_name.empty? + abort('rake aborted: name cannot be blank') if theme_name.empty? abort("rake aborted: '#{theme_path}' directory not found.") unless FileTest.directory?(theme_path) - abort("rake aborted: '#{CONFIG['layouts']}' directory not found.") unless FileTest.directory?(CONFIG['layouts']) + abort("rake aborted: '#{CONFIG[:layouts]}' directory not found.") unless FileTest.directory?(CONFIG[:layouts]) Dir.glob("#{theme_path}/*") do |filename| next if non_layout_files.include?(File.basename(filename).downcase) puts "Generating '#{theme_name}' layout: #{File.basename(filename)}" - open(File.join(CONFIG['layouts'], File.basename(filename)), 'w') do |page| - if File.basename(filename, ".html").downcase == "default" - page.puts "---" + open(File.join(CONFIG[:layouts], File.basename(filename)), 'w') do |page| + if File.basename(filename, '.html').downcase == 'default' + page.puts '---' page.puts File.read(settings_file) if File.exist?(settings_file) - page.puts "---" + page.puts '---' else - page.puts "---" - page.puts "layout: default" - page.puts "---" + page.puts '---' + page.puts 'layout: default' + page.puts '---' end - page.puts "{% include JB/setup %}" + page.puts '{% include JB/setup %}' page.puts "{% include themes/#{theme_name}/#{File.basename(filename)} %}" end end - puts "=> Theme successfully switched!" - puts "=> Reload your web-page to check it out =)" + puts '=> Theme successfully switched!' + puts '=> Reload your web-page to check it out =)' end # task :switch # Public: Install a theme using the theme packager. @@ -164,13 +252,13 @@ namespace :theme do # rake theme:install name="cool-theme" # # Returns Success/failure messages. - desc "Install theme" + desc 'Install theme' task :install do - if ENV["git"] - manifest = theme_from_git_url(ENV["git"]) - name = manifest["name"] + if ENV['git'] + manifest = theme_from_git_url(ENV['git']) + name = manifest['name'] else - name = ENV["name"].to_s.downcase + name = ENV['name'].to_s.downcase end packaged_theme_path = JB::Path.build(:theme_packages, :node => name) @@ -190,7 +278,7 @@ namespace :theme do # Exclude directories as they'll be recursively created. Exclude meta-data files. packaged_theme_files = [] FileUtils.cd(packaged_theme_path) { - Dir.glob("**/*.*") { |f| + Dir.glob('**/*.*') { |f| next if ( FileTest.directory?(f) || f =~ /^(manifest|readme|packager)/i ) packaged_theme_files << f } @@ -199,7 +287,7 @@ namespace :theme do # Mirror each file into the framework making sure to prompt if already exists. packaged_theme_files.each do |filename| file_install_path = File.join(JB::Path.base, filename) - if File.exist? file_install_path and ask("#{file_install_path} already exists. Do you want to overwrite?", ['y', 'n']) == 'n' + if File.exist? file_install_path and ask("#{file_install_path} already exists. Do you want to overwrite?", %w(y n)) == 'n' next else mkdir_p File.dirname(file_install_path) @@ -208,8 +296,8 @@ namespace :theme do end puts "=> #{name} theme has been installed!" - puts "=> ---" - if ask("=> Want to switch themes now?", ['y', 'n']) == 'y' + puts '=> ---' + if ask('=> Want to switch themes now?', %w(y n)) == 'y' system("rake switch_theme name='#{name}'") end end @@ -225,13 +313,13 @@ namespace :theme do # rake theme:package name="twitter" # # Returns Success/failure messages. - desc "Package theme" + desc 'Package theme' task :package do - name = ENV["name"].to_s.downcase + name = ENV['name'].to_s.downcase theme_path = JB::Path.build(:themes, :node => name) asset_path = JB::Path.build(:theme_assets, :node => name) - abort("rake aborted: name cannot be blank") if name.empty? + abort('rake aborted: name cannot be blank') if name.empty? abort("rake aborted: '#{theme_path}' directory not found.") unless FileTest.directory?(theme_path) abort("rake aborted: '#{asset_path}' directory not found.") unless FileTest.directory?(asset_path) @@ -246,8 +334,8 @@ namespace :theme do cp_r asset_path, packaged_theme_assets_path ## Log packager version - packager = {"packager" => {"version" => CONFIG["theme_package_version"].to_s } } - open(JB::Path.build(:theme_packages, :node => "#{name}/packager.yml"), "w") do |page| + packager = {:packager => {:version => CONFIG[:theme_package_version].to_s } } + open(JB::Path.build(:theme_packages, :node => "#{name}/packager.yml"), 'w') do |page| page.puts packager.to_yaml end @@ -264,13 +352,13 @@ end # end namespace :theme # # Returns theme manifest hash def theme_from_git_url(url) - tmp_path = JB::Path.build(:theme_packages, :node => "_tmp") - abort("rake aborted: system call to git clone failed") if !system("git clone #{url} #{tmp_path}") + tmp_path = JB::Path.build(:theme_packages, :node => '_tmp') + abort('rake aborted: system call to git clone failed') unless system("git clone #{url} #{tmp_path}") manifest = verify_manifest(tmp_path) - new_path = JB::Path.build(:theme_packages, :node => manifest["name"]) - if File.exist?(new_path) && ask("=> #{new_path} theme package already exists. Override?", ['y', 'n']) == 'n' + new_path = JB::Path.build(:theme_packages, :node => manifest['name']) + if File.exist?(new_path) && ask("=> #{new_path} theme package already exists. Override?", %w(y n)) == 'n' remove_dir(tmp_path) - abort("rake aborted: '#{manifest["name"]}' already exists as theme package.") + abort("rake aborted: '#{manifest['name']}' already exists as theme package.") end remove_dir(new_path) if File.exist?(new_path) @@ -284,17 +372,18 @@ end # # Returns theme manifest hash def verify_manifest(theme_path) - manifest_path = File.join(theme_path, "manifest.yml") + manifest_path = File.join(theme_path, 'manifest.yml') manifest_file = File.open( manifest_path ) - abort("rake aborted: repo must contain valid manifest.yml") unless File.exist? manifest_file + abort('rake aborted: repo must contain valid manifest.yml') unless File.exist? manifest_file manifest = YAML.load( manifest_file ) manifest_file.close manifest end def ask(message, valid_options) + answer = false if valid_options - answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer) + answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /, '/')} ") until valid_options.include?(answer) else answer = get_stdin(message) end diff --git a/_config.yml b/_config.yml index 17bd3e216e..e93ceba87b 100644 --- a/_config.yml +++ b/_config.yml @@ -3,6 +3,7 @@ permalink: /:categories/:year/:month/:day/:title exclude: [".rvmrc", ".rbenv-version", "README.md", "Rakefile", "changelog.md"] +auto: true pygments: true # Themes are encouraged to use these universal variables @@ -30,7 +31,7 @@ production_url : http://username.github.io # All Jekyll-Bootstrap specific configurations are namespaced into this hash # JB : - version : 0.3.0 + version : 0.3.2 # All links will be namespaced by BASE_PATH if defined. # Links in your website should always be prefixed with {{BASE_PATH}} diff --git a/changelog.md b/changelog.md index 7965e9d3fe..4d893f083e 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,13 @@ Incremental version bumps that were not released publicly are nested where appro P.S. If there is a standard (popular) changelog format, please let me know. +- **0.3.2 : 2013.12.28** + - @kriserickson Cleaned up the Rakefile so that Intellij wasn't complaining... + +- **0.3.1 : 2013.08.22** + - @kriserickson Added the ability to do drafts from command-line + - @kriserickson Fixed preview from the command line. + - **0.3.0 : 2013.02.24** - **Features** - Update twitter bootstrap to 2.2.2. Add responsiveness and update design a bit.