jekyll
Version:
A blog-aware, static site generator in Ruby
198 lines (187 loc) • 4.64 kB
Markdown
---
layout: docs
title: Permalinks
permalink: /docs/permalinks/
---
Jekyll supports a flexible way to build your site’s URLs. You can specify the
permalinks for your site through the [Configuration](../configuration/) or in the
[YAML Front Matter](../frontmatter/) for each post. You’re free to choose one of
the built-in styles to create your links or craft your own. The default style is
`date`.
Permalinks are constructed by creating a template URL where dynamic elements are
represented by colon-prefixed keywords. For example, the default `date`
permalink is defined as `/:categories/:year/:month/:day/:title.html`.
## Template variables
<div class="mobile-side-scroller">
<table>
<thead>
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p><code>year</code></p>
</td>
<td>
<p>Year from the Post’s filename</p>
</td>
</tr>
<tr>
<td>
<p><code>month</code></p>
</td>
<td>
<p>Month from the Post’s filename</p>
</td>
</tr>
<tr>
<td>
<p><code>i_month</code></p>
</td>
<td>
<p>Month from the Post’s filename without leading zeros.</p>
</td>
</tr>
<tr>
<td>
<p><code>day</code></p>
</td>
<td>
<p>Day from the Post’s filename</p>
</td>
</tr>
<tr>
<td>
<p><code>i_day</code></p>
</td>
<td>
<p>Day from the Post’s filename without leading zeros.</p>
</td>
</tr>
<tr>
<td>
<p><code>short_year</code></p>
</td>
<td>
<p>Year from the Post’s filename without the century.</p>
</td>
</tr>
<tr>
<td>
<p><code>title</code></p>
</td>
<td>
<p>Title from the Post’s filename</p>
</td>
</tr>
<tr>
<td>
<p><code>categories</code></p>
</td>
<td>
<p>
The specified categories for this Post. If a post has multiple
categories, Jekyll will create a hierarchy (e.g. <code>/category1/category2</code>).
Also Jekyll automatically parses out double slashes in the URLs,
so if no categories are present, it will ignore this.
</p>
</td>
</tr>
</tbody>
</table>
</div>
## Built-in permalink styles
**Note:** these may only apply to posts, not to pages, collections or
static files. For example, `pretty` changes page permalinks from
`/:path/:basename:output_ext` to `/:page/:basename/` if the page is HTML,
thus "prettyifying" the page permalink. The `date`, `none`, and all custom
values do not apply to pages. No permalink style applies to static files,
and collections have their own means of specifying permalinks. It's all
rather confusing but check out [Issue #2691](https://github.com/jekyll/jekyll/issues/2691)
for more background on the subject, and submit a PR if you're adventurous
enough to fix it all!
<div class="mobile-side-scroller">
<table>
<thead>
<tr>
<th>Permalink Style</th>
<th>URL Template</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p><code>date</code></p>
</td>
<td>
<p><code>/:categories/:year/:month/:day/:title.html</code></p>
</td>
</tr>
<tr>
<td>
<p><code>pretty</code></p>
</td>
<td>
<p><code>/:categories/:year/:month/:day/:title/</code></p>
</td>
</tr>
<tr>
<td>
<p><code>none</code></p>
</td>
<td>
<p><code>/:categories/:title.html</code></p>
</td>
</tr>
</tbody>
</table>
</div>
## Permalink style examples
Given a post named: `/2009-04-29-slap-chop.md`
<div class="mobile-side-scroller">
<table>
<thead>
<tr>
<th>URL Template</th>
<th>Resulting Permalink URL</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>None specified, or <code>permalink: date</code></p>
</td>
<td>
<p><code>/2009/04/29/slap-chop.html</code></p>
</td>
</tr>
<tr>
<td>
<p><code>pretty</code></p>
</td>
<td>
<p><code>/2009/04/29/slap-chop/index.html</code></p>
</td>
</tr>
<tr>
<td>
<p><code>/:month-:day-:year/:title.html</code></p>
</td>
<td>
<p><code>/04-29-2009/slap-chop.html</code></p>
</td>
</tr>
<tr>
<td>
<p><code>/blog/:year/:month/:day/:title</code></p>
</td>
<td>
<p><code>/blog/2009/04/29/slap-chop/index.html</code></p>
</td>
</tr>
</tbody>
</table>
</div>