Skip to content

Commit

Permalink
Merge pull request #911 from alexwlchan/improve-tags
Browse files Browse the repository at this point in the history
Make a couple of improvements to tags
  • Loading branch information
alexwlchan authored Oct 3, 2024
2 parents 3e8731a + b24221f commit c3f6554
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/_includes/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
<li class="tags">
Tagged with
{% assign tags = page.visible_tags | sort %}
{% for t in tags %}
<a href="/tags/{{ t }}/">{{ t }}</a>{% unless forloop.last %}, {% endunless %}
{% for tag_name in tags %}
{% include tag_link.html -%}
{%- unless forloop.last %}, {% endunless %}
{% endfor %}
</li>
{% endif %}
Expand Down
6 changes: 6 additions & 0 deletions src/_includes/tag_link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% if tag_name contains ":" %}
{% assign parts = tag_name | split: ":" %}
<a href="/tags/{{ parts[0] }}/{{ parts[1] }}/">{{ tag_name }}</a>
{%- else -%}
<a href="/tags/{{ tag_name }}/">{{ tag_name }}</a>
{%- endif -%}
6 changes: 5 additions & 1 deletion src/_layouts/tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

<article>
<h1 class="title">
<a href="/tags/">Tags</a> » {{ page.tag }}
<a href="/tags/">Tags</a>
{% if page.namespace != "" %}
» <a href="/tags/{{ page.namespace }}/">{{ page.namespace }}</a>
{% endif %}
» {{ page.tag_name }}
</h1>

{% if page.featured_posts.size > 0 %}
Expand Down
23 changes: 20 additions & 3 deletions src/_plugins/tagging.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# This plugin contains a bunch of logic for the way I do tagging.

def visible?(tag_name, count)
if tag_name.include?(':') && (count >= 3)
true
else
!tag_name.include? ':'
end
end

Jekyll::Hooks.register :site, :post_read do |site|
# This hook runs before the site is built, and adds the following fields
# to the `site` object:
Expand Down Expand Up @@ -33,7 +41,7 @@

site.data['visible_tags'] =
site.data['tag_tally']
.filter { |_, count| count >= 3 }
.filter { |tag_name, count| visible?(tag_name, count) }
.keys

visible_posts.each do |doc|
Expand Down Expand Up @@ -93,7 +101,15 @@ class TagPage < Jekyll::Page
def initialize(site, visible_posts, tag)
@site = site
@base = site.source
@dir = "tags/#{tag}"

if tag.include? ':'
namespace, tag_name = tag.split(':')
@dir = "tags/#{namespace}/#{tag_name}"
else
namespace = ''
tag_name = tag
@dir = "tags/#{tag}"
end

@basename = 'index'
@ext = '.html'
Expand All @@ -110,7 +126,8 @@ def initialize(site, visible_posts, tag)

@data = {
'layout' => 'tag',
'tag' => tag,
'namespace' => namespace,
'tag_name' => tag_name,
'title' => "Tagged with ‘#{tag}’",
'featured_posts' => featured_posts,
'remaining_posts' => remaining_posts
Expand Down
2 changes: 2 additions & 0 deletions src/_posts/2017/2017-02-11-backup-your-instapaper.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ tags:
- python
- instapaper
title: A script for backing up your Instapaper bookmarks
index:
exclude: true
---

About three days ago, there was [an extended outage][outage] at Instapaper.
Expand Down
2 changes: 2 additions & 0 deletions src/_posts/2018/2018-05-14-google-duplex.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ tags:
- accessibility
- ableism
- inclusion
index:
exclude: true
---

Last week was Google I/O, and there was a lot of discussion around one of their keynote demos: Google Duplex.
Expand Down
2 changes: 2 additions & 0 deletions src/_posts/2018/2018-08-07-finding-slow-builds-in-travis.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ tags:
- travis
- python
- builds-and-ci
index:
exclude: true
---

For a while, I've been whinging on Twitter about Scala compile times -- mostly driven by the ever-increasing length of the Travis builds at work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ I started writing about how to work with ICNS files in Pillow, and it got quite
I remembered the [Zen of Python][zen] -- *"If the implementation is hard to explain, it's a bad idea"* -- and I went back to the drawing board.

[Pillow]: https://pillow.readthedocs.io/
[pillow_posts]: /tags/python:pillow/
[pillow_posts]: /tags/python/pillow/
[pillow_icns]: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html?highlight=icns#icns
[zen]: https://www.python.org/dev/peps/pep-0020/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: til
title: "Beware of using `test -n` with command expansion"
date: 2024-01-22 10:16:06 +0000
tags:
- fish
- fish-shell
---
I'd written a fish script that used `test -n` (check for an empty string) and a command substitution, but I was seeing unexpected results:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: til
date: 2024-02-22 12:33:03 +0000
title: How to check when an HTTPS certificate expires
tags:
- https
- http
- curl
---
You can check whether a certificate is about to expire using the following `openssl` command:
Expand Down
4 changes: 2 additions & 2 deletions src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ Here are some of my favourite things [that I've written](/articles/):
Here are some of the topics I write about:

<ul class="dot_list">
{% for tag in site.data['popular_tags'] %}
<li><a href="/tags/{{ tag }}/">{{ tag }}</a></li>
{% for tag_name in site.data['popular_tags'] %}
<li>{% include tag_link.html %}</li>
{% endfor %}
</ul>

Expand Down
2 changes: 1 addition & 1 deletion src/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ title: Tags
<ul id="tags">
{% for tag_name in visible_tags %}
<li>
<a href="/tags/{{ tag_name }}/">{{ tag_name }}</a>
{% include tag_link.html %}
({{ site.data['tag_tally'][tag_name] }})
</li>
{% endfor %}
Expand Down

4 comments on commit c3f6554

@alexwlchan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://alexwlchan.net as production
🚀 Deployed on https://66ff1b7b65050f46320a99f3--alexwlchan.netlify.app

@alexwlchan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://alexwlchan.net as production
🚀 Deployed on https://66ff9a6ed9202cce76db054f--alexwlchan.netlify.app

@alexwlchan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://alexwlchan.net as production
🚀 Deployed on https://6700ebf552c2bbb4745d3e48--alexwlchan.netlify.app

@alexwlchan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://alexwlchan.net as production
🚀 Deployed on https://67023d51a9abf90138e0f511--alexwlchan.netlify.app

Please sign in to comment.