git

使用github搭建博客

jekyll/gitpage/markdown

Posted by Xiaolei.liang on May 13, 2019 本文总阅读量

安装

  1. 在github上面设置gitpage,这个在设置选项里面有。

  2. 选择jekyll的原因是,直接push markdown文件,不用再转成html文件。

  3. 选择模版,此处使用Hux的模版:

    1. git clone https://github.com/xxx/xxx.github.io.git
    2. cd xxx
    3. rm -rf ./*
    4. git clone https://github.com/Huxpro/huxblog-boilerplate.git
    5. mv huxblog-boilerplate/* ./ && rm -rf huxblog-boilerplate
  4. 修改_config.yml文件:

    # Site settings
    title: 窗外蟋蟀
    SEOTitle: 窗外蟋蟀的博客 | Keysaim Blog
    header-img: img/home-bg-hill.jpg
    email: keysaim@gmail.com
    description: "描述"
    keyword: "窗外蟋蟀, keysaim"
    url: "https://keysaim.github.io"
    baseurl: ""
    
  5. 修改_layout中的post和page模版文件:

    语法错误:
    "site.duoshuo_share && site.duoshuo_username" 修改成 "site.duoshuo_share and site.duoshuo_username"
    "tag[1].size > 1" 修改成 "tag[1].size > site.featured-condition-size"
    
  6. 在_layout中写文件,目录名:YEAR-MONTH-DAY-title.markdown, 如:2019-05-13-hello.md , 格式如下:

    ---
    layout:     post
    title:      "Hello world!"
    subtitle: "new start"
    author: test
    header-img: "img/post-bg-2015.jpg"
    tags:
        - 生活
    ---
    
    ## 正文
    
     hello, world!
    

    备注: 开头如果加上date字段,会有问题哦。

本地调试

  1. 安装命令:

    $ brew install ruby
    $ gem install github-pages
    $ cd keysaim.github.io
    $ jekyll serve --watch
    

    该服务会侦听在本地4000的端口上,可以打开浏览器访问http://127.0.0.1:4000,这样就可以在本地查看自己的博文效果了。

参考文档

如何快速搭建自己的github.io博客