12/08/2018, 14:36

Writing a blog for a hosting on GitHub

For blogging There are many excellent solutions. Of all the existing platforms for blogs (engines, services, generators) Jekyll seemed to me the most stand out because of their advantages. Now I will tell you about blogging platform on Github. So what is a Jekyll - is a system generating ...

For blogging There are many excellent solutions. Of all the existing platforms for blogs (engines, services, generators) Jekyll seemed to me the most stand out because of their advantages. Now I will tell you about blogging platform on Github.

GitHub Jekyll

So what is a Jekyll - is a system generating static websites, has template engine written in Ruby, and focused on the creation of static content for the blog. The main feature: is used on Github Pages, which allows you to keep the original blog code repository on Github - and some of its caching server within 10 minutes after the commit will collect and display to visitors in the form of a full HTML pages with your styles and javascript code.

Why I chose Jekyll?

Advantages:

  • Simplicity - Jekyll reduces everything to an absolute minimum by getting rid of complex components:
    • No database - Unlike other content management systems (CMS), Jekyll does not use a database (DB). All pages before publishing are converted to static HTML. This is fine in terms of page loading speed as during startup does not occur to the database query.
    • No CMS - Write in Markdown, Jekyll will generate a static site. On GitHub, you can edit the content of pages, even if you do not have your PC on hand with a customized work environment.
    • Fast, very fast, because the static. No databases, dynamic logic - all pages are ready for display and are on GitHub servers with excellent performance time of return pages.
    • Minimalistic - Most sites on Jekyll contains no extra functionality or features that you do not use.
  • Control of view - Spend less time on complex patterns written by other people, and more - by adapting simple basic template or create your own.
  • Absolute safety - Most of the vulnerabilities that have CMS, are absent in the Jekyll, because there is not any CMS database or an interpreted language, the code of which may contain vulnerabilities. So you do not need to spend a lot of time installing updates that close security holes.
  • Reliable and user-friendly web hosting - It's just convenient if you are already using the GitHub, that's all. GitHub Pages free will collect and publish the site using Jekyll, and simultaneously implements version control.

Disadvantages:

  • To hide the source code of your site need a paid account

Where to begin?

There are several ways to get started with Jekyll, each has its own peculiarities. Here are some options:

  • Install Jekyll locally using the console, create a new blank site by console command jekyll new, gather its by console command jekyll build and place. (Website Jekyll shows the process.)
  • Clone the repository with the workpiece on the local machine, set Jekyll locally from the console, make changes, collect locally, put on GitHub.
  • Fork the repository with the workpiece, change the code, put on GitHub.

Let's start with the most simple and quick options: will fork the repository with the workpiece. This will run the project in a matter of minutes, and we do not have to install all of the dependencies. The best example for a quick start seemed to me that's the repository

Placing of your blog on GitHub

As a user of the GitHub, you can create a free "custom" sites (in contrast to the "Project" web site), which will be available at http://yourusername.github.io. Ideal for placing a blog on Jekyll! The best thing about this is that you simply place the Jekyll-blog on the master branch, then GitHub Pages himself will collect static website and will distribute it. You do not need to worry about the assembly process - this is already taken care of.

Click «Settings» (right menu) in the repository of fork and change the name of the repository to yourusername.github.io, replace yourusername with your username on GitHub. Most likely, the site will be available immediately, this can be checked by opening http://yourusername.github.io. If not yet available - do not worry, then we'll find out how to force a build.

Important ! You must understand the difference between placing on GitHub user of the site and the project page. For a user site do not need to create any branches: master branch is already configured as necessary to handle with the help of Jekyll everything in it is placed and create a static site. There is no need to create a branch gh-pages

Note: for Jekyll there is a large number of plug-ins, but GitHub Pages supports only a few of them. If you connect a plug-in that is not supported, Jekyll can not put together a website, so that strictly adhere to the list of supported plugins.

Content of the project

_includes / (html blocks ready for insertion)
_layouts / (templates)
_posts / (articles)
_sass / (styles)
images / (image for your blog)

Templates can be written using a template engine Liquid or with a standard markdown syntax.

The post should include header, indicating the name of the template and the post:

---
layout: post
title: "Post name"
---

Setting up a blog

You can now change the name of the site, its description, avatar and other settings by editing _config.yml file in the root directory of the project. These custom variables for convenience, were made separately, and they are used in the templates during the static assembly. Change _config.yml (or any file in the repository) will cause re-assembly site. See the result will be a couple of seconds at http://yourusername.github.io. After this action the site is sure to be available. Adapt the site for themselves, changing the variables in _config.yml and save your changes to the repository.

You can edit the files in one of three ways. Choose the one that works best for you:

  • Edit files directly in the browser on GitHub.com site in your repository yourusername.github.io (as shown below)
  • Use a third-party editor that supports the Markdown
  • Clone the repository, make changes locally, then send the changes (make a git push) in the remote repository on GitHub.

**Note: ** Do not think that you need to perform jekyll build locally to make changes to the website - GitHub Pages do it for you. Just put the files you want to collect in the master branch of the repository to your site or gh-pages of any other repository, GitHub Pages then converts them using Jekyll.

The publication of the first article

Now the blog is up and running. It is time to publish the first article:

  1. Create /_posts/filename.md file. Enter the text of your first post.
  2. Change the file name to include the current date and the post title. Jekyll requires a certain naming format: year-month-day-title.md.
  3. Update header. Variables in the beginning of the file referred to an introductory unit, we will look at them in more detail a little later. In this case, they determine the title of the article and the template used. There are other variables that can be used in the opening section, for example, permalink, tags and category.

If you want to create a new article on GitHub.com directly in your browser, just go to the directory /_posts/ in your repository on GitHub and click on the icon "+". The main thing - do not forget to stick to the format of the file name and add an introductory unit, the files were processed Jekyll.

Closing remark

I think that this is enough to understand how you can create your own blog is simple, fast, reliable. I like Jekyll as a convenient tool to quickly create a blog. This allows me to focus on what I'm writing, rather than on technical issues. I like GitHub for features such as hosting and storage of my projects and ideas.

I wish you success and creativity, which you describe in your new blog!

Useful links:

  • https://jekyllrb.com/docs/home/
  • https://github.com/barryclark/jekyll-now
  • https://github.com/jekyll/docker
  • https://shopify.github.io/liquid/
  • http://wiki.github.com/mojombo/jekyll/install
0