为Jekyll博客添加RSS feed订阅功能

来源:互联网 发布:量子蚁群算法程序 编辑:程序博客网 时间:2024/06/05 20:24

我们都知道,很多人经常会在博客里面分享很多有价值的东西。我们通过别人的博客,获取知识,找到问题的解决办法,

寻求真理。但是,如果别人的博客有了更新的时候,我们如何第一时间获取到更新的消息呢?

RSS订阅是站点用来和其他站点之间共享内容的一种简易方式,即Really Simple Syndication(简易信息聚合)。


1、在_config.yml文件 添加(如果没有)下列属性:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. name:         blog Name  
  2. description:  A description for your blog  
  3. url:          http://your-blog-url.com  
这些值{{ site.name }},{{ site.description }},{{ site.url }}会在你的feed文件里用到。


2、在网站根目录下添加 feed.xml

我的feed.xml,代码如下:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. ---  
  2. layout: none  
  3. ---  
  4.   
  5. <?xml version="1.0" encoding="UTF-8"?>  
  6. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">  
  7.     <channel>  
  8.         <title>{{ site.name }}</title>  
  9.         <description>{{ site.description }}</description>  
  10.         <link>{{ site.baseurl}}{{ site.url }}</link>  
  11.         <atom:link href="{{ site.baseurl}}{{ site.url }}/feed.xml" rel="self" type="application/rss+xml" />  
  12.         {% for post in site.posts limit:10 %}  
  13.             <item>  
  14.                <title>{{ post.title }}</title>  
  15.                <description>{{ post.content | xml_escape }}</description>  
  16.                <pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>  
  17.                <link>{{ site.url }}{{ site.baseurl}}{{ post.url }}</link>  
  18.                <guid isPermaLink="true">{{ site.url }}{{ site.baseurl}}{{ post.url }}</guid>  
  19.                </item>  
  20.         {% endfor %}  
  21.     </channel>  
  22. </rss>  

3、发布

在你网站的合适地方添加如下代码:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. <a href="{{ site.url }}/feed.xml">RSS订阅</a>  
0 0