mylsGit & GitHubGitHub上有趣的资源

通过Github Pages和Jekyll搭建个人博客

2015-06-24  本文已影响9724人  Jason_Yuan

目录###

1. 什么是Jekyll ?
2. 使用静态网站生成器的好处
3. 环境搭建
4. 主题


1. 什么是Jekyll ?

Jekyll
Jekyll(raw_text_files, templates)
{
    return Beautiful_web_pages;
} 

2. 使用静态网站生成器的好处

3. 环境搭建

本文只说明在Mac上的实现过程

第一步 安装 Jekyll
jason: ~ $ gem install jekyll
jason: ~ $ sudo gem install jekyll
jekyll 2.5.3
第二步 创建 Jekyll 项目
jason: ~ $ cd Desktop
jason: ~/Desktop $ jekyll new Jason_Blog
New jekyll site installed in /Users/boyuan/Desktop/Jason_Blog.
boyuan: ~/Desktop $ cd Jason_Blog_2/
boyuan: ~/Desktop/Jason_Blog $ jekyll serve

注意:此时Jason_Blog文件夹中会增加_site文件夹,包含了生成网站的所有结构。同时,原来文件夹中开头没有下划线的文件夹会被复制到_site文件夹中,比如CSS文件夹

第三步 更改配置文件_config.yml

详细内容参考官网 - Jekyll configuration
想了解更多YAML文件 - YAML

# Build settings
markdown: kramdown
permalink: pretty

URL变更为:http://127.0.0.1:4000/jekyll/update/2015/06/22/welcome-to-jekyll/

# Build settings
markdown: kramdown
permalink: /:title

URL变更为:http://127.0.0.1:4000/welcome-to-jekyll/

第四步 深入了解Jekyll模板

Jekyll实际使用的是模板语言Liquid来操作模板和输出文件的。Liquid现在是Github上的开源项目,有兴趣可以多了解一下,很简单

---
layout: post                       // 表示选择post模板
title:  "Welcome to Jekyll!"       // 博客的标题
date:   2015-06-23 01:54:33        // 博客日期
author: Jason                      // 作者
categories: jekyll update          // 添加类别,空格分开
permalink: "Welcome to Jekyll"     // 确定显示的URL
---

注:反复使用的变量,比如layout, author等可以移到_config.yml

default.html
// 格式一   output markup
{% include head.html %}
// 格式二   tag markup
{{ content }}
// 下面是about.md 中的 YAML Front Matter
---
layout: page                       // 表示选择post模板
title: About                       // 标题为About
permalink: /about/                 //about后面添加一个 "/" 可是_site中生成同名文件夹
---
boyuan: ~/Desktop/Jason_Blog $ jekyll serve --drafts

4. 主题

有了上面的了解,网络上有一大波主题在等着你,直接下个主题,轻松简单。

最后,发布到Github吧, Free Free Free
请戳 => 如何使用Github Pages免费搭建网站

上一篇 下一篇

猜你喜欢

热点阅读