From c665e5cdd615d81f4a71b48fa0eec10d7aca0f11 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 21 Feb 2024 22:24:21 +0200 Subject: [PATCH] do this https://rdrama.net/h/countryclub/post/79285/-/5969149#context --- files/routes/jinja2.py | 7 +++++++ files/templates/util/macros.html | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index f664cc5b2..9a7225373 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -1,6 +1,7 @@ import time import math import datetime +import random from os import environ, listdir, path @@ -87,6 +88,12 @@ def selected_tab(request): return 'home' +@app.template_filter("seeded_random") +def seeded_random(choices, url): + if url.startswith('/post/'): + random.seed(url) + return random.choice(choices) + def current_registered_users(): return "{:,}".format(g.db.query(User).count()) diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index ae51c4081..4e9af6903 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -5,7 +5,7 @@ {%- endmacro -%} {%- macro random_image(path) -%} - {{- SITE_FULL_IMAGES ~ "/" ~ path ~ "/" ~ listdir('files/' ~ path)|random() ~ '?x=7' -}} + {{- SITE_FULL_IMAGES ~ "/" ~ path ~ "/" ~ listdir('files/' ~ path)|seeded_random(request.path) ~ '?x=7' -}} {%- endmacro -%} {% macro post_meta(p) %}