COOL STUFF |
---|
Written in Ruby |
Uses Markdown for content generation |
Integrates with GitHub Pages |
###What is Jekyll? Jekyll is a static site generator, written in Ruby. It renders static web pages from raw text/Markdown saved locally.
It was created by Tom Preston-Werner, co-founder of GitHub, and is
the engine behind GitHub Pages, a GitHub feature that allows users to host websites based on their GitHub repositories.
###Using Jekyll
- Install Jekyll with
gem install jekyll
- Generate a Jekyll project with
jekyll new project
whereproject
is the name of the site or blog being created - Change directories into the new project directory
- Jekyll has a built in development server for previewing the rendered site
jekyll serve
- defaults to
localhost:4000
--watch
automatically reload the server when it detects changes to the project. NOTE: changes to_config.yml
require a manual server restart (explanation)--detach
will run the server in a background process, effectively freeing up the terminal session for other use. To kill the server process usekill -9 PID
wherePID
is the process ID of the Jekyll server. The process ID can be found with thetop
command or in the last line of console output from the server.
- defaults to
###Directory Structure
├── _config.yml
├── _drafts
| ├── begin-with-the-crazy-ideas.md
| └── on-simplicity-in-technology.md
├── _includes
| ├── footer.html
| └── header.html
├── _layouts
| ├── default.html
| └── post.html
├── _posts
| ├── 2007-10-29-why-every-programmer-should-play-nethack.md
| └── 2009-04-26-barcamp-boston-4-roundup.md
├── _data
| └── members.yml
├── _site
└── index.html
###How It Works _config.yml (excerpt)
# Site settings
title: Amazing Blog
email: [email protected]
description: "Very Amazing Blog"
baseurl: ""
url: "http://amazingblog.com"
-
SOME FUN YAML FACTS
- YAML is a recursive acronym meaning "YAML Ain't Markup Language"
- JSON is derived from YAML 1.2
-
YAML is a "human readable data-serialization format". Key-value pairs defined within the Site settings in
_config.yml
are available throughout the site as variables - for examplesite.title
returns"Amazing Blog"
with the above configuration. -
The Liquid Templating Language is used to process templates. Variables within double-curly braces are evaluated and then rendered to the page - for example
{{site.description}}
-
Similar to Rails, Jekyll creates layouts that will be used to frame content on the site. Layouts are stored within
_layouts
. Partials are also used to DRY up pages. Partials are stored within_includes
. -
Inside the
_posts
directory, individual Markdown files represent unique posts, or pages, of the site. Content is written as Markdown and rendered to HTML by Jeckyll when the site is "built" -
Filenames for posts must follow the specified format:
YEAR-MONTH-DATE-title.md
for example2014-06-27-school-is-over.md
. -
At the top of each post is a YAML Front-Matter block.
--- layout: post title: Blogging Like a Hacker ---
Any file that contains a YAML front matter block will be processed by Jekyll as a special file. The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines. This is also where predefined variables can be set, as in
layout: post
which specifies that thepost.html
layout will be used with this content. Custom variables defined here are accessed with Liquid tags on this page, or any page requires it.
-
Syntax Highlighting - Jekyll has support for syntax highlighting using the Rouge gem.
{% highlight ruby %} def foo puts 'foo' end {% endhighlight %}
Surround code snippets with {% highlight %}
and {% endhighlight %}
tags and pass in a language, as above.
###Build A Site
- Generate static version of the site with
jekyll build
--destination <destination path>
specifies directory for generator output
- Change directories to destination path
- Initialize new git repository, add files, and commit changes
###GitHub Pages
- Create a new GitHub repository. When using GitHub pages, name of repository must be
username.github.io
where "username" is GitHub username - Add this repository as a remote of the local repository
- Push changes
- visit
http://username.github.io
to see your site - Pushing future commits to the remote repository will instantly update the site
##Resources