diff --git a/.gitignore b/.gitignore index 990b0a0..9413ba3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ .bundle .DS_Store .sass-cache -.gist_cache -_cache +_gist_cache +_code_cache _assets public source/_stash diff --git a/_config.yml b/_config.yml index 650ab27..0e50cab 100644 --- a/_config.yml +++ b/_config.yml @@ -1,16 +1,17 @@ # Required configuration source: source destination: public +code_dir: downloads/code port: 4000 -url: http://yoursite.com +url: http://octopress.dev title: My Octopress Blog subtitle: A blogging framework for hackers. author: Your Name subscribe_rss: /atom.xml subscribe_email: http://feedburner.com/asdfasdf -markdown: rdiscount +#markdown: rdiscount pygments: true recent_posts: 1 simple_search: http://google.com/search diff --git a/themes/classic/_plugins/blockquote.rb b/themes/classic/_plugins/blockquote.rb index 21ebc5d..8048f47 100644 --- a/themes/classic/_plugins/blockquote.rb +++ b/themes/classic/_plugins/blockquote.rb @@ -1,21 +1,20 @@ # -# Author: Josediaz Gonzalez - https://github.com/josegonzalez -# Source URL: https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/blockquote.rb -# Modified by Brandon Mathis removed pullquotes and added simple cite paramaters +# Author: Brandon Mathis +# Based on the work of: Josediaz Gonzalez - https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/blockquote.rb # require './_plugins/titlecase.rb' module Jekyll # Outputs a string with a given attribution as a quote # - # {% blockquote John Paul Jones %} - # Monkeys! + # {% blockquote Bobby Willis http://google.com/blah the search for bobby's mom %} + # Wheeee! # {% endblockquote %} # ... #
- # Monkeys! - #
- # John Paul Jones + #

Wheeee!

+ #
# class Blockquote < Liquid::Block @@ -42,15 +41,16 @@ module Jekyll def render(context) output = super - if @by.nil? - '

' + output.join + '

' - elsif !@title.nil? - '

' + output.join + '

' + '

' + @by + '' + '' + @title + '

' + author = "#{@by}" + cite = "#{(@title || 'source')}" + reply = if @by.nil? + "

#{output.join.gsub(/\n\n/, '

')}

" elsif !@source.nil? - '

' + output.join + '

' + '

' + @by + '' + 'source

' + "

#{output.join.gsub(/\n\n/, '

')}

" else - '

' + output.join + '

' + '

' + @by + '

' + "

#{output.join.gsub(/\n\n/, '

')}

" end + "
#{reply}
" end end end diff --git a/themes/classic/_plugins/gist_tag.rb b/themes/classic/_plugins/gist_tag.rb index 1f37416..0a8797f 100644 --- a/themes/classic/_plugins/gist_tag.rb +++ b/themes/classic/_plugins/gist_tag.rb @@ -1,9 +1,11 @@ -# Nicked from Brandon Tilly -# Gist https://gist.github.com/803483 +# A Liquid tag for Jekyll sites that allows embedding Gists and showing code for non-JavaScript enabled browsers and readers. +# by: Brandon Tilly +# Source URL: https://gist.github.com/1027674 # Post http://brandontilley.com/2011/01/31/gist-tag-for-jekyll.html # -# Example usage: {% gist 803483 gist_tag.rb %} //embeds a gist for this plugin +# Example usage: {% gist 1027674 gist_tag.rb %} //embeds a gist for this plugin +require 'cgi' require 'digest/md5' require 'net/https' require 'uri' @@ -12,60 +14,70 @@ module Jekyll class GistTag < Liquid::Tag def initialize(tag_name, text, token) super - system('mkdir -p .gist_cache') - @text = text - @cache = true - @cache_folder = File.expand_path "../.gist_cache", File.dirname(__FILE__) + @text = text + @cache_disabled = false + @cache_folder = File.expand_path "../_gist_cache", File.dirname(__FILE__) + FileUtils.mkdir_p @cache_folder end def render(context) - return "" unless @text =~ /([\d]*) (.*)/ + if parts = @text.match(/([\d]*) (.*)/) + gist, file = parts[1].strip, parts[2].strip + script_url = script_url_for gist, file + code = get_cached_gist(gist, file) || get_gist_from_web(gist, file) + html_output_for script_url, code + else + "" + end + end - gist, file = $1.strip, $2.strip - script_url = "https://gist.github.com/#{gist}.js?file=#{file}" + def html_output_for(script_url, code) + code = CGI.escapeHTML code + <<-HTML + + + HTML + end - code = get_cached_gist(gist, file) || get_gist_from_web(gist, file) - code = code.gsub "<", "<" - string = "" - string += "" - return string + def script_url_for(gist_id, filename) + "https://gist.github.com/#{gist_id}.js?file=#{filename}" end def get_gist_url_for(gist, file) - "https://gist.github.com/raw/#{gist}/#{file}" + "https://raw.github.com/gist/#{gist}/#{file}" end - def cache_gist(gist, file, data) - file = get_cache_file_for gist, file - File.open(file, "w+") do |f| - f.write(data) + def cache(gist, file, data) + cache_file = get_cache_file_for gist, file + File.open(cache_file, "w") do |io| + io.write data end end def get_cached_gist(gist, file) - return nil if @cache == false - file = get_cache_file_for gist, file - return nil unless File.exist?(file) - return File.new(file).readlines.join + return nil if @cache_disabled + cache_file = get_cache_file_for gist, file + File.read cache_file if File.exist? cache_file end def get_cache_file_for(gist, file) - gist.gsub! /[^a-zA-Z0-9\-_\.]/, '' - file.gsub! /[^a-zA-Z0-9\-_\.]/, '' - md5 = Digest::MD5.hexdigest "#{gist}-#{file}" + bad_chars = /[^a-zA-Z0-9\-_.]/ + gist = gist.gsub bad_chars, '' + file = file.gsub bad_chars, '' + md5 = Digest::MD5.hexdigest "#{gist}-#{file}" File.join @cache_folder, "#{gist}-#{file}-#{md5}.cache" end def get_gist_from_web(gist, file) - gist_url = get_gist_url_for(gist, file) - raw_uri = URI.parse(gist_url) - https = Net::HTTP.new(raw_uri.host, raw_uri.port) + gist_url = get_gist_url_for gist, file + raw_uri = URI.parse gist_url + https = Net::HTTP.new raw_uri.host, raw_uri.port https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE - request = Net::HTTP::Get.new(raw_uri.request_uri) - data = https.request(request) + request = Net::HTTP::Get.new raw_uri.request_uri + data = https.request request data = data.body - cache_gist(gist, file, data) unless @cache == false + cache gist, file, data unless @cache_disabled data end end @@ -73,11 +85,10 @@ module Jekyll class GistTagNoCache < GistTag def initialize(tag_name, text, token) super - @cache = false + @cache_disabled = true end end end Liquid::Template.register_tag('gist', Jekyll::GistTag) Liquid::Template.register_tag('gistnocache', Jekyll::GistTagNoCache) - diff --git a/themes/classic/_plugins/include_code.rb b/themes/classic/_plugins/include_code.rb new file mode 100644 index 0000000..fa5c76f --- /dev/null +++ b/themes/classic/_plugins/include_code.rb @@ -0,0 +1,40 @@ +require 'pathname' + +module Jekyll + + class IncludeCodeTag < Liquid::Tag + def initialize(tag_name, file, tokens) + super + @file = file.strip + end + + def render(context) + code_dir = (context.registers[:site].config['code_dir'] || 'downloads/code') + code_path = (Pathname.new(context.registers[:site].source) + code_dir).expand_path + file = code_path + @file + + if File.symlink?(code_path) + return "Code directory '#{code_path}' cannot be a symlink" + end + + unless file.file? + return "File #{file} could not be found" + end + + Dir.chdir(code_path) do + code = file.read + file_type = file.extname + url = "#{context.registers[:site].config['url']}/#{code_dir}/#{@file}" + source = "
#{file.basename}download
\n" + source += "{% highlight #{file_type} %}\n" + code + "\n{% endhighlight %}
" + partial = Liquid::Template.parse(source) + context.stack do + partial.render(context) + end + end + end + end + +end + +Liquid::Template.register_tag('include_code', Jekyll::IncludeCodeTag) diff --git a/themes/classic/_plugins/pygments_cache_patch.rb b/themes/classic/_plugins/pygments_cache_patch.rb index 36c78d2..09c0984 100644 --- a/themes/classic/_plugins/pygments_cache_patch.rb +++ b/themes/classic/_plugins/pygments_cache_patch.rb @@ -6,7 +6,7 @@ require 'fileutils' require 'digest/md5' -PYGMENTS_CACHE_DIR = File.expand_path('../../_cache', __FILE__) +PYGMENTS_CACHE_DIR = File.expand_path('../../_code_cache', __FILE__) FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) Jekyll::HighlightBlock.class_eval do