• Upgrading Jekyll 2.x to 4.x



    (or: I already mentioned it's a very old Jekyll setup)


    Turns out I did make it to item #984 on my TODOs.
    Upgrading Jekyll has proven to be far easier than migrating to Hugo.
    There were only 2 issues to tackle:

    Issue 1 - Generating Categories and Tags in Jekyll 4.x.x

    The old scripts of generate_categories.rb and generate_tags.rb and their corresponding liquid filters: tag_links and category_links no longer seem to do the trick in Jekyll 4.
    Is it likely possible to fix these functions and keep using the liquid filters? Probably. Is it necessary? Nope.

    It's much easier to just build a template that does the same job and is certainly more future-proof.
    In short, this was the old template:

    old_template.html
    1
    2
    3
    4
    5
    
    {% raw %}
    <!-- This used to work for Jekyll 2 -->
    <div class="post-tags">Tagged with <span>{{ post.tags | tag_links }}</span></div>
    <div class="post-category">Posted in <span>{{ post.categories | category_links }}</span></div>
    {% endraw %}
    new_template.html
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    
    {% raw %}
    {% comment %}<!-- TODO put this in a separate include to save some trouble. Obviously there's some room for improvement here. -->{% endcomment %}
    <div class="post-tags">Tagged with <span>
      {% for tag in post.tags %}
      <a class="tag" href="{{ "/tag/" | append: tag | downcase | replace: " ", "-" | uri_escape }}">{{ tag }}</a>{% if forloop.last %}{% else %}, {% endif %}
      {% endfor %}
    </span></div>
    <div class="post-category">Posted in <span>
      {% for category in post.categories %}
      <a class="category" href="{{ "/category/" | append: category | downcase | replace: " ", "-" | uri_escape }}">{{ category }}</a>{% if forloop.last %}{% else %}, {% endif %}
      {% endfor %}
    </span></div>
    {% endraw %}
    Full example here (including the old scripts and new template).

    Issue 2 - Unrendered liquid in Paginator

    On generated pages (page/##) I was getting unrendered Jekyll liquid code for my meta_description.
    Why? Not sure. A relatively simple IF change helped handle this and grab the correct parts -
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    {% comment %} TODO this should likely be resolved by proper layout usage (dedicated paginator page layout for starters) {% endcomment %}
    
    {% assign meta_desc = site.description %}
    {% raw %}{% unless page.url == '/' %}
      {% if page.meta_description %}
        {% capture meta_desc %}{{ page.meta_description }}{% endcapture %}
      {% elsif page.excerpt %}
        {% capture meta_desc %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% endcapture %}
      {% elsif page.content %}
        {% if page.content contains "for post in paginator.posts" %}
          {% capture meta_desc %}{{ paginator.posts | first | strip_html | strip_newlines | strip | split: " - " | first | truncate: 160 }}{% endcapture %}
        {% else %}
          {% capture meta_desc %}{{ page.content | strip_html | strip_newlines | strip | truncate: 160 }}{% endcapture %}
        {% endif %}
      {% endif %}
    {% endunless %}
    {% endcapture %}
    <meta name="description" content="{{ meta_desc }}">
    {% endraw %}
    This ended up giving me the same meta_descriptions as I used to get on Jekyll 2.x.

    The good news is that the build time has decreased by 10X!
    The really good news is that it's now fully within GitHub Actions!
  • Adventures of a very old Jekyll Setup



    A waterfall of errors

    So I've been writing on an old Jekyll website of mine.
    Sooner or later I promised myself to move it to Hugo, however it's #983 on the TODO list.
    For now, during the build I have been bombarded with the following 5 errors on repeat:
    1
    2
    3
    4
    5
    
    /var/lib/gems/2.7.0/gems/jekyll-3.1.2/lib/jekyll/convertible.rb:42: warning: Using the last argument as keyword parameters is deprecated
    /var/lib/gems/2.7.0/gems/jekyll-3.1.2/lib/jekyll/document.rb:265: warning: Using the last argument as keyword parameters is deprecated
    /var/lib/gems/2.7.0/gems/jekyll-3.1.2/lib/jekyll/tags/include.rb:169: warning: Using the last argument as keyword parameters is deprecated
    /var/lib/gems/2.7.0/gems/jekyll-3.1.2/lib/jekyll/url.rb:119: warning: URI.escape is obsolete
    /var/lib/gems/2.7.0/gems/rb-inotify-0.9.7/lib/rb-inotify/watcher.rb:66: warning: rb_safe_level will be removed in Ruby 3.0
    Obviously the real answer here would be to upgrade my Jekyll setup to ensure Ruby stops complaining about my ancient stack.
    I have promptly placed upgrading my stack as item #984 on the TODO list (as this is running in isolation, it's not a huge threat).

    For the time being, I am using the following command to silence the noise:
    1
    
    bundle exec jekyll serve 2>&1 | egrep -v 'deprecated|obsolete|rb_safe_level'
  • AWS S3 Sync in GitHub Actions



    Using GitHub Actions to deploy your static website to S3?

    Great!

    Using AWS S3 Sync command?

    Amazing!

    Did you make sure you have the `--size-only` flag on?

    Without `--size-only`, your entire bucket will be uploaded each time your push to your branch. This includes contents that haven't changed at all.

    Why?

    By default, AWS S3 Sync compares the timestamp of your source and destination files. If the timestamp doesn't match - the file will be uploaded. This is a problem, since the files are newly created on each build (they are checked out as part of the workflow). To ensure only size is compared, use the `--size-only` flag like so:
    1
    
    aws s3 sync ./ s3://YOUR_BUCKET_NAME --size-only --exclude '.git/*' --exclude '.github/*'
    p.s. You may have noticed I've also excluded the .git/ and .github/ folders.

    You're welcome ;)