惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Webroot Blog
Webroot Blog
AI
AI
P
Palo Alto Networks Blog
Attack and Defense Labs
Attack and Defense Labs
WordPress大学
WordPress大学
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
Spread Privacy
Spread Privacy
T
Tor Project blog
罗磊的独立博客
小众软件
小众软件
S
Security Affairs
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
Apple Machine Learning Research
Apple Machine Learning Research
T
Threatpost
NISL@THU
NISL@THU
博客园_首页
PCI Perspectives
PCI Perspectives
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
N
News and Events Feed by Topic
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Forbes - Security
Forbes - Security
博客园 - 叶小钗
D
Darknet – Hacking Tools, Hacker News & Cyber Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
L
LINUX DO - 热门话题
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Cloudflare Blog
A
About on SuperTechFans
爱范儿
爱范儿
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
TaoSecurity Blog
TaoSecurity Blog
宝玉的分享
宝玉的分享
G
GRAHAM CLULEY
雷峰网
雷峰网
F
Full Disclosure
I
Intezer
Cloudbric
Cloudbric
博客园 - 三生石上(FineUI控件)
U
Unit 42

Jens Oliver Meiert · On Craft and Responsibility

AWAGAM: Easier Importing and Sharing of Blocklists With Bundles · Jens Oliver Meiert Israel, the United States, and Their European Clients vs. the European People · Jens Oliver Meiert Releasing Feed Ghost, a Dual-Purpose Web Tool to Access and Subscribe to Feeds via the Internet Archive · Jens Oliver Meiert Anti-Pro-Palestine as Pro-Islamophobia, Pro-Racism, Pro-Genocide · Jens Oliver Meiert HTML Minifier Next 7 Is ESM-Only · Jens Oliver Meiert On the Two Sides and the Spectrum That Is Open Source Maintenance · Jens Oliver Meiert Beware the “First” · Jens Oliver Meiert Releasing Middleman Alerter, a Chromium Extension to Warn About Third-Party Reverse Proxies · Jens Oliver Meiert On the Twisted Logic of Labeling Criticism of Israel as “Anti-Semitism” · Jens Oliver Meiert Websites Are Not Going to Die · Jens Oliver Meiert Slavery · Jens Oliver Meiert Releasing hihtml, a Supertool for HTML Validation, Link-Checking, and Minification · Jens Oliver Meiert AI and HTML: Validating, Omitting Optional Code, and Minifying as Token Optimization · Jens Oliver Meiert HTML.md · Jens Oliver Meiert Website Optimization Measures, Part XXXVII · Jens Oliver Meiert A Decent Person · Jens Oliver Meiert 26 Tips to Become a Better Engineering Manager · Jens Oliver Meiert There Is No Elite Unless It Serves the People and the Environment · Jens Oliver Meiert AI Will Never Be Ethical or Safe · Jens Oliver Meiert A Simple Model to Address Work Performance Issues · Jens Oliver Meiert There Is No “Wrong” in CSS · Jens Oliver Meiert Releasing Searcher, a Configurable, Privacy-Minded Chromium Extension to Trigger Random Searches · Jens Oliver Meiert “Conflict” · Jens Oliver Meiert HTML Minifier Next: Zero-Config Mode, SVG Minification With SVGO, Even Faster · Jens Oliver Meiert
How to Provide a “Random Post” Feature With Eleventy and PHP · Jens Oliver Meiert
2026-06-02 · via Jens Oliver Meiert · On Craft and Responsibility

Published on Jun 2, 2026, filed under . (Share this post, e.g., on Mastodon or on Bluesky.)

Have you ever thought about providing a “random article” feature on your website?

And, are you using Eleventy on a PHP-enabled server?

Then this is for you, a quick way of providing a URL to return a random article.

1. Drop the URLs of Your Posts in a PHP File That Randomly Redirects to These URLs

Save the following where you need it (.njk), and adjust where you want to export the output (here: /random/index.php):

---
eleventyExcludeFromCollections: true
permalink: /random/index.php
---
<?php
$posts = [
{%- for post in collections.posts %}
{%- if post.url %}
  '{{ post.url | absoluteUrl(metadata.url) }}',
{%- endif %}
{%- endfor %}
];

header('Cache-Control: no-store');

if (!empty($posts)) {
  header('Location: ' . $posts[array_rand($posts)], true, 302);
} else {
  header('Location: https://meiert.com/', true, 302);
}
exit;

In brief, the file:

  • makes sure not to be part of other Eleventy collections
  • goes through your “posts” collection (change and tailor this where needed)
  • (assumes you use Eleventy’s RSS plugin or rolled your own absoluteUrl filter)
  • sets a Cache-Control header (more, as far as I know, shouldn’t be needed anymore)
  • picks one URL to redirect to on request (or falls back to the homepage, here represented by metadata.url)

2. Link and Feature the Script

Not much more to see here—link your /random or how you’ve called it, and tell others about the feature!

_ If you want to see this in action, here are three examples: WebGlossary.info uses this solution to provide random terms, meiert.com—this site—gives you random articles of mine, and Haiku Haiku Love, an old heartbreak project where this is done just via PHP, returns random haiku!

About Me

Jens Oliver Meiert, on March 2, 2026.

I’m Jens (long: Jens Oliver Meiert), and I’m an engineering lead, guerrilla philosopher, and indie publisher. I’ve worked as a technical lead and engineering manager at various companies, including Google; I’m an open-source developer and a contributor to web standards (like HTML, CSS, WCAG); and I write and review books for O’Reilly and Frontend Dogma.

I love trying things, not only in web development and engineering management, but also with respect to politics and philosophy. Here on meiert.com I talk about some of my experiences and perspectives. (Please share feedbackinterpret charitably, keep it friendly, but do be critical.)

Learn More

You can support my work for the community by sharing it, by reading or gifting my books, or by becoming a backer on GitHub or Steady. (Let’s talk if you need a competent hand for technical optimization and activism projects.)

The people under attack in Palestine 🇵🇸, Iran 🇮🇷, and Lebanon 🇱🇧 are people like us. They’re our brothers and sisters, too. Read up on their history, scrutinize what you’re told, and demand that they be respected.