我在 Jekyll 中有一个 RSS 模板,如下所示:
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>{{ site.title }}</title>
<link href="{{ site.url }}/feed.atom" rel="self"/>
<link href="{{ site.url }}/"/>
<updated>{{ site.time | date_to_xmlschema }}</updated>
<id>{{ site.url }}/</id>
<author>
<name>{{ site.author.name }}</name>
<email>{{ site.author.email }}</email>
</author>
{% for post in site.posts limit:20 %}
<entry>
<title>{{ post.title }}</title>
<link href="{{ site.url }}{{ post.url }}"/>
<updated>{{ post.date | date_to_xmlschema }}</updated>
<id>{{ site.url }}{{ post.id }}</id>
<content type="html">{{ post.content | replace:'src="/assets','src="http://example.com/assets' | xml_escape }}</content>
</entry>
{% endfor %}
</feed>
Run Code Online (Sandbox Code Playgroud)
现在,我想http://example.com(当前是硬编码的)被{{ site.url }}变量替换。我尝试了很多方法,但无法实现。
部分答案就在问题中:
{{ post.content | replace:'src="/assets','src="http://example.com/assets' | xml_escape | replace: 'http://example.com', site.url }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2331 次 |
| 最近记录: |