首先感谢Harttle这套blog代码. 如何使用Github和Jekyll搭建Blog的文章网上已经很多, 就不赘述了, 姑且记录一些自己遇到的问题.

域名DNS问题

由于是第一次使用非ip解析域名, 当使用CNAME记录将tokinonagare.com解析到tokinonagare.github.io时, Cloudflare上出现一个”!”的警告, 并且无法连接tokinonagare.com.

  1. 需在项目文件夹中新建CNAME文件, 写入tokinonagare.com;
  2. 因为是顶级域名, 需在DNS使用ALIAS记录, 然而Cloudflare没有这个记录选项, 所以需直接用A记录到两个ip:192.30.252.153&192.30.252.154注: ip会更改;
  3. 如果不使用A记录, 使用CNAME记录到tokinonagare.com访问正常, 按照Github的说法会出现邮件的解析问题(未验证);
  • 参考: https://help.github.com/articles/my-custom-domain-isn-t-working/
  • 参考: http://justcoding.iteye.com/blog/1959737

目录摘要显示

源代码中目录页面中的每篇Blog文章占据了太大的篇幅, 秉着使用尽量少的操作浏览尽量多的内容, 故进行修改.

①首先尝试CSS, 添加行高限制, 隐藏溢出内容, 然而会出现部分最后一行行显示半截, 故舍弃;

#posts > div.post.paper{
	height-line: 150%;
	height:  40em;
	overflow: hidden;
}

②考虑jekyll对于这种问题应该会做处理, 于是去查看源码;

  
	{{ post.content | split:"<!-- more -->" | first }}
  

<!-- more -->是一个分割标签, 该段代码含义: 显示从文章开始到该标签的内容;

③用字数进行限制, 然而这样会导致HTML的内容也会显示出来;

	
	{{ post.content | truncatewords: 300 }}
	

④使用摘要显示

	
	{{ post.excerpt }}
	

需在_config.yml中添加: excerpt_separator: "<!-- more -->"

---
excerpt: "摘要内容"
---

需要手动添加内容, 对于懒人来说太困难了_(:з」∠)…

  • 参考: http://mikeygee.com/blog/truncate.html
  • 参考: https://blog.omgmog.net/post/adding-support-for-more-tag-to-jekyll-without-plugins/
  • 参考: http://jekyllrb.com/docs/posts/#post-excerpts
  • 参考: https://truongtx.me/2013/05/01/jekyll-read-more-feature-without-any-plugin/

敏感词处理

Liquid Exception: undefined method `split’ for nil:NilClass

如果直接写入{{ post.content | split:'<!-- more -->' | first }}会出现报错, 需要添加{% raw %}{% endraw %};

  {% raw %}
	{{ post.content | split:"<!-- more -->" | first }}
  {% endraw %}

然而我在写入{% raw %}{% endraw %}自身时, 又遇到了问题, 方法是拆分掉{%;

{% raw %}:

	{% raw %}{% raw %}{% endraw %}

{% endraw %}:

	{% raw %}{%{% endraw %}endraw %}
  • 参考: https://github.com/jekyll/jekyll/issues/3381
  • 参考: http://blog.slaks.net/2013-06-10/jekyll-endraw-in-code/

Gitignore

由于每次本地jekyll serve 的时候都会在_site/文件夹中生成网站文件, 而push的时候需要git commit的话显得就很多余, 故想到能否屏蔽掉这一个文件夹

根目录新建文件.gitignore写入

_site/
.sass-cache/
.jekyll-metadata

传送门: Github/Jekyll.gitignore

新窗口中打开URL链接

使用[Tokinonagare](http://tokinonagare.com)打开的URL只能在当前窗口打开, 对于一些参考链接的话非常不方便

添加jQuery_layouts/default.html

<script>
//Url在新窗口中打开
  $(document.links).filter(function() {
    return this.hostname != window.location.hostname;
  }).attr('target', '_blank');
</script>
  • 参考: http://www.chengxusheji.com/archives/121.html
  • 参考: https://github.com/github/gitignore

转载请注明出处 Blog誕生 - GitHub 博客搭建问题记录