zoukankan      html  css  js  c++  java
  • 2019-9-2-给博客添加rss订阅

    title author date CreateTime categories
    给博客添加rss订阅
    lindexi
    2019-09-02 12:57:38 +0800
    2018-2-13 17:23:3 +0800

    如果是自己搭建博客,有一个问题是如何写一篇新的文章就可以告诉读者,你写了一篇新的?一个简单方法是使用 rss ,RSS订阅是站点用来和其他站点之间共享内容的一种简易方式,即Really Simple Syndication(简易信息聚合),使用这个东西就可以把自己写的博客推送给读者。 本文告诉大家,如果在博客配置 rss 让读者可以订阅。

    一般在很多网站都可以看到这个图标,这就是rss,他可以把最新的文章发给你。如果自己的博客没有添加 rss 那么大家需要打开博客才可以发现你写了新的文章,所以建议在博客添加。

    在配置之前,需要知道 rss 的格式,实际上 rss 的格式可以看 www.w3school.com.cn/rss/rss_syntax.asp ,但是使用的很简单。

    <?xml version="1.0" encoding="UTF-8"?>  
    <rss version="2.0">  
      <channel>  
        <title>博客标题</title>  
        <link>博客地址</link>  
        <description>网站描述</description>  
        <language>语言</language>  
        <item>  
          <title>第一篇</title>  
          <description>摘要</description>  
          <author>作者</author>  
          <pubDate>发布时间</pubDate>  
          <link>链接</link>  
          <guid>链接</guid>  
        </item>  
      <channel>  
    </rss>  

    可以看到 channel 的 title 指的是博客的标题,language 指的是语言,如中文 zh-CN 。如果有多个博客,那么写在 item 那里,其中 link 和 guid 设置为相同。

    请看我博客的 rss ,atom 是可以不写

    <?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
        <title>林德熙</title>
        <description>Windows 10 Developer</description>
        <link>https://lindexi.gitee.io/lindexi/</link>
        <atom:link href="https://lindexi.gitee.io/lindexi/feed.xml" rel="self" type="application/rss+xml"/>
        <pubDate>Thu, 07 Dec 2017 11:02:39 +0800</pubDate>
        <lastBuildDate>Thu, 07 Dec 2017 11:02:39 +0800</lastBuildDate>
        <generator>Jekyll v3.4.3</generator>
        <item>  
          <title>第一篇</title>  
          <description>摘要</description>  
          <author>作者</author>  
          <pubDate>发布时间</pubDate>  
          <link>链接</link>  
          <guid>链接</guid>  
        </item> 
        <item>  
          <title>第二篇</title>  
          <description>摘要</description>  
          <author>作者</author>  
          <pubDate>Wed, 29 Nov 2017 00:00:00 +0800</pubDate>
          <category>uwp</category>  
          <link>链接</link>  
          <guid>链接</guid>  
        </item> 
        </channel>
        </rss>

    需要注意这里的时间都是这样写Wed, 29 Nov 2017 00:00:00 +0800,所以可以使用自动生成。如果使用的是 jekyll 大概可以直接复制我下面代码到 rss 文件。实际上去我希望你去我的项目复制文件。

    {% raw %}

    <?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
        <title>{{ site.title | xml_escape }}</title>
        <description>{{ site.description | xml_escape }}</description>
        <link>{{ site.url }}{{ site.baseurl }}/</link>
        <atom:link href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}" rel="self" type="application/rss+xml"/>
        <pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
        <lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
        <generator>Jekyll v{{ jekyll.version }}</generator>
        {% for post in site.posts limit:10 %}
          <item>
            <title>{{ post.title | xml_escape }}</title>
            <description>{{ post.content | xml_escape }}</description>
            <pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
            <link>{{ post.url | prepend: site.baseurl | prepend: site.url }}</link>
            <guid isPermaLink="true">{{ post.url | prepend: site.baseurl | prepend: site.url }}</guid>
            {% for tag in post.tags %}
            <category>{{ tag | xml_escape }}</category>
            {% endfor %}
            {% for cat in post.categories %}
            <category>{{ cat | xml_escape }}</category>
            {% endfor %}
          </item>
        {% endfor %}
      </channel>
    </rss>
    

    {% endraw %}

    需要在 _config.yml 设置 site.description 等

    现在很多小伙伴喜欢在极客头条分享自己的博客,这也是我访问最多的地方。

    这样就可以写完博客告诉小伙伴,让大家学到。

    推荐一个rss工具 攸阅 可以把自己订阅的博客发到邮箱。

    如果需要自己写一个,可以抄袭我的win10 UWP RSS阅读器

  • 相关阅读:
    ZooKeeper实践:(1)集群管理
    删除重复数据只保留一条
    查询sqlserver 大小写
    字段按位数自动加空格
    批量更新数据遍历数据
    测试端口号是否开通
    收缩数据库
    插入ID=-1 的数据
    查询重复语句,多表查询
    oracle数据查询时间
  • 原文地址:https://www.cnblogs.com/lindexi/p/12086458.html
Copyright © 2011-2022 走看看