标签插件和 Front-matter 中的标签不同。 它们是从 Octopress 移植的,为您提供了一种快速向帖子添加特定内容的有用方法。
虽然你可以使用任何格式书写你的文章,但是标签插件永远可用,且语法也都是一致的。
标签插件不应该被包裹在 Markdown 语法中,例如: []({% post_path lorem-ipsum %})
是不被支持的。
引用块
Perfect for adding quotes to your post, with optional author, source and title information.
别号: quote
{% blockquote [author[, source]] [link] [source_link_title] %} |
示例
No arguments. Plain 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.
引用书上的句子
{% blockquote David Levithan, Wide Awake %} |
Do not just seek happiness for yourself. Seek happiness for all. Through kindness. Through mercy.
引用 Twitter
{% blockquote @DevDocs https://twitter.com/devdocs/status/356095192085962752 %} |
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.
代码块
A useful feature for adding code snippets to your post.
别名: code
{% codeblock [title] [lang:language] [url] [link text] [additional options] %} |
以 option:value
的格式指定额外选项,例如:line_number:false first_line:5
。
额外选项 | 描述 | 默认值 |
---|---|---|
line_number |
显示行号 | true |
line_threshold |
只有代码块的行数超过该阈值,才显示行数 | 0 |
highlight |
启用代码高亮 | true |
first_line |
指定第一个行号 | 1 |
mark |
突出显示特定的行,每个值用逗号分隔。 使用破折号指定数字范围 例如: mark:1,4-7,10 将标记第1、4至7和10行 |
|
wrap |
用 <table> 包裹代码块 |
true |
示例
普通的代码块
{% codeblock %} |
alert('Hello World!'); |
指定语言
{% codeblock lang:objc %} |
[rectangle setX: 10 y: 10 width: 20 height: 20]; |
在文章中插入代码。
{% codeblock Array.map %} |
array.map(callback[, thisArg]) |
附加说明和网址
{% codeblock _.compact http://underscorejs.org/#compact Underscore.js %} |
\_.compact([0, 1, false, 2, '', 3]); => [1, 2, 3] |
反引号代码块
This is identical to using a code block, but instead uses three backticks to delimit the block.
``[language] [title] [url] [link text] code snippet ``Pull Quote
To add pull quotes to your posts:
{% pullquote [class] %} |
jsFiddle (v7.0.0
中被移除)
该标签在 Hexo 7.0.0 中被删除。 如果你正在使用
v7.0.0+
,请使用 hexo-tag-embed 替代。
在文章中嵌入 jsFiddle。
{% jsfiddle shorttag [tabs] [skin] [width] [height] %} |
Gist (v7.0.0
中被移除)
如果你正在使用
v7.0.0+
,请使用 hexo-tag-embed 替代。
To embed a Gist snippet:
{% 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
文件夹内的代码文件。 source/downloads/code
不是固定的,取决于你在配置文件中 code_dir
的配置。
{% include_code [title] [lang:language] [from:line] [to:line] path/to/file %} |
示例
嵌入 test.js 文件全文
{% include_code lang:javascript test.js %} |
只嵌入第 3 行
{% include_code lang:javascript from:3 to:3 test.js %} |
嵌入第 5 行至第 8 行
{% include_code lang:javascript from:5 to:8 test.js %} |
嵌入第 5 行至文件结束
{% include_code lang:javascript from:5 test.js %} |
嵌入第 1 行至第 8 行
{% include_code lang:javascript to:8 test.js %} |
Youtube (v7.0.0
中被移除)
如果你正在使用
v7.0.0+
,请使用 hexo-tag-embed 替代。
在文章中插入 Youtube 视频。
{% youtube video_id [type] [cookie] %} |
示例
视频
{% youtube lJIrF4YjHfQ %} |
播放列表
{% youtube PL9hW1uS6HUfscJ9DHkOSoOX45MjXduUxo 'playlist' %} |
隐私模式
在这种模式下,禁用 YouTube cookie
{% youtube lJIrF4YjHfQ false %} |
Vimeo (v7.0.0
中被移除)
如果你正在使用
v7.0.0+
,请使用 hexo-tag-embed 替代。
Inserts a responsive or specified size Vimeo video.
{% vimeo video_id [width] [height] %} |
Include Posts
Include links to other posts.
{% post_path filename %} |
在使用此标签时可以忽略文章文件所在的路径或者文章的永久链接信息、如语言、日期。
例如,在文章中使用 {% post_link how-to-bake-a-cake %}
时,只需有一个名为 how-to-bake-a-cake.md
的文章文件即可。
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
.
默认链接文字是文章的标题,你也可以自定义要显示的文本。
默认对文章的标题和自定义标题里的特殊字符进行转义。 可以使用 escape
选项,禁止对特殊字符进行转义。
例如:
Display title of the post.
{% post_link hexo-3-8-released %}
Display custom text.
{% post_link hexo-3-8-released 'Link to a post' %}
Escape title.
{% post_link hexo-4-released 'How to use <b> tag in title' %} |
Do not escape title.
{% post_link hexo-4-released '<b>bold</b> custom title' false %} |
Include Assets
引用文章的资源,与 资源文件夹 一起使用。
{% asset_path filename %} |
嵌入图片
hexo-renderer-marked 3.1.0+ 可以(可选)自动解析图片的文章路径,参考 本节 如何启用它。
“foo.jpg” 位于 http://example.com/2020/01/02/hello/foo.jpg
。
默认(无选项)
{% asset_img foo.jpg %}
<img src="/2020/01/02/hello/foo.jpg" /> |
自定义 class 属性
{% asset_img post-image foo.jpg %}
<img src="/2020/01/02/hello/foo.jpg" class="post-image" /> |
展示尺寸
{% asset_img foo.jpg 500 400 %}
<img src="/2020/01/02/hello/foo.jpg" width="500" height="400" /> |
title 和 alt 属性
{% asset_img foo.jpg "lorem ipsum'dolor'" %}
<img src="/2020/01/02/hello/foo.jpg" title="lorem ipsum" alt="dolor" /> |
URL
url_for (7.0.0+)
返回一个带有根路径前缀的URL。 输出将会自动编码。
{% url_for text path [relative] %} |
例如:
_config.yml |
{% url_for blog index.html %} |
<a href="/blog/index.html">blog</a> |
是否输出相对链接,默认遵循配置文件中 relative_link
的值 例如, post/page 的路径值可能是 /foo/bar/index.html
_config.yml |
{% url_for blog index.html %} |
<a href="../../index.html">blog</a> |
即使配置文件中启用了 relative_link
,你也可以使用 relative
参数禁用相对链接输出,反之亦然
{% url_for blog index.html false %} |
<a href="/index.html">blog</a> |
full_url_for (7.0.0+)
返回一个以 config.url
为前缀的URL。 输出将会自动编码。
{% full_url_for text path %} |
示例:
_config.yml |
{% full_url_for index /a/path %} |
<a href="https://example.com/blog/a/path">index</a> |
Raw
If certain content is causing processing issues in your posts, wrap it with the raw
tag to avoid rendering errors.
{% raw %} |
Post Excerpt
在文章中使用 <!-- more -->
,那么 <!-- more -->
之前的文字将会被视为摘要。 excerpt:
value in the front-matter, if specified, will take precedent.
示例:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. |