make event song persistent

master
Aevann 2024-02-23 21:49:26 +02:00
parent 627765f4c9
commit f46522ff56
3 changed files with 5 additions and 8 deletions

View File

@ -89,8 +89,9 @@ def selected_tab(request):
return 'home'
@app.template_filter("seeded_random")
def seeded_random(choices, seed):
random.seed(seed)
def seeded_random(choices, p):
if request.path.startswith('/post/') and p:
random.seed(p.id)
return random.choice(choices)

View File

@ -139,7 +139,7 @@
{% if IS_EVENT() and not (SITE_NAME == 'WPD' and not v) and (not v or v.event_music) and not (hole and hole.name == 'music') and not (u and u.song) and not (IS_HOMOWEEN() and p and p.award_count("haunt", v)) and not (p and p.embed and p.domain == 'twitter.com') %}
{% set path = "assets/events/" ~ IS_EVENT() ~ "/music" %}
{% set song = SITE_FULL ~ "/" ~ path ~ "/" ~ listdir('files/'~path)|random ~ '?x=45' %}
{% set song = SITE_FULL ~ "/" ~ path ~ "/" ~ listdir('files/'~path)|seeded_random(id) ~ '?x=45' %}
<audio id="event-song" hidden preload="none" src="{{song}}" loop></audio>
<script defer src="{{'events/shared/js/music.js' | asset}}"></script>
{% endif %}

View File

@ -5,11 +5,7 @@
{%- endmacro -%}
{%- macro random_image(path) -%}
{% 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 %}
{{- SITE_FULL_IMAGES ~ "/" ~ path ~ "/" ~ listdir('files/' ~ path)|seeded_random(p) ~ '?x=7' -}}
{%- endmacro -%}
{% macro post_meta(p) %}