diff options
author | Brandon Mathis <brandon@imathis.com> | 2011-07-19 09:06:54 -0400 |
---|---|---|
committer | Brandon Mathis <brandon@imathis.com> | 2011-07-19 09:06:54 -0400 |
commit | 17c59fb1d1bf3e0c05137af4b4bd09ae271a2d31 (patch) | |
tree | a4b3b5d43173f9b02ec4b6401cb6e14f6e716a35 /plugins/pygments_cache_patch.rb | |
parent | 873a604e144c53cfc5465a790e43db5b7ebb429e (diff) | |
download | my_new_personal_website-17c59fb1d1bf3e0c05137af4b4bd09ae271a2d31.tar.xz my_new_personal_website-17c59fb1d1bf3e0c05137af4b4bd09ae271a2d31.zip |
Moved plugins to root directory. I'm ditching the idea of shipping plugins with themes until it's more obviously necessary. This way it's easier to merge and update plugins.
Diffstat (limited to 'plugins/pygments_cache_patch.rb')
-rw-r--r-- | plugins/pygments_cache_patch.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/plugins/pygments_cache_patch.rb b/plugins/pygments_cache_patch.rb new file mode 100644 index 00000000..09c09840 --- /dev/null +++ b/plugins/pygments_cache_patch.rb @@ -0,0 +1,30 @@ +# +# Author: Raimonds Simanovskis, http://blog.rayapps.com/ +# Source URL: https://github.com/rsim/blog.rayapps.com/blob/master/_plugins/pygments_cache_patch.rb +# + +require 'fileutils' +require 'digest/md5' + +PYGMENTS_CACHE_DIR = File.expand_path('../../_code_cache', __FILE__) +FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) + +Jekyll::HighlightBlock.class_eval do + def render_pygments(context, code) + if defined?(PYGMENTS_CACHE_DIR) + path = File.join(PYGMENTS_CACHE_DIR, "#{@lang}-#{Digest::MD5.hexdigest(code)}.html") + if File.exist?(path) + highlighted_code = File.read(path) + else + highlighted_code = Albino.new(code, @lang).to_s(@options) + File.open(path, 'w') {|f| f.print(highlighted_code) } + end + else + highlighted_code = Albino.new(code, @lang).to_s(@options) + end + output = add_code_tags(highlighted_code, @lang) + output = context["pygments_prefix"] + output if context["pygments_prefix"] + output = output + context["pygments_suffix"] if context["pygments_suffix"] + output + end +end |