Jekyll+GitHub Pages部署本身的静态Blog

混了这么久,一直想拥有本身的博客,经过jekyllGitHub Pages捣腾出了本身的博客(https://www.ichochy.com)css

1、安装jekyll

  1. 首先有安装Ruby的开发环境
  2. 运行gem install jekyll bundler安装jekyll和bundler
  3. 运行jekyll new myBlog建立默认的bloghtml

    文件目录:
    -rw-r--r--   1 mleo  staff    35  2 13 15:02 .gitignore
    -rw-r--r--   1 mleo  staff   398  2 13 15:02 404.html
    -rw-r--r--   1 mleo  staff  1039  2 13 15:02 Gemfile
    -rw-r--r--   1 mleo  staff  1686  2 13 15:03 Gemfile.lock
    -rw-r--r--   1 mleo  staff  1652  2 13 15:02 _config.yml
    drwxr-xr-x   3 mleo  staff    96  2 13 15:02 _posts
    -rw-r--r--   1 mleo  staff   539  2 13 15:02 about.md
    -rw-r--r--   1 mleo  staff   175  2 13 15:02 index.md
  4. 运行cd myBlog进入blog目录,运行bundler exec jelly serve启动git

    MacBook-Pro:myBlog mleo$ bundler exec jekyll serve
    Configuration file: /Users/mleo/Develop/Coding/myBlog/_config.yml
            Source: /Users/mleo/Develop/Coding/myBlog
       Destination: /Users/mleo/Develop/Coding/myBlog/_site
     Incremental build: disabled. Enable with --incremental
      Generating... 
       Jekyll Feed: Generating feed for posts
                    done in 0.862 seconds.
     Auto-regeneration: enabled for '/Users/mleo/Develop/Coding/myBlog'
    Server address: http://127.0.0.1:4000/
      Server running... press ctrl-c to stop.
  5. 经过http://127.0.0.1:400就能够访问bloggithub

    以下图:

    WX20190213-152850

2、了解jekyll

  1. jekyll目录结构:json

    文件/目录 描述
    _config.yml 常量配置信息,网站的基础信息
    _drafts 未发布的草稿帖子
    _includes 模块化页面,使用: include default.html
    _layouts 布局模板页面,使用: layout: default
    _posts 发布的blog,固定格式: YEAR-MONTH-DAY-title.MARKUP
    _data 文件数据(.yml.yaml.json.csv.tsv格式)
    _sass 定义站点使用的样式
    _site Jekyll build 后生成的站点静态文件
    .jekyll-metadata Jekyll build 日志信息
    index.htmlindex.md其余HTML,Markdown文件 将由Jekyll转换,生成首页
    其余文件/文件夹 例如 cssimagesfavicon.ico文件等
  2. 经过Gemfile文件配置 jekyll 主题sass

    Jekyll 3.2开始,jekyll new使用Gemfile文件来定义网站的主题,使默认目录结构更简单。默认状况下_layouts_includes_sass存储在Ruby中。bash

    minima 是默认主题,运行 bundle show minima 显示主题文件位置markdown

    MacBook-Pro:myBlog mleo$ bundle show minima
    /Library/Ruby/Gems/2.3.0/gems/minima-2.5.0
  3. 自定义站点信息模块化

    经过自定义_config.yml文件,改变 blog 网站信息,布局

    常量 说明
    title 标题
    email 做者邮箱
    description 网站信息
    baseurl 网站路径
    url 网站地址,如:https://www.ichochy.com
    twitter_username 媒体帐号,如:iChochy
    github_username 媒体帐号,如:iChochy

    注:修改_config.yml须要重启服务

3、书写Blog

  • 进入_post目录,开始你的创做吧,注意文件的格式必须为YEAR-MONTH-DAY-title.MARKUP,如:2019-02-13-blog.md
  • 开始写做吧,直接使用md语法来书写你的文章

    ---                                                                                                                                          
    layout: post                       --指定模板
    title:  "blog"                     --标题
    date:   2019-02-13 15:02:11 +0800  --时间
    tags: blog                   --分类
                                           
    ---   
    内容
    以下图:

    WX20190215-171119

4、建立GitHub Pages项目

  • 新建一个项目,项目名必须为<username>.github.io,如:个人用户名为iChochy,项目名为iChochy.github.io

    以下图:

    WX20190215-172254

5、将Blog接交到GitHub

  • 将本地写好的的blog pull到github上,在项目设置中打开GitHub Pages

    以下图:

    WX20190218-102109

  • 选择master branch并保存,就完成了部署

6、运行Blog

直接访问项目名(<username>.github.io)就能够看你blog了,如:iChochy.github.io

7、自定义域名

  • 自定义域名须要有本身的域名,没有能够注册购买个心意的域名:阿里云
  • 进入域名配置中心,配置域名解析

    以下图:

    WX20190218-095303

  • 进入github项目设置,设置本身的域名并保存,就完成了自定义域名设置

    以下图:

    WX20190218-095906

8、开启HTTPS

  • 进入github项目设置,开启Enforce HTTPS就完成了

    不过,若是是自定义域名,会须要等待几分钟, github须要申请证书并部署
  • 完成开启后,以下图:

    WX20190218-104830


联系方式:

邮箱: iChochy@qq.com
网站: https://www.ichochy.com
源文: https://www.ichochy.com/blog/2019/02/13/Jekyll GitHub-Pages部署本身的静态Blog.html
相关文章
相关标签/搜索