鍍金池/ 教程/ Java/ 模板
Assets
相關(guān)資源
創(chuàng)建頁面
基本用法
常見問題
模板
升級
配置
部署方法
使用 Jekyll 的站點(diǎn)
頭信息
插件
博客遷移
永久鏈接
使用草稿
貢獻(xiàn)
分頁功能
安裝
目錄結(jié)構(gòu)
Data Files
常用變量
GitHub Pages
撰寫博客
快速指南
附加功能

模板

Jekyll 使用 Liquid 模板語言,支持所有標(biāo)準(zhǔn)的 Liquid 標(biāo)簽過濾器 。 Jekyll 甚至增加了幾個過濾器和標(biāo)簽,方便使用。

過濾器

http://wiki.jikexueyuan.com/project/jekyll/images/11.png" alt="" />

標(biāo)簽

引用

如果你需要在多個地方引用一小代碼片段,可以使用 include 標(biāo)簽。

{% include footer.html %}

Jekyll 要求所有被引用的文件放在根目錄的 _includes 文件夾,上述代碼將把 <source>/_includes/footer.html 的內(nèi)容包含進(jìn)來。

ProTip?: Use variables as file name

The name of the file you wish to embed can be literal (as in the example above), or you can use a variable, using liquid-like variable syntax as in {% include {{ my_variable }} %}.

你還可以傳遞參數(shù):

{% include footer.html param="value" %}

這些變量可以通過 Lquid 調(diào)用:

{{ include.param }}

Code snippet highlighting

Jekyll 已經(jīng)支持 超過 100 種語言 代碼高亮顯示,在此感謝 Pygments 。要使用 Pygments ,你必須安裝 Python 并且在配置文件中設(shè)置 pygmentstrue 。

Alternatively, you can use Rouge to highlight your code snippets. It doesn’t support as many languages as Pygments does but it should fit in most cases and it’s written in pure Ruby ; you don’t need Python on your system!

使用代碼高亮的例子如下:

{% highlight ruby %}
def foo
  puts 'foo'
end
{% endhighlight %}

highlight 的參數(shù) (本例中的 ruby) 是識別所用語言,要使用合適的識別器可以參照 Lexers 頁 的 “short name” 。

行號

highlight 的第二個可選參數(shù)是 linenos ,使用了 linenos會強(qiáng)制在代碼上加入行號。例如:

{% highlight ruby linenos %}
def foo
  puts 'foo'
end
{% endhighlight %}

代碼高亮的樣式

要使用代碼高亮,你還需要包含一個樣式。例如你可以在 syntax.css 找到,這里有 跟 GitHub 一樣的樣式,并且免費(fèi)。如果你使用了 linenos ,可能還需要在 syntax.css 加入 .lineno樣式。

Post URL

如果你想使用你某篇文章的鏈接,標(biāo)簽 post_url 可以滿足你的需求。

{% post_url 2010-07-21-name-of-post %}

If you organize your posts in subdirectories, you need to include subdirectory path to the post:

{% post_url /subdir/2010-07-21-name-of-post %}

當(dāng)使用 post_url標(biāo)簽時,不需要寫文件后綴名。

還可以用 Markdown 這樣為你的文章生成超鏈接:

[Name of Link]({% post_url 2010-07-21-name-of-post %})

Gist

使用 gist 標(biāo)簽可以輕松的把 GitHub Gist 簽入到網(wǎng)站中:

{% gist 5555251 %}

你還可以配置 gist 的文件名,用以顯示:

{% gist 5555251 result.md %}

gist 同樣支持私有的 gists ,這需要 gist 所屬的 github 用戶名:

{% gist parkr/931c1c8d465a04042403 %}

私有的 gist 同樣支持文件名。

上一篇:貢獻(xiàn)下一篇:撰寫博客