paritybit.ca

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 1648546e74e052eda3fb519f357bf2943ee63fd9
parent 025385e24a8d8661c74a975ea602b8a2a98c9e3e
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Sun, 21 Jun 2020 00:06:08 -0400

Publish new blog post

Diffstat:
Mpages/blog.md | 1+
Apages/blog/how-to-create-an-rss-feed-for-your-blog-3.md | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpages/home.md | 4++--
Mpublic/feeds/sitewide-feed.xml | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpublic/sitemap.xml | 1+
5 files changed, 169 insertions(+), 2 deletions(-)

diff --git a/pages/blog.md b/pages/blog.md @@ -20,6 +20,7 @@ href="https://social.paritybit.ca/@jbauer">Mastodon</a>. ### 2020 <ul> + <li>2020-06-20 <a href="blog/how-to-create-an-rss-feed-for-your-blog-3">How to Create an RSS Feed for Your Blog — 3 — Automating Updates</a></li> <li>2020-06-19 <a href="blog/how-to-create-an-rss-feed-for-your-blog-2">How to Create an RSS Feed for Your Blog — 2 — The Basics</a></li> <li>2020-06-18 <a href="blog/how-to-create-an-rss-feed-for-your-blog-1">How to Create an RSS Feed for Your Blog — 1 — Why?</a></li> <li>2020-06-16 <a href="blog/my-beginnings-with-gentoo">My Beginnings with Gentoo</a></li> diff --git a/pages/blog/how-to-create-an-rss-feed-for-your-blog-3.md b/pages/blog/how-to-create-an-rss-feed-for-your-blog-3.md @@ -0,0 +1,106 @@ +## How to Create an RSS Feed for Your Blog — 3 — Automating Updates + +[//]: # "If you have a blog then you should be syndicating your posts through an RSS feed. This is part 3 in a series about why you should have an RSS feed and how to do it." + +[//]: # "main.min.css" + +[//]: # "The General Approach; Conclusion" + +<div class="byline"> +<b>Written By:</b> Jake Bauer | + <b>Posted:</b> 2020-06-20 | + <b>Last Updated:</b> 2020-06-20 +</div> + +This is the third part in a series about creating an RSS feed for your website. +[Click here to read the first +part](https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-1) +about why you should have an RSS feed if you don't already have one and [click +here to read the second part](https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-2) about writing a basic feed. In this part, I'll be talking a bit about automating updates to your feed and showing you how I do it. + +### The General Approach + +Once you know what sort of elements you want your feed items to have (e.g. +`<author>`, `<link>`, etc), you can fairly easily script updates to your feed. +Unfortunately, I can't describe exactly how you should do this since it would +differ depending on what operating system you're using and what tools you have +available. If you can leverage something like a static site generator to +generate your feeds for you, then this article is probably not going to be of +much help to you. + +To keep my feed up to date and to generate `<item>`s, I have a POSIX shell +script that I use to publish my posts. You can [view the publish +script](https://git.sr.ht/~jbauer/paritybit.ca/tree/master/publish) in its +entirety online, but I've extracted just the bit which updates my feed and +pasted it below: + +```bash +create_rss_entry() +{ + print_info_msg "Creating RSS entry" + + # Opening tag + rssEntry="${rssEntry}<item>" + + # Set <title> + rssEntry="${rssEntry} + <title>$pageTitle</title>" + + # Set <link> and <guid> + rssEntry="${rssEntry} + <link>$baseURL/$fileName</link>" + rssEntry="${rssEntry} + <guid>$baseURL/$fileName</guid>" + + # Set pubDate + rssEntry="${rssEntry} + <pubDate>$date</pubDate>" + + # Fill out content + pageContent=$(cat build/blog/"$fileName"-content.html) + rssEntry="${rssEntry} + <description><![CDATA[$pageContent]]></description>" + + # Close the entry + rssEntry="${rssEntry} + </item>" +} + +update_rss_feed() +{ + print_info_msg "Updating RSS feed" + mv "$mainFeed" "$mainFeed.bak" + head -n 8 "$mainFeed.bak" > "$mainFeed" + echo "$rssEntry" >> "$mainFeed" + tail -n +9 "$mainFeed.bak" >> "$mainFeed" +} +``` + +It's actually fairly easy to generate feed entries through a simple script such +as this one, and the concepts used above could be easily translated into other +scripting languages like Perl or Python if you're more comfortable using those +languages. + +I have the benefit that [the static site generator I +use](https://git.sr.ht/~jbauer/tree/master/compile) outputs the HTML of just the +post—no HTML `<head>` or `<body>` tags included—as an intermediate step in the +process of compiling a page from Markdown to HTML. This allows me to easily +include the text of the post in the `<description>` tags, but it would be fairly +easy to extract just the HTML inside the `<main>` tag of your HTML page, should +you not have a site generator which does something like this. + +### Conclusion + +This concludes my simple, 3-part guide on creating an RSS feed for your own +website or blog. It's not very difficult to do and it provides numerous benefits +for your readers. If the process described in this mini-series seems like too +much work or too complicated, there is numerous feed generation software +available online. All that matters is that you create a feed for your site. + +In the future, I'll be looking more into Atom feeds and a series about them may +be coming soon. + +_This is my fiftieth post for the +[#100DaysToOffload](https://social.paritybit.ca/tags/100DaysToOffload) +challenge. You can learn more about this challenge over at +[https://100daystooffload.com](https://100daystooffload.com)._ diff --git a/pages/home.md b/pages/home.md @@ -20,6 +20,8 @@ extent)! Access through `gopher://paritybit.ca` or `gemini://paritybit.ca`. src="/img/feed-icon.png" width="15" height="15" alt="Click for RSS Feed"/> </a> </div> +2020-06-20 <a class="feed-item" href="blog/how-to-create-an-rss-feed-for-your-blog-3">How to Create an RSS Feed for Your Blog — 3 — Automating Updates</a> + 2020-06-19 <a class="feed-item" href="blog/how-to-create-an-rss-feed-for-your-blog-2">How to Create an RSS Feed for Your Blog — 2 — The Basics</a> 2020-06-18 <a class="feed-item" href="blog/how-to-create-an-rss-feed-for-your-blog-1">How to Create an RSS Feed for Your Blog — 1 — Why?</a> @@ -37,8 +39,6 @@ extent)! Access through `gopher://paritybit.ca` or `gemini://paritybit.ca`. 2020-06-11 <a class="feed-item" href="blog/improving-my-blog-post-publishing-script">Improving My Blog Post Publishing Script</a> 2020-06-11 <a class="feed-item" href="blog/trying-out-dwm">Trying Out dwm</a> - -2020-06-09 <a class="feed-item" href="blog/setting-up-a-status-page">Setting Up a Status Page</a> ### What is a Parity Bit? It is a bit (in the 1's and 0's sense) used in checking for errors in digital diff --git a/public/feeds/sitewide-feed.xml b/public/feeds/sitewide-feed.xml @@ -7,6 +7,65 @@ <description>The feed that covers all notable additions, updates, announcements, and other changes for the entire paritybit.ca website.</description> <item> + <title>How to Create an RSS Feed for Your Blog — 3 — Automating Updates</title> + <link>https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-3</link> + <guid>https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-3</guid> + <pubDate>Sun, 21 Jun 2020 00:01:44 -0400</pubDate> + <description><![CDATA[<h2 id="how-to-create-an-rss-feed-for-your-blog-3-automating-updates">How to Create an RSS Feed for Your Blog — 3 — Automating Updates</h2> +<div class="byline"> +<p><b>Written By:</b> Jake Bauer | <b>Posted:</b> 2020-06-20 | <b>Last Updated:</b> 2020-06-20</p> +</div> +<p>This is the third part in a series about creating an RSS feed for your website. <a href="https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-1">Click here to read the first part</a> about why you should have an RSS feed if you don’t already have one and <a href="https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-2">click here to read the second part</a> about writing a basic feed. In this part, I’ll be talking a bit about automating updates to your feed and showing you how I do it.</p> +<h3 id="the-general-approach">The General Approach</h3> +<p>Once you know what sort of elements you want your feed items to have (e.g. <code>&lt;author&gt;</code>, <code>&lt;link&gt;</code>, etc), you can fairly easily script updates to your feed. Unfortunately, I can’t describe exactly how you should do this since it would differ depending on what operating system you’re using andw hat tools you have available. If you can leverage something like a static site generator to generate your feeds for you, then this article is probably not going to be of much help to you.</p> +<p>To keep my feed up to date and to generate <code>&lt;item&gt;</code>s, I have a POSIX shell script that I use to publish my posts. You can <a href="https://git.sr.ht/~jbauer/paritybit.ca/tree/master/publish">view the publish script</a> in its entirety online, but I’ve extracted just the bit which updates my feed and pasted it below:</p> +<div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb1-1" title="1"><span class="fu">create_rss_entry()</span></a> +<a class="sourceLine" id="cb1-2" title="2"><span class="kw">{</span></a> +<a class="sourceLine" id="cb1-3" title="3"> <span class="ex">print_info_msg</span> <span class="st">&quot;Creating RSS entry&quot;</span></a> +<a class="sourceLine" id="cb1-4" title="4"></a> +<a class="sourceLine" id="cb1-5" title="5"> <span class="co"># Opening tag</span></a> +<a class="sourceLine" id="cb1-6" title="6"> <span class="va">rssEntry=</span><span class="st">&quot;</span><span class="va">${rssEntry}</span><span class="st">&lt;item&gt;&quot;</span></a> +<a class="sourceLine" id="cb1-7" title="7"></a> +<a class="sourceLine" id="cb1-8" title="8"> <span class="co"># Set &lt;title&gt;</span></a> +<a class="sourceLine" id="cb1-9" title="9"> <span class="va">rssEntry=</span><span class="st">&quot;</span><span class="va">${rssEntry}</span></a> +<a class="sourceLine" id="cb1-10" title="10"><span class="st"> &lt;title&gt;</span><span class="va">$pageTitle</span><span class="st">&lt;/title&gt;&quot;</span></a> +<a class="sourceLine" id="cb1-11" title="11"></a> +<a class="sourceLine" id="cb1-12" title="12"> <span class="co"># Set &lt;link&gt; and &lt;guid&gt;</span></a> +<a class="sourceLine" id="cb1-13" title="13"> <span class="va">rssEntry=</span><span class="st">&quot;</span><span class="va">${rssEntry}</span></a> +<a class="sourceLine" id="cb1-14" title="14"><span class="st"> &lt;link&gt;</span><span class="va">$baseURL</span><span class="st">/</span><span class="va">$fileName</span><span class="st">&lt;/link&gt;&quot;</span></a> +<a class="sourceLine" id="cb1-15" title="15"> <span class="va">rssEntry=</span><span class="st">&quot;</span><span class="va">${rssEntry}</span></a> +<a class="sourceLine" id="cb1-16" title="16"><span class="st"> &lt;guid&gt;</span><span class="va">$baseURL</span><span class="st">/</span><span class="va">$fileName</span><span class="st">&lt;/guid&gt;&quot;</span></a> +<a class="sourceLine" id="cb1-17" title="17"></a> +<a class="sourceLine" id="cb1-18" title="18"> <span class="co"># Set pubDate</span></a> +<a class="sourceLine" id="cb1-19" title="19"> <span class="va">rssEntry=</span><span class="st">&quot;</span><span class="va">${rssEntry}</span></a> +<a class="sourceLine" id="cb1-20" title="20"><span class="st"> &lt;pubDate&gt;</span><span class="va">$date</span><span class="st">&lt;/pubDate&gt;&quot;</span></a> +<a class="sourceLine" id="cb1-21" title="21"></a> +<a class="sourceLine" id="cb1-22" title="22"> <span class="co"># Fill out content</span></a> +<a class="sourceLine" id="cb1-23" title="23"> <span class="va">pageContent=$(</span><span class="fu">cat</span> build/blog/<span class="st">&quot;</span><span class="va">$fileName</span><span class="st">&quot;</span>-content.html<span class="va">)</span></a> +<a class="sourceLine" id="cb1-24" title="24"> <span class="va">rssEntry=</span><span class="st">&quot;</span><span class="va">${rssEntry}</span></a> +<a class="sourceLine" id="cb1-25" title="25"><span class="st"> &lt;description&gt;&lt;![CDATA[</span><span class="va">$pageContent</span><span class="st">]]&gt;&lt;/description&gt;&quot;</span></a> +<a class="sourceLine" id="cb1-26" title="26"></a> +<a class="sourceLine" id="cb1-27" title="27"> <span class="co"># Close the entry</span></a> +<a class="sourceLine" id="cb1-28" title="28"> <span class="va">rssEntry=</span><span class="st">&quot;</span><span class="va">${rssEntry}</span></a> +<a class="sourceLine" id="cb1-29" title="29"><span class="st"> &lt;/item&gt;&quot;</span></a> +<a class="sourceLine" id="cb1-30" title="30"><span class="kw">}</span></a> +<a class="sourceLine" id="cb1-31" title="31"></a> +<a class="sourceLine" id="cb1-32" title="32"><span class="fu">update_rss_feed()</span></a> +<a class="sourceLine" id="cb1-33" title="33"><span class="kw">{</span></a> +<a class="sourceLine" id="cb1-34" title="34"> <span class="ex">print_info_msg</span> <span class="st">&quot;Updating RSS feed&quot;</span></a> +<a class="sourceLine" id="cb1-35" title="35"> <span class="fu">mv</span> <span class="st">&quot;</span><span class="va">$mainFeed</span><span class="st">&quot;</span> <span class="st">&quot;</span><span class="va">$mainFeed</span><span class="st">.bak&quot;</span></a> +<a class="sourceLine" id="cb1-36" title="36"> <span class="fu">head</span> -n 8 <span class="st">&quot;</span><span class="va">$mainFeed</span><span class="st">.bak&quot;</span> <span class="op">&gt;</span> <span class="st">&quot;</span><span class="va">$mainFeed</span><span class="st">&quot;</span></a> +<a class="sourceLine" id="cb1-37" title="37"> <span class="bu">echo</span> <span class="st">&quot;</span><span class="va">$rssEntry</span><span class="st">&quot;</span> <span class="op">&gt;&gt;</span> <span class="st">&quot;</span><span class="va">$mainFeed</span><span class="st">&quot;</span></a> +<a class="sourceLine" id="cb1-38" title="38"> <span class="fu">tail</span> -n +9 <span class="st">&quot;</span><span class="va">$mainFeed</span><span class="st">.bak&quot;</span> <span class="op">&gt;&gt;</span> <span class="st">&quot;</span><span class="va">$mainFeed</span><span class="st">&quot;</span></a> +<a class="sourceLine" id="cb1-39" title="39"><span class="kw">}</span></a></code></pre></div> +<p>It’s actually fairly easy to generate feed entries through a simple script such as this one, and the concepts used above could be easily translated into other scripting languages like Perl or Python if you’re more comfortable using those languages.</p> +<p>I have the benefit that <a href="https://git.sr.ht/~jbauer/tree/master/compile">the static site generator I use</a> outputs the HTML of just the post—no HTML <code>&lt;head&gt;</code> or <code>&lt;body&gt;</code> tags included—as an intermediate step in the process of compiling a page from Markdown to HTML. This allows me to easily include the text of the post in the <code>&lt;description&gt;</code> tags, but it would be fairly easy to extract just the HTML inside the <code>&lt;main&gt;</code> tag of your HTML page, should you not have a site generator which does something like this.</p> +<h3 id="conclusion">Conclusion</h3> +<p>This concludes my simple, 3-part guide on creating an RSS feed for your own website or blog. It’s not very difficult to do and it provides numerous benefits for your readers. If the process described in this mini-series seems like too much work or too complicated, there is numerous feed generation software available online. All that matters is that you create a feed for your site.</p> +<p>In the future, I’ll be looking more into Atom feeds and a series about them may be coming soon.</p> +<p><em>This is my fiftieth post for the <a href="https://social.paritybit.ca/tags/100DaysToOffload">#100DaysToOffload</a> challenge. You can learn more about this challenge over at <a href="https://100daystooffload.com" class="uri">https://100daystooffload.com</a>.</em></p>]]></description> + </item> +<item> <title>How to Create an RSS Feed for Your Blog — 2 — The Basics</title> <link>https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-2</link> <guid>https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-2</guid> diff --git a/public/sitemap.xml b/public/sitemap.xml @@ -3,6 +3,7 @@ <url><loc>https://www.paritybit.ca</loc></url> <url><loc>https://www.paritybit.ca/home</loc></url> <url><loc>https://www.paritybit.ca/blog</loc></url> + <url><loc>https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-3</loc></url> <url><loc>https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-2</loc></url> <url><loc>https://www.paritybit.ca/blog/how-to-create-an-rss-feed-for-your-blog-1</loc></url> <url><loc>https://www.paritybit.ca/blog/my-beginnings-with-gentoo</loc></url>