Created
April 5, 2012 05:19
-
-
Save arika/2308202 to your computer and use it in GitHub Desktop.
improve process time of octopress/jekyll (2nd)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # based lib/jekyll/site.rb of jekyll 0.11.0 | |
| module Jekyll | |
| class Site | |
| class PostList < Array | |
| def sort | |
| self.class.new(super) | |
| end | |
| def next(obj) | |
| setup_index_cache | |
| neighbor(obj, :next) | |
| end | |
| def previous(obj) | |
| setup_index_cache | |
| neighbor(obj, :previous) | |
| end | |
| private | |
| def setup_index_cache | |
| return if @index_cache | |
| @index_cache = {} | |
| each_with_index do |obj, i| | |
| hash = @index_cache[obj.object_id] = { | |
| :previous => i - 1, | |
| :next => i + 1, | |
| } | |
| hash[:previous] = nil if hash[:previous] < 0 | |
| hash[:next] = nil if hash[:next] == length | |
| end | |
| end | |
| def neighbor(obj, dir) | |
| setup_index_cache | |
| hash = @index_cache[obj.object_id] || {} | |
| hash[dir] ? self[hash[dir]] : nil | |
| end | |
| end | |
| alias reset_without_posts_hack reset | |
| def reset | |
| reset_without_posts_hack | |
| self.posts = PostList.new | |
| end | |
| alias render_without_cache render | |
| def render | |
| @site_payload = nil | |
| render_without_cache | |
| end | |
| alias site_payload_without_cache site_payload | |
| def site_payload | |
| unless @site_payload | |
| @site_payload = site_payload_without_cache | |
| end | |
| {}.deep_merge(@site_payload) | |
| end | |
| end | |
| class Post | |
| def next | |
| self.site.posts.next(self) | |
| end | |
| def previous | |
| self.site.posts.previous(self) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment