Skip to main content

GitHub tag (latest SemVer) version on pypi python versions on pypi Downloads license Donate

Similar articles for Pelican

A lightweight Pelican plugin to provide a list of similar articles, related to one another by a similarity calculation based on their tags.

Installation

This plugin can be installed via:

pip install pelican-similar-articles-light

Template integration

Minimal version:

{% if article.similar_articles %}
    <ul>
    {% for sub_article in article.similar_articles %}
        <li><a href="{{ SITEURL }}/{{ sub_article.url }}">{{ sub_article.title }}</a></li>
    {% endfor %}
    </ul>
{% endif %}

With bootstrap and translations support:

{% if article.similar_articles %}
<div class="alert alert-warning text-left" role="alert">
    <p><strong>{{ _("You might be interested in") ~ ' ' ~ ngettext("the following article:", "the following articles:", article.similar_articles|count) }}</strong></p>
    <ul>
    {% for sub_article in article.similar_articles %}
        <li><a href="{{ SITEURL }}/{{ sub_article.url }}" class="alert-link">{{ sub_article.title }}</a></li>
    {% endfor %}
    </ul>
</div>
{% endif %}

Pelican configuration

Enable the plugin in pelicanconf.py:

PLUGINS = [..., 'similar_articles_light']

You you can customize some features of the plugin. You will find below the default values which can be overwritten by a statement in the pelicanconf.py file.

The maximum number of similar articles:

SIMILAR_ARTICLES_MAX_COUNT = 2

The the minimal score to consider an article as similar:

SIMILAR_ARTICLES_MIN_SCORE = 0.0001

About the implementation

The plugin computes a similarity score based on the tags of the articles. It consists in building a global bag of words (dictionary), and a bag of words for each article, representing this article as an n-dimensional vector.

The terms are weighted using the TF-IDF method, according to their rareness within the corpus formed by all the tags of the site.

The vector of each article is then compared to all the others via the calculation of the cosine simiarity widely used in text mining. It consists in determining the angle formed between 2 vectors. The maximum similarity obtained is 1 (the documents have all their important tags in common), while the minimum is 0 (the documents have no tag in common).

Comparison with the plugin Similar Posts

The Similar Posts plugin uses exactly the same technique, I don't think you will have any difference in the the result obtained. However, the dependencies used are a bit too large and somewhat oversized for the intended purpose: a few words (tags) summarizing an article among a handful of articles from a Pelican blog.

The implementation of Similar Articles Light is in pure Python. In any case, reinventing the wheel should never be a reason to sell a technology; therefore please consider this plugin as a proof of concept of a few dozen lines of code, fully functional and without dependencies; so probably slightly faster to run than Similar Posts.

License

This program is released under the GNU Affero General Public License.

Metadata

Release files for pelican-similar-articles-light 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pelican-similar-articles-light 1.0.1
File Size Uploaded Provenance Actions
pelican_similar_articles_light-1.0.1.tar.gz 17.7 kB Without provenance Details for pelican_similar_articles_light-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pelican-similar-articles-light 1.0.1
File Interpreter ABI Platform Actions
pelican_similar_articles_light-1.0.1-py3-none-any.whl Python 3 none any Details for pelican_similar_articles_light-1.0.1-py3-none-any.whl

Total release size: 36.1 kB

Release files / pelican_similar_articles_light-1.0.1.tar.gz

Download URL pelican_similar_articles_light-1.0.1.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0e84791c208f3fa9c6b896582db62551a61e6a6b39ab8135ba38c8ceb3336838
BLAKE2b-256 checksum
How to use checksums
80ea4f3956c20d76f52677670e0f060ff092d20918342b4df6bae777e437e150
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / pelican_similar_articles_light-1.0.1-py3-none-any.whl

Download URL pelican_similar_articles_light-1.0.1-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38ca8d823ef6c35d30eab8d5593332d1606a527a5ac3b5adab5e2c1f5aa3b1bc
BLAKE2b-256 checksum
How to use checksums
6a595ede21c2ccf9c6e9190b477ad6c745828dc84adaad9eb0d584b60d658514
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for pelican-similar-articles-light 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page