Create Custom Description for Your Jekyll Posts
There are two ways to create a description from your post, the first one is use the existing post.excerpt
tag Jekyll has after reading Jekyll documentation or create your own with some simple steps.
The general idea is to create a custom page variable in your posts and use it in your layouts.
For our example we ‘ll call our variable post_description
, at least that’s what I am using for my blog, and give it a value in my markdown post:
and in my default.html or any other place I want to use it instead of post.excerpt
, now I can use post.post_description
and that’s it.
You can use these page values anywhere you want. For instance I am using this for creating meta tags for description and keywords in my <head>
tag. You can take a peak in my github repository for this site.
You can add and image for your facebook og tags or anything else you can think of.
Update: As Emilio Lopez correctly mentioned in the comments you can declare post_excerpt in the page variables too.
The truth is I prefer extending things than overwriting default environment variables but this is in the Jekyll documentation so, it’s safe. (Thanks Emilio!)