Permalink
Browse files

make faster posts regenaration with pygments caching and lsi just on …

…deployment
  • Loading branch information...
rsim committed Aug 9, 2010
1 parent 175457a commit bd4d383bf09c0543c9ac1f4ec3f50cb57c4e03ed
Showing with 29 additions and 3 deletions.
  1. +2 −1 .gitignore
  2. +1 −1 Rakefile
  3. +0 −1 _config.yml
  4. +26 −0 _plugins/pygments_cache_patch.rb
View
@@ -1,3 +1,4 @@
+_cache/
_drafts/
_site/
-tags
+tags/
View
@@ -5,7 +5,7 @@ end
desc "Build site using Jekyll"
task :build => :tags do
- jekyll
+ jekyll("--lsi")
end
desc "Serve on Localhost with port 4000"
View
@@ -2,4 +2,3 @@ markdown: rdiscount
pygments: true
permalink: /:year/:month/:day/:title/
exclude: Rakefile README.textile
-lsi: true
@@ -0,0 +1,26 @@
+require 'fileutils'
+require 'digest/md5'
+
+PYGMENTS_CACHE_DIR = File.expand_path('../../_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

0 comments on commit bd4d383

Please sign in to comment.