2010-06-14 35 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="/,所以只有那些真正開始/受到影響的鏈接。