diff options
-rw-r--r-- | .themes/classic/sass/partials/_blog.scss | 5 | ||||
-rw-r--r-- | .themes/classic/sass/partials/_syntax.scss | 3 | ||||
-rw-r--r-- | .themes/classic/source/_includes/article.html | 9 | ||||
-rw-r--r-- | .themes/classic/source/_includes/head.html | 3 | ||||
-rw-r--r-- | .themes/classic/source/_layouts/page.html | 2 | ||||
-rw-r--r-- | .themes/classic/source/index.html | 10 | ||||
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 2 | ||||
-rw-r--r-- | Rakefile | 31 | ||||
-rw-r--r-- | _config.yml | 7 | ||||
-rw-r--r-- | plugins/category_generator.rb | 3 | ||||
-rw-r--r-- | plugins/code_block.rb | 12 | ||||
-rw-r--r-- | plugins/include_code.rb | 11 | ||||
-rw-r--r-- | plugins/octopress_filters.rb | 20 | ||||
-rw-r--r-- | plugins/pagination.rb | 121 | ||||
-rw-r--r-- | plugins/pygments_code.rb | 21 |
16 files changed, 207 insertions, 54 deletions
diff --git a/.themes/classic/sass/partials/_blog.scss b/.themes/classic/sass/partials/_blog.scss index 8d9d5f80..3416347b 100644 --- a/.themes/classic/sass/partials/_blog.scss +++ b/.themes/classic/sass/partials/_blog.scss @@ -51,14 +51,15 @@ article { @include box-shadow(rgba(#000, .15) 0 1px 4px); @include box-sizing(border-box); display: block; - margin: 0 auto 1.5em; } img { &.left { float: left; margin-right: 1.5em; } &.right { float: right; margin-left: 1.5em; } + &.center { margin: 0 auto 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/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/_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/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> @@ -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..55634060 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,6 +40,7 @@ GEM blankslate (>= 2.1.2.3) ffi (~> 1.0.7) sass (3.1.5) + 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]" @@ -52,7 +55,7 @@ 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" + system "trap 'kill $jekyllPid $compassPid $rackPid' Exit; jekyll --auto & jekyllPid=$!; compass watch & compassPid=$!; rackup --port #{server_port} & rackPid=$!; wait" end # usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post") @@ -61,7 +64,7 @@ task :new_post, :title do |t, args| require './plugins/titlecase.rb' 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}" puts "Creating new post: #{filename}" open(filename, 'w') do |post| system "mkdir -p #{source_dir}/#{posts_dir}"; @@ -121,7 +124,7 @@ end desc "Clean out caches: _code_cache, _gist_cache, .sass-cache" task :clean do - system "rm -rf _code_cache/** _gist_cache/** .sass-cache/**" + system "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" @@ -150,6 +153,8 @@ task :update_source, :theme do |t, args| 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/" + system "mv -f #{source_dir}/index.html #{blog_index_dir}" if blog_index_dir != source_dir + system "cp -f #{source_dir}.old/index.html #{source_dir}" if blog_index_dir != source_dir puts "## Updated #{source_dir} ##" end @@ -251,6 +256,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 9a48c018..00dc8aa4 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..aa1180e1 100644 --- a/plugins/category_generator.rb +++ b/plugins/category_generator.rb @@ -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(/_|\W/, '-')}/'>#{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 |