tocttou / hacker-blog

Hacker-Blog is a minimalistic, responsive jekyll theme built for hackers. https://ashishchaudhary.in/hacker-blog
Creative Commons Zero v1.0 Universal
316 stars 534 forks source link

use absolute URLs in atom.xml and fix broken URL #23

Open MichaelCurrin opened 3 years ago

MichaelCurrin commented 3 years ago

Refactor

Adding site.url is not a good pattern in Jekyll.

In particular, if someone uses this repo on a subpath, the code would break, because site.url does not include site.baseurl.

If you do this:

{{ post.url | absolute_url }}

That uses the site.url and site.baseurl values for you

e.g. I tested locally and got:

<link>https://michaelcurrin.github.io/jekyll-blog-demo/jekyll/update/2018/12/18/welcome-to-jekyll/</link>

I also refactored the other parts not around posts, to use absolute_url.

Note that when running locally you should do this, so that site.url is used as domain instead of localhost.

JEKYLL_ENV=production bundle exec jekyll build --trace

Fix

I replaced feed.xml with atom.xml in the file.

MichaelCurrin commented 3 years ago

Here is the full output when I ran locally. Just the URLs matter. Note that I don't have author set up on my site.

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
    xmlns:atom="http://www.w3.org/2005/Atom">

    <channel>
        <title>Jekyll Blog Demo</title>
        <description>Starter for a static website or blog - built with Jekyll, a minimal theme and GH Pages</description>
        <link>https://michaelcurrin.github.io/jekyll-blog-demo/</link>
        <atom:link href="https://michaelcurrin.github.io/jekyll-blog-demo/atom.xml" rel="self" type="application/rss+xml" />

        <author>
            <name></name>
            <email></email>
            <uri></uri>
        </author>

        <item>
            <title>First post!</title>
            <description>&lt;p&gt;This is my first post after the one created as part of the blog template.&lt;/p&gt;
</description>
            <pubDate>Sat, 22 Dec 2018 00:00:00 +0200</pubDate>

            <link>https://michaelcurrin.github.io/jekyll-blog-demo/2018/12/22/first-post/</link>
            <link href="https://michaelcurrin.github.io/jekyll-blog-demo/2018/12/22/first-post/"/>
            <guid isPermaLink="true">https://michaelcurrin.github.io/jekyll-blog-demo/2018/12/22/first-post/</guid>
        </item>

        <item>
            <title>Welcome to Jekyll!</title>
            <description>&lt;p&gt;You’ll find this post in your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_posts&lt;/code&gt; directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jekyll serve&lt;/code&gt;, which launches a web server and auto-regenerates your site when a file is updated.&lt;/p&gt;

&lt;p&gt;To add new posts, simply add a file in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_posts&lt;/code&gt; directory that follows the convention &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;YYYY-MM-DD-name-of-post.ext&lt;/code&gt; and includes the necessary front matter. Take a look at the source for this post to get an idea about how it works.&lt;/p&gt;

&lt;p&gt;Jekyll also offers powerful support for code snippets.&lt;/p&gt;

&lt;p&gt;Using backticks.&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;print_hi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hi, &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;print_hi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;Tom&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#=&amp;gt; prints &apos;Hi, Tom&apos; to STDOUT.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;highlight&lt;/code&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;print_hi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hi, &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;print_hi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;Tom&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#=&amp;gt; prints &apos;Hi, Tom&apos; to STDOUT.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Check out the &lt;a href=&quot;https://jekyllrb.com/docs/home&quot;&gt;Jekyll docs&lt;/a&gt; for more info on how to get the most out of Jekyll. File all bugs/feature requests at &lt;a href=&quot;https://github.com/jekyll/jekyll&quot;&gt;Jekyll’s GitHub repo&lt;/a&gt;. If you have questions, you can ask them on &lt;a href=&quot;https://talk.jekyllrb.com/&quot;&gt;Jekyll Talk&lt;/a&gt;.&lt;/p&gt;

</description>
            <pubDate>Tue, 18 Dec 2018 18:24:52 +0200</pubDate>

            <link>https://michaelcurrin.github.io/jekyll-blog-demo/jekyll/update/2018/12/18/welcome-to-jekyll/</link>
            <link href="https://michaelcurrin.github.io/jekyll-blog-demo/jekyll/update/2018/12/18/welcome-to-jekyll/"/>
            <guid isPermaLink="true">https://michaelcurrin.github.io/jekyll-blog-demo/jekyll/update/2018/12/18/welcome-to-jekyll/</guid>
        </item>

    </channel>
</rss>
MichaelCurrin commented 3 years ago

Also by the way it looks weird that the live atom.xml page in your linked site uses a completely different format. e.g. feed and entry, which are not in the atom file I edited.

Screen Shot 2021-09-17 at 12 05 13 pm