2010-06-14 20 views
2

我的博客由Jekyll提供,提供Atom订阅源。扩展Jekyll和Liquid解析帖子内容

--- 
layout: nill 
rooturi: http://stefan.artspace44.com 
--- 

<?xml version="1.0" encoding="utf-8"?> 
<feed xmlns="http://www.w3.org/2005/Atom"> 

... 

{% for post in site.posts %} 
    <entry> 
    <title>{{ post.title }}</title> 
    <link href="{{ page.rooturi }}{{ post.url }}" /> 
    <updated>{{post.date | date_to_xmlschema }}</updated> 
    <id>{{ page.rooturi }}{{ post.id }}</id> 
    <content type="html">{{ post.content | xml_escape }}</content> 
    </entry> 
{% endfor %} 
</feed> 

我需要更改每个帖子的内容,使

<img href="/images/01.jpg" /> 
<a href="/2010/post/">Post</a> 

变为:

<img href="http://stefan.artspace44.com/images/01.jpg" /> 
<a href="http://stefan.artspace44.com/2010/post/">Post</a> 

我想沿着

线做某事
<content type='html'> 
    {{ post.content | make_hrefs_base page.rooturi }} 
</content> 

会在哪里我jekyllliquid代码这一点,我怎么能解决只改变HREF值指向“/ ”,而不是“http://otherdomain.com/”的问题呢?

谢谢

回答

3

会在哪里我在杰基尔或液体的代码呢?

在最近发布的Jekyll 0.6.0中,您可以创建自己的插件,包括Liquid标签插件。你可以查看Jekyll plugin文档以获取更多信息,但这将是你最好的选择。

我该如何解决只改变指向“/”而不是“http://otherdomain.com/”的href值的问题?

看起来很容易。在您的自定义Liquid标签中,检查第一个字符是否为'/';如果是,则预先安装您的新域。您可以使用Ruby HTML解析器来查找<a>的所有实例,然后根据需要更改href属性。

0

我在the feed of my blog有同样的问题,我设法解决它没有使用插件,即只有香草液。

my Atom XML file,我的内容填充像这样:

<content type="html"> 
    {{ post.content | replace: site.feed_linkurl_find, site.feed_linkurl_replace | replace: site.feed_imgurl_find, site.feed_imgurl_replace | xml_escape }} 
</content> 

...我在my config file有这些变量:

# URL replacements for feeds 
feed_linkurl_find: href="/ 
feed_linkurl_replace: href="http://christianspecht.de/ 
feed_imgurl_find: src="/ 
feed_imgurl_replace: src="http://christianspecht.de/ 

换句话说,我只需要做两ordinary string replaces,一个用于链接,另一个用于图像。

的诀窍是:
在这两种情况下,我通过href="http://christianspecht.de/更换href="/,所以只有那些真正开始/受到影响的链接。