Once you became to have a lot of posts, Octopress’ rake generate
command could take a long time.
When you want to check your site, normally it is needed to build only your new post.
While Octopress has tasks of isolate/integrate to achieve such usage,
it needs some manual commands, and there is a risk to push your site with only a new post.
In this post, I will introduce how to speed up rake generate
with an easy command, and in safety.
isolate/integrate update
rake isolate[my-post] command stashes all posts other than my-post
from source/_post directory.
They are stashed in source/_stash, which are not used for a build,
so that Jekyll command builds only my-post.
After checking your site, you can revert them by rake integrate.
But there are some difficulties:
- You need some commands to build one time for a check.
- In addition, you need to give a name of a post.
- You may
deployyour site only with a new post. isolatecommand doesn’t move a directory in _post directory.- I put my old posts in such source/_post/y_2014, because Octopress (Jekyll) manages these posts under subdirectories as same as posts under source/_post.
- Pages are not stashed.
To solve them, I modified Rakefile as below for isolate/integrate tasks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
First, new variables full_stash_dir, stash_root_dir, full_stash_root_dir
and root_stashes are added.
full_stash_dir is introduced because in Octopress’ Rakefile
overwrites stash_dir values in isolate task,
so that it will fail if we use isolate and integrate in a sequence.
With above modifications of isolate/integrate, it is actually not needed,
but use them just for making paths clear.
stash_root_dir is used for pages instead of posts.
(Pages are normally in a root directory (source/).)
full_stash_root_dir is full path name for stash_root_dir.
And root_stashes are what you want to stash in isolate task.
Above setting will move source/Your-Page in source/_stash_root
in isolate task.
You can give multiple pages as an array.
Next, isolate task is now able to select the last modified post automatically
if you don’t give a post name.
The posts are sorted by mtime (modified time) and the last one is used.
mv command loop was modified to move all files/directories in source/_post directory.
In addition, it moves pages listed in root_stashes in source/.
In the last of isolate task, it makes .isolated file
in Octopress’ top directory.
It is used in deploy command to check if files are isolated or not.
(see below).
integrated task now moves files/directories in full_stash_root_dir, too.
In addition, it deletes .isolated, and makes .integrated.
It is used in deploy command, too.
generate_only command
Then, make a task which build only one post automatically.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
Here, rake generate_only task executes isolate, generate (compass/jekyll)
and integrate.
gen_only and go are aliases for generate_only.
Now you can generate only your new post with
$ rake generate_only["my-latest-post"]
or
$ rake generate_only
for the last modified post. You can even use:
$ rake go
as same as rake generate_only.
Similar settings can be used for watch and preview:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
Assure full build
In deploy task,
it should assure that you built with all files w/o stashed files.
In Octopress’ Rakefile, there is a similar method
using .preview-mode file, which is made in preview or watch tasks
1
In below, deploy task checks .integrated or .isolated files,
and re-generates after integrate if there is one of these files.
In addition, generate task deletes .integrated (and .preview-mode)
as full files build are done at that point.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
Then, you can safely use rake generate_only command.
These modifications can be seen in Octogray theme:
Note: currently .preview-mode is remained only in
deploytask. It was somehow removed fromprevieworwatchtasks. So it checks indeploy, but the file is not created inprevieworwatch, it is meaningless. ↩
