我正在使用markdown文件的YAML Headers 将 excerpt
变量添加到我可以在别处使用的博客帖子中 . 在其中一个摘录中,我通过降价链接标记引用了早期的博客文章,我使用液体模板数据变量 {{ site.url }}
代替站点的基本URL .
所以我有类似的东西(有点修剪)
---
title: "Decluttering ordination plots in vegan part 2: orditorp()"
status: publish
layout: post
published: true
tags:
- tag1
- tag2
excerpt: In the [earlier post in this series]({{ site.url }}/2013/01/12/
decluttering-ordination-plots-in-vegan-part-1-ordilabel/ "Decluttering ordination
plots in vegan part 1: ordilabel()") I looked at the `ordilabel()` function
----
但是,jekyll和Maruku md解析器不喜欢这个,这让我怀疑你不能在YAML头中使用液体标记 .
是否可以在jekyll处理的页面的YAML Headers 中使用液体标记?
-
如果是,我在示例中做错了什么?
-
如果不允许,我还能实现我的目标?我目前正在我的笔记本电脑上开发我的网站,当我准备部署时,我不得不改变 .
我从Maruku得到的错误是:
| Maruku tells you:
+---------------------------------------------------------------------------
| Must quote title
| ---------------------------------------------------------------------------
| the [earlier post in this series]({{ site.url }}/2013/01/12/decluttering-o
| --------------------------------------|-------------------------------------
| +--- Byte 40
和
| Maruku tells you:
+---------------------------------------------------------------------------
| Unclosed link
| ---------------------------------------------------------------------------
| the [earlier post in this series]({{ site.url }}/2013/01/12/decluttering-or
| --------------------------------------|-------------------------------------
| +--- Byte 41
和
| Maruku tells you:
+---------------------------------------------------------------------------
| No closing ): I will not create the link for ["earlier post in this series"]
| ---------------------------------------------------------------------------
| the [earlier post in this series]({{ site.url }}/2013/01/12/decluttering-or
| --------------------------------------|-------------------------------------
| +--- Byte 41
2 回答
我不相信将液体变量嵌入YAML中是可能的 . 至少,我还没弄明白怎么做 .
一种可行的方法是使用Liquid's replace filter . 具体来说,定义要用于变量替换的字符串(例如
!SITE_URL!
) . 然后,在输出期间使用替换过滤器将其切换到所需的Jekyll变量(例如site.url
) . 这是一个减少的.md文件,在我的jekyll 0.11安装上表现得如预期:在我的机器上测试,正确插入URL,然后按预期从markdown转换为HTML链接 . 如果要替换多个项目,可以将多个替换调用串在一起 .
一个重要的注意事项是you must explicitly set the site.url值 . 你不能和杰基尔一起免费获得 . 您可以使用以下命令在
_config.yml
文件中进行设置:或者,在调用jekyll时定义它:
今天我遇到了类似的问题 . 作为一个解决方案,我创建了以下简单的Jekyll过滤器插件,它允许扩展嵌套的液体模板(例如YAML前端物质中的液体变量):
可以将过滤器添加到站点根目录的“_plugins”子目录中,从而将过滤器添加到Jekyll站点 . 上面的代码可以简单地粘贴到yoursite / _plugins / liquify_filter.rb文件中 .
之后是一个像...的模板
......应该呈现一些像“问候哈利波特!”的输出 . 扩展也适用于更深层次的嵌套结构 - 只要在内部液体输出块上指定了液化过滤器 . 像{}之类的东西当然也有用 .
Update - 看起来现在可以作为Ruby gem使用:https://github.com/gemfarmer/jekyll-liquify .