標籤外掛(Tag Plugins)

標籤外掛和 Front-matter 中的標籤不同,它們是用於在文章中快速插入特定內容的外掛。

Although you can write your posts in any formats, but the tag plugins will always be available and syntax remains the same.

Tag plugins should not be wrapped inside Markdown syntax, e.g. []({% post_path lorem-ipsum %}) is not supported.

Block Quote

在文章中插入引言,可包含作者、來源和標題。

捷徑: quote

{% blockquote [author[, source]] [link] [source_link_title] %}
content
{% endblockquote %}

沒有提供參數,僅輸出普通的 blockquote

{% blockquote %}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque hendrerit lacus ut purus iaculis feugiat. Sed nec tempor elit, quis aliquam neque. Curabitur sed diam eget dolor fermentum semper at eu lorem.
{% endblockquote %}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque hendrerit lacus ut purus iaculis feugiat. Sed nec tempor elit, quis aliquam neque. Curabitur sed diam eget dolor fermentum semper at eu lorem.

引用書上的句子

{% blockquote David Levithan, Wide Awake %}
Do not just seek happiness for yourself. Seek happiness for all. Through kindness. Through mercy.
{% endblockquote %}

Do not just seek happiness for yourself. Seek happiness for all. Through kindness. Through mercy.

David LevithanWide Awake

引用 Twitter

{% blockquote @DevDocs https://twitter.com/devdocs/status/356095192085962752 %}
NEW: DevDocs now comes with syntax highlighting. http://devdocs.io
{% endblockquote %}

NEW: DevDocs now comes with syntax highlighting. http://devdocs.io

引用網路上的文章

{% blockquote Seth Godin http://sethgodin.typepad.com/seths_blog/2009/07/welcome-to-island-marketing.html Welcome to Island Marketing %}
Every interaction is both precious and an opportunity to delight.
{% endblockquote %}

Every interaction is both precious and an opportunity to delight.

Code Block

在文章中插入程式碼。

捷徑: code

{% codeblock [title] [lang:language] [url] [link text] [additional options] %}
code snippet
{% endcodeblock %}

Specify additional options in option:value format, e.g. line_number:false first_line:5.

Extra Options Description Default
line_number Show line number true
line_threshold Only show line numbers as long as the numbers of lines of the code block exceed such threshold. 0
highlight Enable code highlighting true
first_line Specify the first line number 1
mark Line highlight specific line(s), each value separated by a comma. Specify number range using a dash
Example: mark:1,4-7,10 will mark line 1, 4 to 7 and 10.
wrap Wrap the code block in <table> true

普通的程式碼區塊

{% codeblock %}
alert('Hello World!');
{% endcodeblock %}
alert('Hello World!');

指定語言

{% codeblock lang:objc %}
[rectangle setX: 10 y: 10 width: 20 height: 20];
{% endcodeblock %}
[rectangle setX: 10 y: 10 width: 20 height: 20];

加上說明

{% codeblock Array.map %}
array.map(callback[, thisArg])
{% endcodeblock %}
Array.map
array.map(callback[, thisArg])

加上說明和網址

{% codeblock _.compact http://underscorejs.org/#compact Underscore.js %}
_.compact([0, 1, false, 2, '', 3]);
=> [1, 2, 3]
{% endcodeblock %}
_.compactUnderscore.js
_.compact([0, 1, false, 2, '', 3]);
=> [1, 2, 3]

Backtick Code Block

另一種形式的程式碼區塊。

```[language] [title] [url] [link text] code snippet ```

Pull Quote

在文章中插入 Pull quote。

{% pullquote [class] %}
content
{% endpullquote %}

jsFiddle (deleted in v7.0.0)

Please use hexo-tag-embed instead if you use v7.0.0+.

在文章中嵌入 jsFiddle。

{% jsfiddle shorttag [tabs] [skin] [width] [height] %}

Gist (deleted in v7.0.0)

Please use hexo-tag-embed instead if you use v7.0.0+.

在文章中嵌入 Gist。

{% gist gist_id [filename] %}

iframe

在文章中插入 iframe。

{% iframe url [width] [height] %}

Image

在文章中插入指定大小的圖片。

{% img [class names] /path/to/image [width] [height] '"title text" "alt text"' %}

Link

在文章中插入連結,並在外連連結自動加上 target="_blank" 屬性。

{% link text url [external] [title] %}

Include Code

插入 source/downloads/code 資料夾內的程式檔,資料夾取决于你在配置文件中 code_dir 的配置。

{% include_code [title] [lang:language] path/to/file %}

Youtube (deleted in v7.0.0)

Please use hexo-tag-embed instead if you use v7.0.0+.

在文章中插入 Youtube 影片。

{% youtube video_id [type] [cookie] %}

Examples

影片

{% youtube lJIrF4YjHfQ %}

播放列表

{% youtube PL9hW1uS6HUfscJ9DHkOSoOX45MjXduUxo 'playlist' %}

隱私模式

禁止 YouTube cookie

{% youtube lJIrF4YjHfQ false %}
{% youtube PL9hW1uS6HUfscJ9DHkOSoOX45MjXduUxo 'playlist' false %}

Vimeo (deleted in v7.0.0)

Please use hexo-tag-embed instead if you use v7.0.0+.

在文章中插入 Vimeo 影片。

{% vimeo video_id %}

引用文章

引用其他文章的連結。

{% post_path filename %}
{% post_link filename [title] [escape] %}

You can ignore permalink and folder information, like languages and dates, when using this tag.

For instance: {% post_link how-to-bake-a-cake %}.

This will work as long as the filename of the post is how-to-bake-a-cake.md, even if the post is located at source/posts/2015-02-my-family-holiday and has permalink 2018/en/how-to-bake-a-cake.

You can customize the text to display, instead of displaying the post’s title.

Post’s title and custom text are escaped by default. You can use the escape option to disable escaping.

For instance:

Display title of the post.

{% post_link hexo-3-8-released %}

Hexo 3.8.0 Released

Display custom text.

{% post_link hexo-3-8-released 'Link to a post' %}

Link to a post

Escape title.

{% post_link hexo-4-released 'How to use <b> tag in title' %}
How to use <b> tag in title

Do not escape title.

{% post_link hexo-4-released '<b>bold</b> custom title' false %}
bold custom title

引用資產

引用文章的資產。

{% asset_path filename %}
{% asset_img [class names] slug [width] [height] [title text [alt text]] %}
{% asset_link filename [title] [escape] %}

Embed image

hexo-renderer-marked 3.1.0+ can (optionally) resolves the post’s path of an image automatically, refer to this section on how to enable it.

“foo.jpg” is located at http://example.com/2020/01/02/hello/foo.jpg.

Default (no option)

{% asset_img foo.jpg %}

<img src="/2020/01/02/hello/foo.jpg">

Custom class

{% asset_img post-image foo.jpg %}

<img src="/2020/01/02/hello/foo.jpg" class="post-image">

Display size

{% asset_img foo.jpg 500 400 %}

<img src="/2020/01/02/hello/foo.jpg" width="500" height="400">

Title & Alt

{% asset_img logo.svg "lorem ipsum'dolor'" %}

<img src="/2020/01/02/hello/foo.jpg" title="lorem ipsum" alt="dolor">

URL

url_for (7.0.0+)

Returns a url with the root path prefixed. Output is encoded automatically.

{% url_for text path [relative] %}

Examples:

_config.yml
root: /blog/ # example
{% url_for blog index.html %}
<a href="/blog/index.html">blog</a>

Relative link, follows relative_link option by default
e.g. post/page path is ‘/foo/bar/index.html’

_config.yml
relative_link: true
{% url_for blog index.html %}
<a href="../../index.html">blog</a>

You could also disable it to output a non-relative link, even when relative_link is enabled and vice versa.

{% url_for blog index.html false %}
<a href="/index.html">blog</a>

full_url_for (7.0.0+)

Returns a url with the config.url prefixed. Output is encoded automatically.

{% full_url_for text path %}

Examples:

_config.yml
url: https://example.com/blog # example
{% full_url_for index /a/path %}
<a href="https://example.com/blog/a/path">index</a>

Raw

如果您要在文章中插入 Swig 標籤,可以試著使用 Raw 標籤,以免發生解析異常。

{% raw %}
content
{% endraw %}