Getting Started with Jekyll
What is Jekyll?
Jekyll is a static site generator. It takes your content, renders Markdown and Liquid templates, and spits out a complete, static website ready to be served by Apache, Nginx or another web server. You can even host your site for free on GitHub Pages.
what language is jekyll written in?
Jekyll is written in Ruby.
Installing ruby
Windows
- Download and install Ruby+Devkit.
- Run
ridk installto install the Devkit and install all components. - To check if ruby is installed, run
ruby -vandgem -vin the command prompt.
Note: If ruby is not recognized as a command, you may need to add the ruby bin directory to your PATH environment variable.
- Go to
ruby/bindirectory, by default it isC:\Ruby27-x64\binif you installed it in the default directory. Copy the path. - Open the Control Panel, click System and Security, then click System.
- Click Advanced system settings on the left and then click Environment Variables.
- Under System variables, click Path, then click Edit.
- Click New and paste the path you copied earlier.
- Click OK to save the change.
Installing Jekyll
- Run
gem install jekyll bundlerto install Jekyll and Bundler. - Run
jekyll -vto check if Jekyll is installed.
Jekyll Structure
1./
2├── _config.yml
3├── _drafts/
4│ ├── begin-with-the-crazy-ideas.textile
5│ └── on-simplicity-in-technology.markdown
6├── _includes/
7│ ├── footer.html
8│ └── header.html
9├── _layouts/
10│ ├── default.html
11│ └── post.html
12├── _posts/
13│ ├── 2007-10-29-why-every-programmer-should-play-nethack.textile
14│ └── 2009-04-26-barcamp-boston-4-roundup.textile
15├── _data/
16│ └── members.yml
17├── _site/
18└── index.html
How to create a new post in jekyll?
- Create a new file in
_postsdirectory. - The file name must be in the format
YYYY-MM-DD-title.md. - Add the following front matter to the top of the file:
1---
2title: "Title of the post"
3date: YYYY-MM-DD HH:MM:SS +/-TTTT
4tags:
5 - tag1
6 - tag2
7category: category
8keywords:
9 - keyword1
10 - keyword2
11---
- Write the post in markdown.
what is markdown?
Markdown is a lightweight markup language with plain text formatting syntax. It is designed so that it can be converted to HTML and many other formats using a tool by the same name.
Creating a new Jekyll site
- Run
jekyll new my-awesome-siteto create a new Jekyll site. - Run
cd my-awesome-siteto go to the site directory. - Run
bundle exec jekyll serveto start the Jekyll server. - Open
http://localhost:4000in your browser to see the site.
Creating a new post
-
Run
bundle exec jekyll post "My New Post"to create a new post. -
Open the post file in your text editor.
-
Add the following front matter to the top of the file:
1--- 2title: My New Post 3date: 2019-04-03 17:51:42 4tags: 5 - tag1 6 - tag2 7category: category 8keywords: 9 - keyword1 10 - keyword2 11--- -
Write your post in Markdown.
-
Save the file.
-
Run
bundle exec jekyll serveto start the Jekyll server. -
Open
http://localhost:4000in your browser to see the site.Notes:
- If you want to use a different date for the post, you can use the
--dateoption when creating the post. For example,bundle exec jekyll post "My New Post" --date 2019-04-03. - If you want to use a different port, you can use the
--portoption when starting the server. For example,bundle exec jekyll serve --port 3000.
- If you want to use a different date for the post, you can use the
Creating a new page
- Run
bundle exec jekyll page "My New Page"to create a new page. - Open the page file in your text editor.
- Add the following front matter to the top of the file:
1---
2title: My New Page
3date: 2019-04-03 17:51:42
4tags:
5 - tag1
6 - tag2
7category: category
8keywords:
9 - keyword1
10 - keyword2
11---
-
Write your page in Markdown.
Note: If you want to create a page that is not in the navigation menu, add
nav_exclude: trueto the front matter. -
Save the file.
-
Run
bundle exec jekyll serveto start the Jekyll server. -
Open
http://localhost:4000in your browser to see the site.
Questions
- Is it possible to serve multiple Jekyll sites locally?
Yes, you can use the
--portoption to serve multiple sites on different ports. For example,bundle exec jekyll serve --port 3000will serve the site on port 3000. You can then serve another site on port 4000 by runningbundle exec jekyll serve --port 4000.
reference: stackoverflow question by Brian Zelip
Jekyll cheatsheet and documentation
reference: