Blogging Basics
Octopress offers some rake tasks to create post and pages preloaded with metadata and according to Jekyll’s naming conventions.
Blog Posts
Blog posts must be stored in the source/_posts
directory and named according to Jekyll’s naming conventions: YYYY-MM-DD-post-title.markdown
. The name of the file will be used
as the url slug, and the date helps with file distinction and determines the sorting order for post loops.
Octopress provides a rake task to create new blog posts with the right naming conventions, with sensible yaml metadata.
Syntax
1
|
|
new_post
expects a naturally written title and strips out undesirable url characters when creating the filename.
The default file extension for new posts is markdown
but you can configure that in the Rakefile
.
Example
1 2 |
|
The filename will determine your url. With the default permalink settings the url would be something like
http://site.com/blog/20011/07/03/zombie-ninjas-attack-a-survivors-retrospective/index.html
.
Open a post in a text editor and you’ll see a block of yaml front matter which tells Jekyll how to processes posts and pages.
1 2 3 4 5 6 7 |
|
Here you can turn comments off and or categories to your post. If you are working on a multi-author blog, you can add author: Your Name
to the
metadata for proper attribution on a post. If you are working on a draft, you can add published: false
to prevent it from being posted when you generate your blog.
You can add a single category or multiple categories like this.
1 2 3 4 5 6 7 8 9 10 11 |
|
New Pages
You can add pages anywhere in your blog source directory and they’ll be parsed by Jekyll. The URL will correspond directly to the filepath, so about.markdown
will become site.com/about.html
. If you prefer the URL site.com/about/
you’ll want to create the page as about/index.markdown
.
Octopress has a rake task for creating new pages easily.
1 2 3 4 5 |
|
Like with the new post task, the default file extension is markdown
but you can configure that in the Rakefile
. A freshly generated page might look like this.
1 2 3 4 5 6 7 8 |
|
The title is derived from the filename so you’ll likely want to change that. This is very similar to the post yaml except it doesn’t include categories, and you can toggle sharing and comments or remove the footer altogehter. If you don’t want to show a date on your page, just remove it from the yaml.
Generate & Preview
1 2 3 |
|
Jekyll’s built in WEBrick server is handy, but if you’re a POW user, you can set it up to work with Octopress like this.
1 2 3 |
|
Now that you’re setup with POW, you’ll just run rake watch
and load up http://octopress.dev
instead.
Also see Sharing Code Snippets and Blogging with Plugins