jekll建自己的博客

这篇文章根据大漠老师的博文写成,请参考<a href="http://damoqiongqiu.github.io/">http://damoqiongqiu.github.io/</a>

搭建的效果请参考<a href="https://baipu.github.io">白璞的技术博客</a>

准备项:

注册一个github账号,创建项目

  • 注册
    首先你需要有一个github的账号,将来的文章将会将github当成仓库用。所以先注册账户吧:
    点击这里进入github,然后按要求注册。
  • 创建项目
开始创建项目处
开始创建项目处

如果找不到上述页面那么下边这样也可以,总之随便点,就是找到repositories然后新建他

先点击这里
先点击这里
然后这里新建
然后这里新建

写你博客的域名,将来你就是根据这个网址访问你的博客,但是!!
注意了:
他的命名规范必须是:“xxx.github.io” 这里的xx必须是你github的名字,

enter description here
enter description here

这里我的名字是baipu所以,就的是baipu.github.io名字必须是这个,我之前用的是baip有问题

新建成功
新建成功

将工程拷到本地,有很多办法,包括git命令,github 或者是其他的:

克隆下来
克隆下来

同过命令行的方法添加文件:不用管

echo "# baip.github.io" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/baipu/baip.github.io.git
git push -u origin master

要不就是从其它项目上拷过来的命令行,先不用管

git remote add origin https://github.com/baipu/baip.github.io.git
git push -u origin master

github的客户端里保存文件,如果没有装github可添加一个文件后,down下来


保存文件
保存文件

安装jekyll 并配置运行环境

下载ruby 和RubyGems下载页

下载ruby

rubygems

下载rubygems后,具体页面就不详细截图了。解压,然后打开随便一个文件夹,不要点击任何文件,摁住shift键,同时鼠标右键,选择在此处打开命令窗口,书如Ruby -v和gem -v如果显示版本号,说明安装没问题


右键显示
右键显示
命令行显示
命令行显示

用Jekyll创建第一个项目

在你刚才拷下文件的外层目录上如上一样,右键,打开命令行,然后执行命令

gem install jekyll bundler

jekyll new baipu.github.io//jekyll new 此处是你刚才项目的名称

cd baipu.github.io//cd 你刚才项目的名称

bundle exec jekyll serve
命令行的显示
命令行的显示

然后用编辑器打开项目,我用的是vscode


编辑器
编辑器

命令行先别关。

这时候需要对文件做一些修改:
注意
把.sass-cache和_site这两个目录添加到.gitignore文件里面去,目的是告诉git不要把这两个目录里面的内容推送到github上去,这是你本地用的,github不需要这些。如果你把_site目录推送到github仓库,github就不会自动帮你构建了。
gitigore文件里面内容如下,你可以拷贝粘贴到你的.gitignore文件里面去:

_site

.sass-cache

.jekyll-metadata

然后提交,发布如下,先提交,然后发布

提交
提交

发布
发布

你本地的命令执行情况如图:
本地服务
本地服务

打开链接http://你刚才注册的名字.github.io

注意,如果你是第一次push,github可能会等10分钟之后才会帮你构建,后续的所有push都会立即构建,所以如果现在没有内容的话,等10分钟再来刷新一下吧。


enter description here
enter description here

出来这个图不要急,看看你的项目名字和github的名字一样么?如果正常请跳过下列步骤,直接看添加文章

enter description here
enter description here

如果不一样,在github上进入设置,然后修改名字

enter description here
enter description here

修改的时候确保名字正确github的名字.github.io
网下拉,看到GitHub Pages下边是这个样子,说明能够访问


enter description here
enter description here

添加文章

用编辑器打开你github的项目:

添加文章就是相当于_posts文件夹里添加一个markdown的文件

文件名必须是2017-07-10-文件名
后缀必须是markdown不能是md
格式也必须是markdown的格式

enter description here
enter description here

markdown的头部需要定制:

---
layout: post
title:  "这是我自己的一篇文章"
date:   2017-07-04 10:51:20 +0800
categories: jekyll update
---

enter description here
enter description here

除了这个头部声明之外,接下来你可以随意编写自己的内容了,markdown的语法:
http://www.appinn.com/markdown/

本地服务如下效果:

enter description here
enter description here

然后提交commit push

提交
提交
推送
推送

修改参数:

为了让title之类的显示自己的配置,可调试_config.yml文件

enter description here
enter description here

改了配置文件后,需要重启服务

bundle exec jekyll serve

结果如图:


白璞的博客
白璞的博客

改变外观:

换系统默认的皮肤:

皮肤默认值好像是minima
找到皮肤的路径:
命令:bundle show minima
得到结果:

D:/study/Ruby23-x64/lib/ruby/gems/2.3.0/gems/minima-2.1.1

我们不用这个皮肤包,可以换,但是只能换几样,github支持的:

将他改成 目标点击查看github支持的皮肤

github支持的皮肤
github支持的皮肤

如果我们想换Architect需要三部
1、改两个配置文件

  • _config.yml里边的 theme 对应的值改成 jekyll-theme-architect
  • Gemfile里边的 minima那一行变成 jekyll-theme-architect


    enter description here
    enter description here
enter description here
enter description here

2、 用gem安装皮肤:
bundle install

enter description here
enter description here

3、换模板,index.md about.md 以及_post中的文件中的layout配置项全部改成default,就像这样:
enter description here
enter description here

ctrl+C关闭服务,然后重启:
效果入下:


换过皮肤后
换过皮肤后

自己修改参数:

这次开始前需要把上一步的换肤步骤全部回退成默认格式

首先,打开你的命令行,运行以下命令,找到minima这款皮肤安装的位置:

bundle show minima

    D:/study/Ruby23-x64/lib/ruby/gems/2.3.0/gems/minima-2.1.1

找到位置,将里边的文件夹复制出来

enter description here
enter description here

结构如下:

enter description here
enter description here

为了防止bundle update需要把上两个文件_config.ymlGemfile的minima那一行删掉

然后就可已根据需求换参数了,比如改变日期格式:
两个文件:home.html 和post.html
日期格式改为:"%Y-%m-%d:%H:%M:%S"

enter description here
enter description here
enter description here
enter description here

这里有更多的参数配置

自己配置css

asset文件夹中新建css文件夹 引入bootstrap:

enter description here
enter description here

然后是文件中引入:头文件配置中,也就是_includ的head.html注意不是header.html
下边的内容拷进去

<link rel="stylesheet" href="/assets/css/bootstrap-4.0.0-alpha.6/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="/assets/css/bootstrap-4.0.0-alpha.6/js/bootstrap.min.js"></script>

如图:
enter description here
enter description here

打开assets/main.scss,把里面的内容改成:

@import "my.scss";

Jekyll当前的版本是用Sass来做CSS预编译的,关于Sass的基本概念语法,请点击这个中文版教程查看。简而言之,你可以把Sass看成是CSS的增强版超集,也就是说,你在.sass文件里面写基本的CSS都是没问题的。

所以写scss的步骤:
1、就是上边的assets/main.scss里边会导入my.scss所以下一步创建
2、在scss文件夹下创建my.scss文件,然后继续导入不同的scss

@import
  "my/base",
  "my/layout",
  "my/syntax-highlighting"
;

3、创建my文件夹,然后里边新建base layout scss文件


enter description here
enter description here

如果想用一个github的nav那就改变header.html文件,如果你导入的bootstrap是4.0的,用下列的代码替换header.html的代码:

<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse fixed-top">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
    aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item">
        <a class="nav-link" href="/">我的文章</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="/videos/index.html">免费视频</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="/projects/index.html">开源项目</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="/social/index.html">在线交流</a>
      </li>
    </ul>
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" href="/about/index.html">关于我</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="/donate/index.html">赞助我</a>
      </li>
    </ul>
  </div>
</nav>

那你将看到:bootstrap的头部


enter description here
enter description here

好,难点来了,以下几个环节可能需要翻墙,请自备梯子

利用Google Analytics监控你的Jekyll站点

Google Analytics(简称GA)是一个监控和分析工具,用来观察数据来源:

Jekyll集成Disqus评论模块

Jekyll的Disqus配置项

打开_layouts/post.html,你会在里面看到这样的内容:

enter description here
enter description here

如果你的_config.yml里面出现了site.disqus.shortname这个配置项,那么就把disqus_comments.html包含进来,从文件名猜测,disqus_comments.html就是用来集成disqus的代码了。

1注册Disqus并拿到你的shortname

1.1 注册

点击这里注册disqus账号

1.2 进入

enter description here
enter description here

选建立自己的站点 画红线那个,然后按提示写自己的东西:
主要是website Name就是等会儿要用到的shortName


enter description here
enter description here

然后选择基础款,免费


enter description here
enter description here

然后三排第四个:

enter description here
enter description here

enter description here
enter description here

填写配置

enter description here
enter description here

enter description here
enter description here

得到shortName,记住的的shortName

enter description here
enter description here

1.4 进行配置:

_config/yml文件里添加如下配置:

disqus:
  shortname: 你的shortName
enter description here
enter description here

此时理论上就可出现了,提交到github上然后更新
如果没有出现,请按照如下流程检查
post.html里边是否有这段代码,没有请复制:

 {% if site.disqus.shortname %}
    {% include disqus_comments.html %}
  {% endif %}
enter description here
enter description here

要么就在文章中添加这个字段:
comments其实 我也不咋知道这个字段是干嘛的,将来找到了会改

enter description here
enter description here

因为如下图有判断,environment在github上为生产环境,本地的话是开发环境不满足,但是这里的comment是什么意思我不懂,所以强制给了一个true

enter description here
enter description here

然后发布:

enter description here
enter description here

分类:

这个完全抄自大漠穷求:
1、_layout里边新建一个文件:category.html
2、里边的代码改为:

--- 
layout: default 
---
{% assign rawcats = "" %}
{% for post in site.posts %}
  {% assign tcats = post.category | join:'|' | append:'|' %}
  {% assign rawcats = rawcats | append:tcats %}
{% endfor %}

{% assign rawcats = rawcats | split:'|' | sort %}
{% assign cats = "" %}
{% for cat in rawcats %}
  {% if cat != "" %}
  {% if cats == "" %}
    {% assign cats = cat | split:'|' %}
  {% endif %}
  {% unless cats contains cat %}
    {% assign cats = cats | join:'|' | append:'|' | append:cat | split:'|' %}
  {% endunless %}
  {% endif %}
{% endfor %}

<div class="row">
  <div class="col-md-9">
    <div class="list-group">
        {% assign date_format = site.minima.date_format | default: "%Y-%m-%d %H:%M:%S" %}
        {% for ct in cats %}
            <li class="list-group-item list-group-item-info" id="{{ ct | slugify }}"><strong>{{ ct }}</strong></li>
            {% for post in site.posts %}
                {% if post.category contains ct %}
                  <a href="{{ post.url | relative_url }}" class="list-group-item list-group-item-action flex-column align-items-start">
                    <div class="d-flex w-100 justify-content-between">
                      <h5 class="mb-1">{{ post.title | escape }}</h5>
                      <small>{{ post.date | date: date_format }}</small>
                    </div>
                  </a>
                {% endif %}
            {% endfor %}
        {% endfor %}
    </div>
  </div>
  <div class="col-md-3">
  </div>
</div>

3、文章中添加分类字段:
category: this is demo


enter description here
enter description here

结果如图:

enter description here
enter description here

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269

推荐阅读更多精彩内容

  • WebSocket-Swift Starscream的使用 WebSocket 是 HTML5 一种新的协议。它实...
    香橙柚子阅读 22,956评论 8 183
  • 拥有一个自己的博客网站是每一位有追求的写作爱好者的梦想。本文将向大家分享:如何为自己创建一个既时尚又好用的博客网站...
    CrazyCodeBoy阅读 1,091评论 0 114
  • 《马》 谁是草原上的骑手 谁又是那匹剪去长发的 马 在冬夜的喘息中 欲望与想象己携着了梦境 让这个冬天得到 石头一...
    人世老枪阅读 551评论 1 7
  • 如何选择自己前进的道路,真的越来越迷茫? 想想自己现在的工作,工作是很轻松但是真的不是我想要的,没有前进的动力,更...
    亡羊补牢为时不晚阅读 215评论 0 0
  • 每天看这么多东西,自己感觉学到了很多,但是根本就是皮毛啊!这里看看,那里看看,这里有蘑菇,那里里草莓,都想摘下来尝...
    落地之触阅读 134评论 0 0