pelican-random-article
pelican-random-article is a Pelican plugin that automatically generates a /random page.
Visiting /random instantly redirects the reader to a randomly chosen article — just like wiwi.blog/random.
Features
- Generates a static
random/index.htmlpage at build time. - Picks a random article client-side using JavaScript — no server required.
- Works with any Pelican theme; no template changes needed.
- Configurable output path via
pelicanconf.py.
Installation
pip install pelican-random-article
Or with uv:
uv add pelican-random-article
Usage
1. Enable the plugin in pelicanconf.py
PLUGINS = [
# ... your other plugins ...
"pelican.plugins.random_article",
]
2. (Optional) Add a link in your navigation
Point any link to /random (or wherever RANDOM_ARTICLE_SAVE_AS points):
<a href="{{ SITEURL }}/random/">Random</a>
3. Build your site
pelican content
The plugin will write output/random/index.html automatically.
Configuration
Add these to pelicanconf.py to customise the output path:
# Default values shown below
RANDOM_ARTICLE_SAVE_AS = "random/index.html"
Note:
RANDOM_ARTICLE_URLis not consumed by the plugin itself —
it is only needed if you want Pelican's link helpers to resolve/random.
Set it to matchRANDOM_ARTICLE_SAVE_AS:
RANDOM_ARTICLE_URL = "random/"
RANDOM_ARTICLE_SAVE_AS = "random/index.html"
Custom template
By default the plugin renders a small built-in HTML/JS template. To use your
own Jinja2 template instead, point RANDOM_ARTICLE_TEMPLATE at a file path:
RANDOM_ARTICLE_TEMPLATE = "themes/mytheme/templates/random.html"
The template is rendered with these variables:
SITENAME– your site'sSITENAMEsetting (HTML-escaped).SITEURL– your site'sSITEURLsetting (HTML-escaped).article_urls_json– a JSON array of the selected article URLs, pre-marked safe for embedding directly inside a<script>block (not HTML-escaped).
If RANDOM_ARTICLE_TEMPLATE is unset, the built-in template is used.
Excluding articles
Articles can be excluded from the random pool via any combination of:
# Exclude articles whose category is in this list
RANDOM_ARTICLE_EXCLUDE_CATEGORIES = ["Meta", "Drafts"]
# Exclude articles that carry any of these tags
RANDOM_ARTICLE_EXCLUDE_TAGS = ["no-random", "wip"]
Individual articles can also opt out via metadata, e.g.:
:random: false
Random: false
which becomes article.random and, if falsy, excludes that article. All
three settings are optional and default to no exclusion; they combine with
the plugin's existing "published only" filter.
How it works
At build time the plugin:
- Connects to Pelican's
article_generator_finalizedsignal. - Collects all published article URLs.
- Renders a tiny HTML page that contains the full URL list as a JSON array.
- On page load, JavaScript picks a random entry and calls
window.location.href.
Because the redirect happens client-side, the page is completely static and
requires no server-side logic.
Requirements
- Python >= 3.10
- Pelican >= 4.5
- Jinja2 (bundled with Pelican)
License
MIT License © Wei Lee
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pelican_random_article-0.3.0.tar.gz.
File metadata
- Download URL: pelican_random_article-0.3.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c333a628451cb72afd9c8a64b985781eb02623955206f890653ba12b70eac05a
|
|
| MD5 |
cbc98fbb97cc316366cc28f1d2082f7a
|
|
| BLAKE2b-256 |
69675aa5606ba4f671b95ba4a7daa336baab4f2bc360325bd09508e7c66af8ba
|
Provenance
The following attestation bundles were made for pelican_random_article-0.3.0.tar.gz:
Publisher:
publish-to-pypi.yaml on Lee-W/pelican-random-article
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pelican_random_article-0.3.0.tar.gz -
Subject digest:
c333a628451cb72afd9c8a64b985781eb02623955206f890653ba12b70eac05a - Sigstore transparency entry: 2163759739
- Sigstore integration time:
-
Permalink:
Lee-W/pelican-random-article@5df9260a066ec34fd1002665e0469de91a4c7281 -
Branch / Tag:
refs/tags/0.3.0 - Owner: https://github.com/Lee-W
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yaml@5df9260a066ec34fd1002665e0469de91a4c7281 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pelican_random_article-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pelican_random_article-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0264f49ce3d57b4c945fd3fa461fe60f0890109d8a301ea67e715d2d7d3420e5
|
|
| MD5 |
4048a99c1f67cf2140937b77ea670a1a
|
|
| BLAKE2b-256 |
db8dad8e091706fd14631b9308a6864db3036c9a7e95c72a5c3eecc7c5aefd8b
|
Provenance
The following attestation bundles were made for pelican_random_article-0.3.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yaml on Lee-W/pelican-random-article
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pelican_random_article-0.3.0-py3-none-any.whl -
Subject digest:
0264f49ce3d57b4c945fd3fa461fe60f0890109d8a301ea67e715d2d7d3420e5 - Sigstore transparency entry: 2163759759
- Sigstore integration time:
-
Permalink:
Lee-W/pelican-random-article@5df9260a066ec34fd1002665e0469de91a4c7281 -
Branch / Tag:
refs/tags/0.3.0 - Owner: https://github.com/Lee-W
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yaml@5df9260a066ec34fd1002665e0469de91a4c7281 -
Trigger Event:
push
-
Statement type: