GitHub Pages 和 Jekyll 笔记( 二 )


---food: Pizza---<h1>{{ page.food }}</h1>预定义的变量

  • 全局变量: layout, permalink, published
  • 帖子变量: date, category, categories, tags
插件GitHub Pages 默认启用以下的 Jekyll 插件, 不能禁用
  • jekyll-coffeescript
  • jekyll-default-layout
  • jekyll-gist
  • jekyll-github-metadata
  • jekyll-optional-front-matter
  • jekyll-paginate
  • jekyll-readme-index
  • jekyll-titles-from-headings
  • jekyll-relative-links
可以通过 _config.yml 添加新的插件.
代码高亮GitHub Pages 中的代码高亮和 GitHub 是一样的, 默认情况下由 Jekyll 处理代码高亮, Jekyll 使用的代码高亮解析是 Rouge.
页面类型Jekyll 的页面分为不同的类型, 主要有 Page, Posts
PagesPages 用于做单独的页面, 单独创建, 可以放在任意目录, 生成时会放到 _site 目录下
PostsPosts 用于日常的文章发表, 创建时放到 _posts 目录下, 文件名需要使用如下固定的格式
YEAR-MONTH-DAY-title.MARKUP例如
2011-12-31-new-years-eve-is-awesome.md2012-09-12-how-to-write-a-blog.md每个文章的固定格式如下, 前面的front matter可以为空
---layout: posttitle:"Welcome to Jekyll!"---# Welcome**Hello world**, this is my first Jekyll blog post.I hope you like it!静态文件静态文件例如图片, ZIP, PDF, 可以都放置在 assets 目录下, 再从文章中连接, 例如
... which is shown in the screenshot below:![My helpful screenshot](/assets/screenshot.jpg)或者链接到PDF
... you can [get the PDF](/assets/mydoc.pdf) directly.文章列表使用以下方式创建文章列表
<ul>{% for post in site.posts %}<li><a href="https://www.huyubaike.com/biancheng/{{ post.url }}">{{ post.title }}</a></li>{% endfor %}</ul>分类和标签Tag 和 Category 都有单数复数的区分, 如果是单数, 后面的整个值都作为一个标签或分类, 如果是复数, 则按空格分隔tag: classic hollywood会被当成标签"classic hollywood", 如果是tags: classic hollywood, 则会被当成标签 "classic"和"hollywood".
使用tag或category创建文章目录, 可以使用下面的形式, 注意site.tagssite.categories的for循环中, 每个标签或分类会产生两个单元, 一个单元是名称, 另一个单元才是文章列表
{% for tag in site.tags %}<h3>{{ tag[0] }}</h3><ul>{% for post in tag[1] %}<li><a href="https://www.huyubaike.com/biancheng/{{ post.url }}">{{ post.title }}</a></li>{% endfor %}</ul>{% endfor %}分类与标签的区别在与, 分类可以直接由文章的目录路径来定义, 在_post 目录上层的目录, 都会被当成分类, 例如如果文章位于路径 movies/horror/_posts/2019-05-21-bride-of-chucky.markdown, 那么 movies 和 horror a自动成为这个文章的分类.
当文章中使用 front matter 定义了类别, 会在列表中添加这篇文章. 取决于 front matter 中是否定义了分类, 例如 category: classic hollywood, 或 categories: classic hollywood, 帖子就会相应地产生这样的链接 movies/horror/classic%20hollywood/2019/05/21/bride-of-chucky.html 或 movies/horror/classic/hollywood/2019/05/21/bride-of-chucky.html
文章摘要通过excerpt_separator定义, 例如
---excerpt_separator: <!--more-->---Excerpt with multiple paragraphsHere's another paragraph in the excerpt.<!--more-->Out-of-excerpt在列表中引用摘要
<ul>{% for post in site.posts %}<li><a href="https://www.huyubaike.com/biancheng/{{ post.url }}">{{ post.title }}</a>{{ post.excerpt }}</li>{% endfor %}</ul>草稿草稿可以放到 _drafts 目录下
.├── _drafts│└── a-draft-post.md...Jekyll 实例参考
  • https://github.com/github/government.github.com
  • https://github.com/artsy/artsy.github.io
【GitHub Pages 和 Jekyll 笔记】

推荐阅读