diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index 9a7225373..9b5ab9ab2 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -89,9 +89,8 @@ def selected_tab(request): return 'home' @app.template_filter("seeded_random") -def seeded_random(choices, url): - if url.startswith('/post/'): - random.seed(url) +def seeded_random(choices, seed): + random.seed(seed) return random.choice(choices) diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 4e9af6903..5f0d78cf1 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -5,7 +5,11 @@ {%- endmacro -%} {%- macro random_image(path) -%} - {{- SITE_FULL_IMAGES ~ "/" ~ path ~ "/" ~ listdir('files/' ~ path)|seeded_random(request.path) ~ '?x=7' -}} + {% if request.path.startswith('/post/') and p %} + {{- SITE_FULL_IMAGES ~ "/" ~ path ~ "/" ~ listdir('files/' ~ path)|seeded_random(p.id) ~ '?x=7' -}} + {% else %} + {{- SITE_FULL_IMAGES ~ "/" ~ path ~ "/" ~ listdir('files/' ~ path)|random() ~ '?x=7' -}} + {% endif %} {%- endmacro -%} {% macro post_meta(p) %}