Browse Source

Fixed bug and logic in the tag score system. Added a variable to limit the tag list. Updated readme.

gh-pages
Franco Masotti 3 years ago
parent
commit
712f68d030
Signed by: frnmst
GPG Key ID: 24116ED85666780A
  1. 31
      README.md
  2. 6
      _config.yml
  3. 85
      _includes/tag_list.html

31
README.md

@ -33,6 +33,8 @@ Jekyll theme.
- [Tags and categories](#tags-and-categories)
- [Overview](#overview-2)
- [The tags score system](#the-tags-score-system)
- [Until version `0.0.5`](#until-version-005)
- [From version `0.1.0`](#from-version-010)
- [Tags page](#tags-page)
- [Tags in posts](#tags-in-posts)
- [Excerpts](#excerpts)
@ -66,7 +68,7 @@ https://frnmst.github.io/the-flux-of-thought/
## Version
0.0.5
0.1.0
See all
[the-flux-of-thought releases](https://github.com/frnmst/the-flux-of-thought/releases).
@ -334,28 +336,45 @@ This list is just a set of links pointing to the appropriate entry in the
#### The tags score system
A list of tags is present on the home page, i.e: `./_pages/index.html`.
This list is just a set of links pointing to the appropriate entry in the
`./_pages/tags.md` page and are presented using a "score" criteria. All
This list is just a set of links pointing to an appropriate entry in the
`./_pages/tags.md` page, which are presented using a *score* criteria. All
occurrencies of a tag are counted globally. If that frequency is greater or
equal than the `min_tag_score` variable in the `_config.yml` file then the tag
list element is showed along with its score. On the other hand if the frequency
is less than `min_tag_core` the tag will not be shown. If you want all the
tags to be shown, simply set `min_tag_core` to `1`.
You can limit the number of tags from home and tags page by setting the
`limit_tag_links` variable to a positive integer number. If you set it `false`
the tags will not be limited.
You may have noticed that the tag list is presented in a descreasing number of
occurrencies per tags. This method was chosen so that the relevant content
is shown first.
The logic for all this was adapted from
##### Until version `0.0.5`
Until version `0.0.5`, the logic for all this was adapted from
[here](https://raisedbyturtles.org/shopify-associative-arrays)
and
[here](https://stackoverflow.com/questions/48529507/jekyll-show-post-count-for-sub-categories).
##### From version `0.1.0`
Since version `0.1.0` sorting is done first by *tag score* and then
alphabetically.
Some elements of logic were taken from [here](https://stackoverflow.com/questions/42846888/repeat-string-multiple-times-in-jekyll),
[here](https://www.matthewsessions.com/blog/liquid-slice-array/),
[here](https://stackoverflow.com/questions/54769586/how-to-display-tags-in-jekyll-and-get-the-tag-to-click-through-to-all-relevant-c)
and the official [Liquid documentation](https://shopify.github.io/liquid/).
#### Tags page
The purpose of this page is to present links to posts for each tag in the
website. This page reports *all* tags in the website without the "tags score"
website. This page reports *all* tags in the website without the *tags score*
system except that the list will be sorted with descreasing frequency.
The tags reported on the top of the page follow the *tags score* system.
Below the tags list there are links to each posts, organized by tags. If a user
clicks on one of the links in the tags list, the viewport will be moved to the
@ -529,6 +548,8 @@ jekyll-compress-html is released under the MIT license.
## Tests
This theme is guaranteed to work correctly with the following web browsers:
| OS | Browser | Executable | Version command | Browser Version |
|----|---------|------------|-----------------|-----------------|
| [Parabola GNU/Linux-libre](https://parabola.nu) | [Iceweasel](https://wiki.parabola.nu/iceweasel) | `/bin/iceweasel` | `$ iceweasel --version` | `Mozilla Iceweasel 61.0.2` |

6
_config.yml

@ -4,14 +4,14 @@ description: "My blog testing"
# This should point to your website source.
website_source: https://github.com/frnmst/the-flux-of-thought
# These should point to the-flux-of-thought repository.
software_version: "0.0.5"
software_version: "0.1.0"
# The following is used along the software_version variable to build the
# software version url.
software_release_base_url: https://github.com/frnmst/the-flux-of-thought/releases/tag
## Author Info
author_name: "Franco Masotti"
author_email: franco.masotti@student.unife.it
author_email: franco.masotti@live.com
## Site Settings
baseurl: "/the-flux-of-thought" # Base URL must end WITHOUT a slash, default: ""
@ -42,6 +42,8 @@ excerpt_words: 20
## Tags
min_tag_score: 2
# Set the following to false to avoid limiting the tag links.
limit_tag_links: 16
## Meta tag options
meta_description_words: 140

85
_includes/tag_list.html

@ -1,46 +1,81 @@
{% comment %} This is pure madness: an O(n^2) loop is not acceptable but
there is no other solution I am aware of using this templating
language. Using uniq to filter different frequencies should
lead to a better best case (if all frequencies are equal
we get O(n) with n being the number of tags, otherwise
if all freqencies are different we get O(n^2) {% endcomment %}
{% comment %} Get all unique tags {% endcomment %}
{% comment %}The following structure is
the one used in the sorting:
sort by tag frequency and by name after building a
data structure, like this:
frequency|tag name
==================
000008|mytag
010000|anothertag
000010|three
000010|four
frequency|tag_name
==================
becomes: 000008|mytag
000010|four
000010|three
010000|anothertag
where the number of leading zeros for each frequency is computed with:
base_ten_power = len(str(max(number_of_posts_per_tag))) + 1
leading_zeros = base_ten_power - len(str(frequency))
{% endcomment %}
{% comment %}Get the frequency of the tag with the maximum frequency.
{% endcomment %}
{% assign x = '' %}
{% for t in site.tags %}
{% assign tag_frequency = tag_frequency | append: t[1].size | append: '#' %}
{% assign x = x | append: t[1].size | append: ',' %}
{% endfor %}
{% assign b = x | split: ',' | sort | last | size %}
{% assign tag_frequency = tag_frequency | split: '#' %}
{% assign tag_frequency_iterator = tag_frequency | sort | reverse %}
{% assign tag_frequency = tag_frequency_iterator | uniq %}
{% comment %}Str to int and add a leading zero later.
{% endcomment %}
{% assign base_ten_power = b | plus: 0 | plus: 1 %}
{% for f in tag_frequency %}
{% comment %} Nice: srt to int: {% endcomment %}
{% assign freq = f | plus: 0 %}
{% for t in site.tags %}
{% if freq == t[1].size %}
{% assign sorted_tags_by_freq = sorted_tags_by_freq | append: t[0] | append: '#' %}
{% endif %}
{% assign tags = '' %}
{% assign leading_zeros = '' %}
{% for t in site.tags %}
{% capture tag_frequency %}{{ t[1].size }}{% endcapture %}
{% assign len_tag_frequency = tag_frequency | size %}
{% comment %}Prepend a variable amount of leading '0' charaters so that
sorting can be performed correctly.
{% endcomment %}
{% assign leading_zeros = '' %}
{% assign power = base_ten_power | minus: len_tag_frequency %}
{% for i in (1..power) %}
{% assign leading_zeros = leading_zeros | append: '0' %}
{% endfor %}
{% assign tags = tags | append: leading_zeros | append: t[1].size | append: '|' | append: t[0] | append: '§' %}
{% endfor %}
{% assign sorted_tags_by_freq = sorted_tags_by_freq | split: '#' %}
{% assign sorted_tags = tags | split: '§' | sort_natural | reverse %}
{% if site.limit_tag_links %}
{% assign s = site.limit_tag_links | plus: 0 %}
{% assign sorted_tags = sorted_tags | slice: 0, s %}
{% endif %}
<div class="tag-list">
<ul>
{% for tag in sorted_tags_by_freq %}
{% assign tagg = tag | slugify %}
{% for tag_elements in sorted_tags %}
{% assign tag = tag_elements | split: '|' %}
{% assign tag_name = tag[1] %}
{% assign tagg = tag_name | slugify %}
{% assign freq = tag[0] | plus: 0 %}
{% if page.is_home %}
{% assign freq = tag_frequency_iterator[forloop.index0] | plus: 0 %}
{% if freq >= site.min_tag_score %}
{% capture link %}{{ site.baseurl }}/tags/#{{ tagg }}{% endcapture %}
<li>
<a href="{{ link }}">{{ tag }} [{{ freq }}]</a>
<a href="{{ link }}">{{ tag_name }} [{{ freq }}]</a>
</li>
{% endif %}
{% else %}
<li>
<a href="#{{ tagg }}">{{ tag }}</a>
<a href="#{{ tagg }}">{{ tag_name }}</a>
</li>
{% endif %}
{% endfor %}