--- layout: docs title: Writing posts prev_section: frontmatter next_section: drafts permalink: /docs/posts/ --- One of Jekyll’s best aspects is that it is “blog aware”. What does this mean, exactly? Well, simply put, it means that blogging is baked into Jekyll’s functionality. If you write articles and publish them online, this means that you can publish and maintain a blog simply by managing a folder of text-files on your computer. Compared to the hassle of configuring and maintaining databases and web-based CMS systems, this will be a welcome change! ## The Posts Folder As explained on the [directory structure](../structure/) page, the `_posts` folder is where your blog posts will live. These files can be either [Markdown](http://daringfireball.net/projects/markdown/) or [Textile](http://redcloth.org/textile) formatted text files, and as long as they have [YAML front-matter](../frontmatter/), they will be converted from their source format into an HTML page that is part of your static site. ### Creating Post Files To create a new post, all you need to do is create a new file in the `_posts` directory. How you name files in this folder is important. Jekyll requires blog post files to be named according to the following format: {% highlight bash %} YEAR-MONTH-DAY-title.MARKUP {% endhighlight %} Where `YEAR` is a four-digit number, `MONTH` and `DAY` are both two-digit numbers, and `MARKUP` is the file extension representing the format used in the file. For example, the following are examples of valid post filenames: {% highlight bash %} 2011-12-31-new-years-eve-is-awesome.md 2012-09-12-how-to-write-a-blog.textile {% endhighlight %}
Use the post_url
tag to link to other posts without having to worry about the URL's
breaking when the site permalink style changes.
Content processors can modify certain characters to make them look nicer.
For example, the smart
extension in Redcarpet converts standard,
ASCII quotation characters to curly, Unicode ones. In order for the browser
to display those characters properly, define the charset meta value by
including <meta charset="utf-8">
in the
<head>
of your layout.
You can skip the {% raw %}{{ site.url }}{% endraw %}
variable
if you know your site will only ever be displayed at the
root URL of your domain. In this case you can reference assets directly with
just /path/file.jpg
.
' | remove: '
' }}{% endraw %} {% endhighlight %} If you don't like the automatically-generated post excerpt, it can be overridden by adding `excerpt` to your post's YAML front-matter. Completely disable it by setting your `excerpt_separator` to `""`. Also, as with any output generated by Liquid tags, you can pass the `| strip_html` flag to remove any html tags in the output. This is particularly helpful if you wish to output a post excerpt as a `meta="description"` tag within the post `head`, or anywhere else having html tags along with the content is not desirable. ## Highlighting code snippets Jekyll also has built-in support for syntax highlighting of code snippets using either Pygments or Rouge, and including a code snippet in any post is easy. Just use the dedicated Liquid tag as follows: {% highlight text %} {% raw %}{% highlight ruby %}{% endraw %} def show @widget = Widget(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @widget } end end {% raw %}{% endhighlight %}{% endraw %} {% endhighlight %} And the output will look like this: {% highlight ruby %} def show @widget = Widget(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @widget } end end {% endhighlight %}
You can make code snippets include line-numbers by adding the word
linenos
to the end of the opening highlight tag like this:
{% raw %}{% highlight ruby linenos %}{% endraw %}
.