gradient for the current week

This commit is contained in:
j 2025-02-15 00:51:32 +01:00
commit f02023b079
3 changed files with 18 additions and 3 deletions

View file

@ -312,11 +312,12 @@ class Week(models.Model):
items, _ = Item.public(monday)
return items.order_by('published')
@property
def background(self):
def background(self, now=None):
if self.use_hue:
colors = []
for item in self.items():
if now and item.published > now:
continue
color = item.get_hue(update=True)
if color:
if not colors:

View file

@ -68,6 +68,7 @@ def index(request):
now = get_now()
else:
now = None
monday = get_monday(now)
week, archive = models.Item.public(now)
if archive and archive.exists():
context['archive'] = '/_%s/' % get_monday(get_now() - timedelta(days=7))
@ -75,6 +76,9 @@ def index(request):
context["break"] = week
else:
context['items'] = week
extra = models.Week.objects.filter(monday=monday, is_break=False).first()
if extra:
context['week_background'] = extra.background(now)
if now:
context['now'] = now
context['previous_week'] = (now - timedelta(days=7)).strftime(TS_FORMAT)
@ -109,7 +113,7 @@ def archive(request, year=None, month=None, day=None, week=None):
if extra:
context['week_title'] = extra.title
context['week_byline'] = extra.byline
context['week_background'] = extra.background
context['week_background'] = extra.background()
elif week:
week = int(week)
year = int(year)

View file

@ -2,6 +2,16 @@
{% block head %}
<link rel="alternate" type="application/atom+xml" title="{{ settings.SITENAME }}" href="/atom.xml" />
<title>{{ settings.SITENAME }}</title>
{% if week_background %}
<style>
body {
background: {{ week_background }};
}
</style>
<script>
window.useHue = true;
</script>
{% endif %}
{% endblock %}
{% block content %}
<div class="index">