diff options
24 files changed, 311 insertions, 94 deletions
diff --git a/.themes/classic/sass/base/_layout.scss b/.themes/classic/sass/base/_layout.scss index ef47279a..4a3c780f 100644 --- a/.themes/classic/sass/base/_layout.scss +++ b/.themes/classic/sass/base/_layout.scss @@ -75,6 +75,15 @@ aside[role=sidebar] { @extend .group; } +.flex-content { max-width: 100%; height: auto; } + +.basic-alignment { + &.left { float: left; margin-right: 1.5em; } + &.right { float: right; margin-left: 1.5em; } + &.center { display:block; margin: 0 auto 1.5em; } + &.left, &.right { margin-bottom: .8em; } +} + .toggle-sidebar { &, .no-sidebar & { display: none; }} body.sidebar-footer { @@ -103,7 +112,7 @@ body.sidebar-footer { @extend .group; margin-right: $sidebar-width-medium; position: relative; - .no-sidebar & { margin-right: 0; } + .no-sidebar & { margin-right: 0; border-right: 0; } .collapse-sidebar & { margin-right: 20px; } > div, > article { padding-top: $pad-medium/2; diff --git a/.themes/classic/sass/base/_typography.scss b/.themes/classic/sass/base/_typography.scss index 05402574..ef83065b 100644 --- a/.themes/classic/sass/base/_typography.scss +++ b/.themes/classic/sass/base/_typography.scss @@ -86,7 +86,7 @@ del, s { text-decoration: line-through; } abbr, acronym { border-bottom: 1px dotted; cursor: help; } -pre, code, tt { @extend .mono-font; } +pre, code, tt { @extend .mono; } sub, sup { line-height: 0; } diff --git a/.themes/classic/sass/base/_utilities.scss b/.themes/classic/sass/base/_utilities.scss index 8b718cdc..2d49e659 100644 --- a/.themes/classic/sass/base/_utilities.scss +++ b/.themes/classic/sass/base/_utilities.scss @@ -5,6 +5,13 @@ height: image-height($img); } +@mixin shadow-box($border: #fff .5em solid, $shadow: rgba(#000, .15) 0 1px 4px, $border-radius: .3em) { + @include border-radius($border-radius); + @include box-shadow($shadow); + @include box-sizing(border-box); + border: $border; +} + @mixin selection($bg, $color: inherit, $text-shadow: none){ * { &::-moz-selection { background: $bg; color: $color; text-shadow: $text-shadow; } diff --git a/.themes/classic/sass/partials/_blog.scss b/.themes/classic/sass/partials/_blog.scss index 8d9d5f80..558f0a22 100644 --- a/.themes/classic/sass/partials/_blog.scss +++ b/.themes/classic/sass/partials/_blog.scss @@ -44,21 +44,12 @@ article { line-height: 1.3em; } img, video, .flash-video { - max-width: 100%; - height: auto; - border: .5em solid #fff; - @include border-radius(.3em); - @include box-shadow(rgba(#000, .15) 0 1px 4px); - @include box-sizing(border-box); - display: block; - margin: 0 auto 1.5em; + @extend .flex-content; + @extend .basic-alignment; + @include shadow-box; } - img { - &.left { float: left; margin-right: 1.5em; } - &.right { float: right; margin-left: 1.5em; } - &.left, &.right { margin-bottom: .8em; } - } - video { display: block; margin-bottom: 1.5em; width: 100%; } + video, .flash-video { margin: 0 auto 1.5em; } + video { display: block; width: 100%; } .flash-video { > div { position: relative; diff --git a/.themes/classic/sass/partials/_syntax.scss b/.themes/classic/sass/partials/_syntax.scss index 9bee3020..7e8ed8d5 100644 --- a/.themes/classic/sass/partials/_syntax.scss +++ b/.themes/classic/sass/partials/_syntax.scss @@ -85,7 +85,8 @@ h3.filename { + pre { @include border-top-radius(0px); } } -p code { +p code, +li code { @extend .mono; display: inline-block; white-space: no-wrap; diff --git a/.themes/classic/sass/partials/sidebar/_base.scss b/.themes/classic/sass/partials/sidebar/_base.scss index 08f04d23..a0d1c09e 100644 --- a/.themes/classic/sass/partials/sidebar/_base.scss +++ b/.themes/classic/sass/partials/sidebar/_base.scss @@ -20,6 +20,11 @@ aside[role=sidebar] { } } } + img { + @extend .flex-content; + @extend .basic-alignment; + @include shadow-box($border: #fff .3em solid); + } ul { margin-bottom: 0.5em; margin-left: 0; diff --git a/.themes/classic/source/_includes/article.html b/.themes/classic/source/_includes/article.html index 6b3fb045..b561fbc7 100644 --- a/.themes/classic/source/_includes/article.html +++ b/.themes/classic/source/_includes/article.html @@ -12,9 +12,12 @@ {% endunless %} {% if index %} <div class="entry-content">{{ content | excerpt }}</div> - <footer> - <a rel="full-article" href="{{ root_url }}{{ post.url }}">Read on →</a> - </footer> + {% capture excerpted %}{{ content | has_excerpt }}{% endcapture %} + {% if excerpted == 'true' %} + <footer> + <a rel="full-article" href="{{ root_url }}{{ post.url }}">{{ site.excerpt_link }}</a> + </footer> + {% endif %} {% else %} <div class="entry-content">{{ content }}</div> {% endif %} diff --git a/.themes/classic/source/_includes/head.html b/.themes/classic/source/_includes/head.html index 97f62de2..d6a6735b 100644 --- a/.themes/classic/source/_includes/head.html +++ b/.themes/classic/source/_includes/head.html @@ -25,8 +25,7 @@ <script src="{{ root_url }}/javascripts/modernizr-2.0.js"></script> <script src="http://s3.amazonaws.com/ender-js/jeesh.min.js"></script> <script src="{{ root_url }}/javascripts/octopress.js" type="text/javascript"></script> - {% capture rss_url %}{% if site.subscribe_rss contains ':' %}{{ site.subscribe_rss }}{% else %}{{ root_url }}{{ site.subscribe_rss }}{% endif %}{% endcapture %} - <link href="{{ rss_url }}" rel="alternate" title="{{site.title}}" type="application/atom+xml"/> + <link href="{{ site.subscribe_rss }}" rel="alternate" title="{{site.title}}" type="application/atom+xml"/> {% include google_analytics.html %} {% include google_plus_one.html %} {% include twitter_sharing.html %} diff --git a/.themes/classic/source/_includes/post/date.html b/.themes/classic/source/_includes/post/date.html index f1ed4815..dce92472 100644 --- a/.themes/classic/source/_includes/post/date.html +++ b/.themes/classic/source/_includes/post/date.html @@ -6,5 +6,5 @@ <time datetime="{{ date | datetime }}" pubdate {% if updated %} updated {% endif %}>{{ date | ordinalize }}</time> {% endif %} {% if was_updated != '0' %} -<time class="updated" datetime="{{ updated | datetime }}"></time> +<time class="updated" datetime="{{ updated | datetime }}">{{ updated | ordinalize }}</time> {% endif %} diff --git a/.themes/classic/source/_layouts/page.html b/.themes/classic/source/_layouts/page.html index 6710f8b1..08e056ec 100644 --- a/.themes/classic/source/_layouts/page.html +++ b/.themes/classic/source/_layouts/page.html @@ -4,10 +4,12 @@ layout: default <div> <article> + {% if page.title %} <header> <h1 class="entry-title">{{ page.title | titlecase }}</h1> {% if page.date %}<p class="meta">{% include post/date.html %}</p>{% endif %} </header> + {% endif %} {{ content }} {% unless page.footer == false %} <footer> diff --git a/.themes/classic/source/atom.xml b/.themes/classic/source/atom.xml index 23de64e9..693f3978 100644 --- a/.themes/classic/source/atom.xml +++ b/.themes/classic/source/atom.xml @@ -4,7 +4,7 @@ layout: nil <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> - <title>{{ site.blog_title }}</title> + <title>{{ site.title }}</title> <link href="{{ site.url }}/atom.xml" rel="self"/> <link href="{{ site.url }}/"/> <updated>{{ site.time | date_to_xmlschema }}</updated> @@ -22,7 +22,7 @@ layout: nil <link href="{{ site.url }}{{ post.url }}"/> <updated>{{ post.date | date_to_xmlschema }}</updated> <id>{{ site.url }}{{ post.id }}</id> - <content type="html">{{ post.content | full_urls: site.url | xml_escape }}</content> + <content type="html">{{ post.content | expand_urls: site.url | xml_escape }}</content> </entry> {% endfor %} </feed> diff --git a/.themes/classic/source/index.html b/.themes/classic/source/index.html index 7f4c0e12..e7e96956 100644 --- a/.themes/classic/source/index.html +++ b/.themes/classic/source/index.html @@ -1,7 +1,7 @@ --- layout: default -footer: false --- + <div class="blog-index"> {% assign index = true %} {% for post in paginator.posts %} @@ -13,13 +13,11 @@ footer: false <nav role="pagination"> <div> {% if paginator.next_page %} - <a class="prev" href="/page{{paginator.next_page}}/">← Older</a> + <a class="prev" href="{{paginator.next_page}}">← Older</a> {% endif %} <a href="/blog/archives">Blog Archives</a> - {% if paginator.previous_page and paginator.previous_page > 1 %} - <a class="next" href="/page{{paginator.previous_page}}/">Newer →</a> - {% elsif paginator.previous_page %} - <a class="next" href="/">Newer →</a> + {% if paginator.previous_page %} + <a class="next" href="{{paginator.previous_page}}">Newer →</a> {% endif %} </div> </nav> diff --git a/.themes/classic/source/javascripts/twitter.js b/.themes/classic/source/javascripts/twitter.js index 676619e1..a4e85557 100644 --- a/.themes/classic/source/javascripts/twitter.js +++ b/.themes/classic/source/javascripts/twitter.js @@ -1,13 +1,15 @@ // JSON-P Twitter fetcher for Octopress // (c) Brandon Mathis // MIT Lisence function getTwitterFeed(user, count, replies) { - feed = new jXHR(); + var feed = new jXHR(); + feed.onerror = function (msg,url) { $('#tweets li.loading').addClass('error').text("Twitter's busted"); } feed.onreadystatechange = function(data){ if (feed.readyState === 4) { var tweets = new Array(); + var i = 0; for (i in data){ if(tweets.length < count){ if(replies || data[i].in_reply_to_user_id == null){ @@ -66,7 +68,7 @@ function prettyDate(time) { var diff = ((current_date_full - date.getTime()) / 1000); var day_diff = Math.floor(diff / 86400); - if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) return; + if (isNaN(day_diff) || day_diff < 0) return "<span>∞</span>"; return day_diff == 0 && ( diff < 60 && say.just_now || @@ -76,5 +78,5 @@ function prettyDate(time) { diff < 86400 && Math.floor(diff / 3600) + say.hours_ago) || day_diff == 1 && say.yesterday || day_diff < 7 && day_diff + say.days_ago || - day_diff < 31 && Math.ceil(day_diff / 7) + say.weeks_ago; + day_diff > 7 && Math.ceil(day_diff / 7) + say.weeks_ago; } @@ -10,3 +10,4 @@ gem 'haml', '>= 3.1' gem 'compass', '>= 0.11' gem 'rubypants' gem 'rb-fsevent' +gem 'stringex'
\ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index c9235cb2..f2fc737d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,11 +1,11 @@ GEM remote: http://rubygems.org/ specs: - RedCloth (4.2.7) + RedCloth (4.2.8) albino (1.3.3) posix-spawn (>= 0.3.6) blankslate (2.1.2.4) - chunky_png (1.2.0) + chunky_png (1.2.1) classifier (1.3.3) fast-stemmer (>= 1.0.0) compass (0.11.5) @@ -29,17 +29,18 @@ GEM maruku (0.6.0) syntax (>= 1.0.0) posix-spawn (0.3.6) - pygments.rb (0.1.2) + pygments.rb (0.1.3) rubypython (>= 0.5.1) rack (1.3.2) rake (0.9.2) - rb-fsevent (0.4.1) + rb-fsevent (0.4.3.1) rdiscount (1.6.8) rubypants (0.2.0) rubypython (0.5.1) blankslate (>= 2.1.2.3) ffi (~> 1.0.7) - sass (3.1.5) + sass (3.1.7) + stringex (1.3.0) syntax (1.0.0) PLATFORMS @@ -56,3 +57,4 @@ DEPENDENCIES rb-fsevent rdiscount rubypants + stringex @@ -1,5 +1,6 @@ require "rubygems" require "bundler/setup" +require "stringex" ## -- Rsync Deploy config -- ## # Be sure your public key is listed in your server's ~/.ssh/authorized_keys file @@ -10,16 +11,18 @@ deploy_default = "rsync" # This will be configured for you when you run config_deploy deploy_branch = "gh-pages" -## -- Misc Configs, you probably have no reason to changes these -- ## +## -- Misc Configs -- ## -public_dir = "public" # compiled site directory -source_dir = "source" # source file directory -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 +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 +server_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]" @@ -41,30 +44,62 @@ end desc "Generate jekyll site" task :generate do + raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir) puts "## Generating Site with Jekyll" system "jekyll" end desc "Watch the site and regenerate when it changes" task :watch do - system "trap 'kill $jekyllPid $compassPid' Exit; jekyll --auto & jekyllPid=$!; compass watch & compassPid=$!; wait" + 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." + jekyllPid = spawn("jekyll --auto") + compassPid = spawn("compass watch") + + trap("INT") { + Process.kill(9, jekyllPid) + Process.kill(9, compassPid) + exit 0 + } + + Process.wait end desc "preview the site in a web browser" task :preview do - system "trap 'kill $jekyllPid $compassPid' Exit; jekyll --auto --server & jekyllPid=$!; compass watch & compassPid=$!; wait" + 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 on port #{server_port}" + jekyllPid = spawn("jekyll --auto") + compassPid = spawn("compass watch") + rackupPid = spawn("rackup --port #{server_port}") + + trap("INT") { + Process.kill(9, jekyllPid) + Process.kill(9, compassPid) + Process.kill(9, rackupPid) + exit 0 + } + + Process.wait 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}" task :new_post, :title 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) require './plugins/titlecase.rb' + mkdir_p "#{source_dir}/#{posts_dir}" args.with_defaults(:title => 'new-post') title = args.title - filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.downcase.gsub(/&/,'and').gsub(/[,'":\?!\(\)\[\]]/,'').gsub(/[\W\.]/, '-').gsub(/-+$/,'')}.#{new_post_ext}" + filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}" + if File.exist?(filename) + puts "### #{filename} Already exists. Overwrite? y/n:" + response = $stdin.gets.chomp.downcase + next unless response == 'y' + end puts "Creating new post: #{filename}" open(filename, 'w') do |post| - system "mkdir -p #{source_dir}/#{posts_dir}"; + system "mkdir -p #{source_dir}/#{posts_dir}/"; post.puts "---" post.puts "layout: post" post.puts "title: \"#{title.gsub(/&/,'&').titlecase}\"" @@ -78,6 +113,7 @@ 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}" 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) require './plugins/titlecase.rb' args.with_defaults(:filename => 'new-page') page_dir = source_dir @@ -88,6 +124,11 @@ task :new_page, :filename do |t, args| filename = "#{name}.#{extension}" mkdir_p page_dir file = page_dir + filename + if File.exist?(file) + puts "### #{file} Already exists. Overwrite? y/n:" + response = $stdin.gets.chomp.downcase + next unless response == 'y' + end puts "Creating new page: #{file}" open(file, 'w') do |page| page.puts "---" @@ -121,7 +162,7 @@ end desc "Clean out caches: _code_cache, _gist_cache, .sass-cache" task :clean do - system "rm -rf _code_cache/** _gist_cache/** .sass-cache/**" + rm_rf ["_code_cache/**", "_gist_cache/**", ".sass-cache/**", "source/stylesheets/screen.css"] end desc "Move sass to sass.old, install sass theme updates, replace sass/custom with sass.old/custom" @@ -129,11 +170,11 @@ task :update_style, :theme do |t, args| theme = args.theme || 'classic' if File.directory?("sass.old") puts "removed existing sass.old directory" - system "rm -r sass.old" + rm_r "sass.old", :secure=>true end - system "mv sass sass.old" + mv "sass", "sass.old" puts "## Moved styles into sass.old/" - system "mkdir -p sass; cp -R #{themes_dir}/"+theme+"/sass/ sass/" + cp_r "#{themes_dir}/"+theme+"/sass/", "sass" cp_r "sass.old/custom/.", "sass/custom" puts "## Updated Sass ##" end @@ -142,14 +183,15 @@ desc "Move source to source.old, install source theme updates, replace source/_i task :update_source, :theme do |t, args| theme = args.theme || 'classic' if File.directory?("#{source_dir}.old") - puts "removed existing #{source_dir}.old directory" - system "rm -r #{source_dir}.old" + puts "## Removed existing #{source_dir}.old directory" + rm_r "#{source_dir}.old", :secure=>true end - system "mv #{source_dir} #{source_dir}.old" - puts "moved #{source_dir} into #{source_dir}.old/" - system "mkdir -p #{source_dir}; cp -R #{themes_dir}/"+theme+"/source/. #{source_dir}" - system "cp -Rn #{source_dir}.old/. #{source_dir}" - system "cp -Rf #{source_dir}.old/_includes/custom/. #{source_dir}/_includes/custom/" + 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 puts "## Updated #{source_dir} ##" end @@ -158,7 +200,17 @@ end ############## desc "Default deploy task" -task :deploy => "#{deploy_default}" do +multitask :deploy => [:copydot, "#{deploy_default}"] do +end + +desc "copy dot files for deployment" +task :copydot do + exclusions = [".", "..", ".DS_Store"] + Dir["#{source_dir}/.*"].each do |file| + if !File.directory?(file) && !exclusions.include?(file) + cp(file, "#{public_dir}"); + end + end end desc "Deploy website via rsync" @@ -168,7 +220,7 @@ task :rsync do end desc "deploy public directory to github pages" -task :push do +multitask :push do puts "## Deploying branch to Github Pages " (Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) } system "cp -R #{public_dir}/* #{deploy_dir}" @@ -251,6 +303,6 @@ end desc "list tasks" task :list do - puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).to_sentence}" + puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}" puts "(type rake -T for more detail)\n\n" end diff --git a/_config.yml b/_config.yml index 3beacd60..42de3419 100644 --- a/_config.yml +++ b/_config.yml @@ -20,7 +20,6 @@ email: # If publishing to a subdirectory as in http://site.com/project set 'root: /project' root: / -port: 4000 permalink: /blog/:year/:month/:day/:title/ source: source destination: public @@ -30,8 +29,10 @@ category_dir: blog/categories markdown: rdiscount pygments: false # default python pygments have been replaced by pygments.rb -paginate: 10 # Posts per page on the blog index -recent_posts: 5 # Posts in the sidebar Recent Posts section +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 # list each of the sidebar modules you want to include, in the order you want them to appear. # To add custom asides, create files in /source/_includes/custom/asides/ and add them to the list like 'custom/asides/custom_aside_name.html' diff --git a/plugins/category_generator.rb b/plugins/category_generator.rb index 205022d3..f732fc1b 100644 --- a/plugins/category_generator.rb +++ b/plugins/category_generator.rb @@ -68,7 +68,7 @@ module Jekyll if self.layouts.key? 'category_index' dir = self.config['category_dir'] || 'categories' self.categories.keys.each do |category| - self.write_category_index(File.join(dir, category.gsub(/_|\W/, '-')), category) + self.write_category_index(File.join(dir, category.gsub(/[_\P{word}]/, '-').gsub(/-{2,}/, '-')), category) end # Throw an exception if the layout couldn't be found. @@ -104,9 +104,8 @@ module Jekyll # def category_links(categories) dir = @context.registers[:site].config['category_dir'] - root_url = @context.registers[:site].config['root'].sub(/\/$/, '') categories = categories.sort!.map do |item| - "<a class='category' href='#{root_url}/#{dir}/#{item.gsub(/_|\W/, '-')}/'>#{item}</a>" + "<a class='category' href='/#{dir}/#{item.gsub(/[_\P{word}]/, '-').gsub(/-{2,}/, '-')}/'>#{item}</a>" end case categories.length diff --git a/plugins/code_block.rb b/plugins/code_block.rb index ff242aab..9c971bf5 100644 --- a/plugins/code_block.rb +++ b/plugins/code_block.rb @@ -53,7 +53,12 @@ module Jekyll def initialize(tag_name, markup, tokens) @title = nil @caption = nil + @filetype = nil @highlight = true + if markup =~ /\s*lang:(\w+)/i + @filetype = $1 + markup = markup.sub(/lang:\w+/i,'') + end if markup =~ CaptionUrlTitle @file = $1 @caption = "<figcaption><span>#{$1}</span><a href='#{$2 + $3}'>#{$4}</a></figcaption>" @@ -64,7 +69,7 @@ module Jekyll @file = $1 @caption = "<figcaption><span>#{$1}</span></figcaption>\n" end - if @file =~ /\S[\S\s]*\.(\w+)/ + if @file =~ /\S[\S\s]*\w+\.(\w+)/ && @filetype.nil? @filetype = $1 end super @@ -77,12 +82,9 @@ module Jekyll source += @caption if @caption source = context['pygments_prefix'] + source if context['pygments_prefix'] if @filetype - @filetype = 'objc' if @filetype == 'm' - @filetype = 'perl' if @filetype == 'pl' - @filetype = 'yaml' if @filetype == 'yml' source += " #{highlight(code, @filetype)}</figure></div>" else - source += "<pre><code>" + code.lstrip.rstrip.gsub(/</,'<') + "</code></pre></figure></div>" + source += "#{tableize_code(code.lstrip.rstrip.gsub(/</,'<'))}</figure></div>" end source = source + context['pygments_suffix'] if context['pygments_suffix'] end diff --git a/plugins/include_code.rb b/plugins/include_code.rb index e064fe2c..70d5f138 100644 --- a/plugins/include_code.rb +++ b/plugins/include_code.rb @@ -30,6 +30,10 @@ module Jekyll def initialize(tag_name, markup, tokens) @title = nil @file = nil + if markup.strip =~ /\s*lang:(\w+)/i + @filetype = $1 + markup = markup.strip.sub(/lang:\w+/i,'') + end if markup.strip =~ /(.*)?(\s+|^)(\/*\S+)/i @title = $1 || nil @file = $3 @@ -52,12 +56,9 @@ module Jekyll Dir.chdir(code_path) do code = file.read - @filetype = file.extname.sub('.','') - @filetype = 'objc' if @filetype == 'm' - @filetype = 'perl' if @filetype == 'pl' - @filetype = 'yaml' if @filetype == 'yml' + @filetype = file.extname.sub('.','') if @filetype.nil? title = @title ? "#{@title} (#{file.basename})" : file.basename - url = "#{context.registers[:site].config['url']}/#{code_dir}/#{@file}" + url = "/#{code_dir}/#{@file}" source = "<div><figure role=code><figcaption><span>#{title}</span> <a href='#{url}'>download</a></figcaption>\n" source += " #{highlight(code, @filetype)}</figure></div>" end diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb index 67118b53..a63c43ab 100644 --- a/plugins/octopress_filters.rb +++ b/plugins/octopress_filters.rb @@ -12,6 +12,11 @@ module OctopressFilters end end + # Checks for excerpts (helpful for template conditionals) + def has_excerpt(input) + input =~ /<!--\s*more\s*-->/i ? true : false + end + # Summary is used on the Archive pages to return the first block of content from a post. def summary(input) if input.index(/\n\n/) @@ -26,14 +31,17 @@ module OctopressFilters # code snippet # ``` def backtick_codeblock(input) + code = nil # Markdown support input = input.gsub /<p>`{3}\s*(\w+)?<\/p>\s*<pre><code>\s*(.+?)\s*<\/code><\/pre>\s*<p>`{3}<\/p>/m do lang = $1 if lang != '' str = $2.gsub('<','<').gsub('>','>').gsub('&','&') - highlight(str, lang) + code = highlight(str, lang) + "<figure role=code>#{code}</figure>" else - "<pre><code>#{$2}</code></pre>" + code = tableize_code($2) + "<figure role=code>#{code}</figure>" end end @@ -48,9 +56,11 @@ module OctopressFilters lang = $1 str = $2.gsub(/^\s{4}/, '') if lang != '' - highlight(str, lang) + code = highlight(str, lang) + "<figure role=code>#{code}</figure>" else - "<pre><code>#{$2.gsub('<','<').gsub('>','>')}</code></pre>" + code = tableize_code($2.gsub('<','<').gsub('>','>')) + "<figure role=code>#{code}</figure>" end end end @@ -58,7 +68,7 @@ module OctopressFilters # Replaces relative urls with full urls def expand_urls(input, url='') url ||= '/' - input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]+)/ do + input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]*)/ do $1+url+$3 end end diff --git a/plugins/pagination.rb b/plugins/pagination.rb new file mode 100644 index 00000000..a318754e --- /dev/null +++ b/plugins/pagination.rb @@ -0,0 +1,121 @@ +module Jekyll + + class Pagination < Generator + # This generator is safe from arbitrary code execution. + safe true + + # Generate paginated pages if necessary. + # + # site - The Site. + # + # Returns nothing. + def generate(site) + site.pages.dup.each do |page| + paginate(site, page) if Pager.pagination_enabled?(site.config, page) + end + end + + # Paginates the blog's posts. Renders the index.html file into paginated + # directories, e.g.: page2/index.html, page3/index.html, etc and adds more + # site-wide data. + # + # site - The Site. + # page - The index.html Page that requires pagination. + # + # {"paginator" => { "page" => <Number>, + # "per_page" => <Number>, + # "posts" => [<Post>], + # "total_posts" => <Number>, + # "total_pages" => <Number>, + # "previous_page" => <Number>, + # "next_page" => <Number> }} + def paginate(site, page) + all_posts = site.site_payload['site']['posts'] + pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i) + page_dir = page.destination('').sub(/\/[^\/]+$/, '') + page_dir_config = site.config['pagination_dir'] + dir = ((page_dir_config || page_dir) + '/').sub(/^\/+/, '') + + (1..pages).each do |num_page| + pager = Pager.new(site.config, num_page, all_posts, page_dir+'/', '/'+dir, pages) + if num_page > 1 + newpage = Page.new(site, site.source, page_dir, page.name) + newpage.pager = pager + newpage.dir = File.join(page.dir, "#{dir}page/#{num_page}") + site.pages << newpage + else + page.pager = pager + end + end + end + end + + class Pager + attr_reader :page, :per_page, :posts, :total_posts, :total_pages, :previous_page, :next_page + + # Calculate the number of pages. + # + # all_posts - The Array of all Posts. + # per_page - The Integer of entries per page. + # + # Returns the Integer number of pages. + def self.calculate_pages(all_posts, per_page) + (all_posts.size.to_f / per_page.to_i).ceil + end + + # Determine if pagination is enabled for a given file. + # + # config - The configuration Hash. + # file - The String filename of the file. + # + # Returns true if pagination is enabled, false otherwise. + def self.pagination_enabled?(config, file) + file.name == 'index.html' && !config['paginate'].nil? && file.content =~ /paginator\./ + end + + # Initialize a new Pager. + # + # config - The Hash configuration of the site. + # page - The Integer page number. + # all_posts - The Array of all the site's Posts. + # num_pages - The Integer number of pages or nil if you'd like the number + # of pages calculated. + def initialize(config, page, all_posts, index_dir, pagination_dir, num_pages = nil) + @page = page + @per_page = config['paginate'].to_i + @page_dir = pagination_dir + 'page/' + @total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page) + @previous_page = nil + + if @page > @total_pages + raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}" + end + + init = (@page - 1) * @per_page + offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1) + + @total_posts = all_posts.size + @posts = all_posts[init..offset] + @previous_page = @page != 1 ? @page_dir + (@page - 1).to_s + '/' : nil + @previous_page = index_dir if @page - 1 == 1 + @next_page = @page != @total_pages ? @page_dir + (@page + 1).to_s + '/' : nil + end + + # Convert this Pager's data to a Hash suitable for use by Liquid. + # + # Returns the Hash representation of this Pager. + def to_liquid + { + 'page' => page, + 'per_page' => per_page, + 'posts' => posts, + 'total_posts' => total_posts, + 'total_pages' => total_pages, + 'previous_page' => previous_page, + 'next_page' => next_page + } + end + end + +end + diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb index cdd6c3a4..67ce8c34 100644 --- a/plugins/pygments_code.rb +++ b/plugins/pygments_code.rb @@ -7,14 +7,12 @@ FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) module HighlightCode def highlight(str, lang) + lang = 'ruby' if lang == 'ru' + lang = 'objc' if lang == 'm' + lang = 'perl' if lang == 'pl' + lang = 'yaml' if lang == 'yml' str = pygments(str, lang).match(/<pre>(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '') #strip out divs <div class="highlight"> - table = '<div class="highlight"><table cellpadding="0" cellspacing="0"><tr><td class="gutter"><pre class="line-numbers">' - code = '' - str.lines.each_with_index do |line,index| - table += "<span class='line'>#{index+1}</span>\n" - code += "<div class='line'>#{line}</div>" - end - table += "</pre></td><td class='code' width='100%'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>" + tableize_code(str, lang) end def pygments(code, lang) @@ -31,4 +29,13 @@ module HighlightCode end highlighted_code end + def tableize_code (str, lang = '') + table = '<div class="highlight"><table cellpadding="0" cellspacing="0"><tr><td class="gutter"><pre class="line-numbers">' + code = '' + str.lines.each_with_index do |line,index| + table += "<span class='line'>#{index+1}</span>\n" + code += "<div class='line'>#{line}</div>" + end + table += "</pre></td><td class='code' width='100%'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>" + end end diff --git a/plugins/sitemap_generator.rb b/plugins/sitemap_generator.rb index 8b6cf78c..b63e9423 100644 --- a/plugins/sitemap_generator.rb +++ b/plugins/sitemap_generator.rb @@ -37,6 +37,7 @@ # Modified for Octopress by John W. Long # require 'rexml/document' +require 'fileutils' module Jekyll @@ -122,6 +123,9 @@ module Jekyll sitemap.add_element(urlset) # File I/O: create sitemap.xml file and write out pretty-printed XML + unless File.exists?(site.dest) + FileUtils.mkdir_p(site.dest) + end file = File.new(File.join(site.dest, SITEMAP_FILE_NAME), "w") formatter = REXML::Formatters::Pretty.new(4) formatter.compact = true |
