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 筆記】

推薦閱讀