代码之家  ›  专栏  ›  技术社区  ›  Stefan

扩展jekyll和liquid以解析post的内容

  •  2
  • Stefan  · 技术社区  · 15 年前

    我的博客,由 Jekyll 提供一个 Atom 饲料。

    ---
    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>
    

    我要在哪里编码 jekyll liquid 以及如何解决只改变 HREF 指向“”的值/ “而不是” http://otherdomain.com/ “?

    谢谢你

    2 回复  |  直到 10 年前
        1
  •  3
  •   mipadi    15 年前

    我在哪里可以用Jekyll或Liquid编码?

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

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

    看起来很容易。在自定义的Liquid标记中,检查第一个字符是否是“/”;如果是,则预先准备新域。您可以使用RubyHTML解析器查找 <a> ,然后更改 href 属性视情况而定。

        2
  •  1
  •   Christian Specht    10 年前

    我也有同样的问题 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="/ 通过 href="http://christianspecht.de/ ,所以只有那些链接 开始 具有 / 受到影响。

    推荐文章