From 0403f2d5aeb1ce4e67fdbb30b65a728f80c1cc1f Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 25 Jan 2025 12:18:02 +0100 Subject: add tag index --- _includes/posts.html | 6 +----- _includes/search.html | 6 ++++++ _layouts/default.html | 1 + _plugins/meta.rb | 23 ++++++++++++++++++++++- _sass/layout.scss | 11 ++++++++--- posts/style.scss | 7 ------- readme.md | 4 ---- tags.html | 28 ++++++++++++++++++++++++++++ 8 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 _includes/search.html create mode 100644 tags.html diff --git a/_includes/posts.html b/_includes/posts.html index 05eebe7..cdd9b47 100644 --- a/_includes/posts.html +++ b/_includes/posts.html @@ -1,10 +1,6 @@ - +{% include search.html %} diff --git a/_includes/search.html b/_includes/search.html new file mode 100644 index 0000000..cc8cd56 --- /dev/null +++ b/_includes/search.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/_layouts/default.html b/_layouts/default.html index 9c2204f..fa4902f 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -24,6 +24,7 @@
home posts + tags {% if page.toc %}top{% endif %} {% if page.post %}bottom{% endif %} diff --git a/_plugins/meta.rb b/_plugins/meta.rb index d1d4a24..28afd13 100644 --- a/_plugins/meta.rb +++ b/_plugins/meta.rb @@ -3,7 +3,8 @@ class Meta < Jekyll::Generator # convert yaml @0123456789 (unix timestamps) into ruby Date site.data = parse_unix_dates(site.data) - for page in site.collections['items'] do + posts = site.collections['items'] + for page in posts do # convert generated page metadata and add directly to `page.meta` in liquid page.data['meta'] = transform_data(site, page.slug) @@ -15,6 +16,9 @@ class Meta < Jekyll::Generator # set page.date to generated date_initial page.data['date'] = page.data['meta']['date'] end + + # count tags on all posts + site.data['tags'] = count_tags(posts) end def parse_unix_dates(data) @@ -43,4 +47,21 @@ class Meta < Jekyll::Generator data['edits'] = git_log.length - 1 # original commit is not an edit return data end + + def count_tags(posts) + tags = {} + + # tally tags + for post in posts do + for tag in post.tags do + tags[tag] = tags.fetch(tag, 0) + 1 + end + end + + # sort by post count descending + tags = tags.sort_by {|key,value| -value} + + return tags + end end + diff --git a/_sass/layout.scss b/_sass/layout.scss index 9666867..18ee411 100644 --- a/_sass/layout.scss +++ b/_sass/layout.scss @@ -67,11 +67,9 @@ aside ul { aside > ul { margin-left: 12px; } // align description arrow with list bullet inside toc -aside summary { list-style-position: outside; } - +summary { list-style-position: outside; } // hide bullets for list items that can be expanded li.stub::marker { content: ""; } - // give collapsable element arrow "clickable" cursor summary::marker { cursor: pointer; } @@ -115,3 +113,10 @@ footer ul { flex-grow: 1; } +#search { + display: flex; + gap: 6px; + margin: 24px 0px; +} +#search input[type=text] { flex-grow: 1; } + diff --git a/posts/style.scss b/posts/style.scss index 532f491..b1a363f 100644 --- a/posts/style.scss +++ b/posts/style.scss @@ -17,10 +17,3 @@ // dates with table numerals #posts td:nth-child(1) { font-feature-settings: "tnum"; } -#search { - display: flex; - gap: 6px; - - margin-bottom: 24px; -} -#search input[type=text] { flex-grow: 1; } diff --git a/readme.md b/readme.md index 4b88963..f757713 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,3 @@ Live at -## TODO - -- tag index - diff --git a/tags.html b/tags.html new file mode 100644 index 0000000..7892800 --- /dev/null +++ b/tags.html @@ -0,0 +1,28 @@ +--- +title: Tags +layout: default +id: tags +toc: false +post: false +--- + +
    + {% assign tags = site.data.tags %} + {% for tag in tags %} +
  • +
    + + {{ tag[0] }} ({{ tag[1] }}) + +
      + {% assign posts = site.items | where_exp: "post", "post.tags contains tag[0]" %} + {% for post in posts %} +
    • {{ post.title }}
    • + {% endfor %} +
    +
    +
  • + {% endfor %} +
+ + -- cgit v1.2.3