From cf2efd7fb32ea6f2b873636005987437f9790395 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 23 Aug 2023 14:44:37 +0200 Subject: [PATCH] keep archive per year, don't call it archive --- app/item/views.py | 20 +++++++++++++++++--- app/static/css/style.css | 6 +++++- app/static/js/render.js | 25 +++++++++++++++++++++++++ app/templates/archive.html | 2 ++ app/templates/index.html | 2 +- app/templates/item.html | 6 ++++-- app/urls.py | 2 +- app/views.py | 26 +++++++++++++++++--------- 8 files changed, 72 insertions(+), 17 deletions(-) diff --git a/app/item/views.py b/app/item/views.py index e35ca27..4a76a60 100644 --- a/app/item/views.py +++ b/app/item/views.py @@ -35,7 +35,8 @@ def index(request): now = None week, archive = models.Item.public(now) context['items'] = week - context['archive'] = archive.exists() + if archive.exists(): + context['archive'] = '/_%s/' % now.year if now: context['now'] = now context['previous_week'] = (now - timedelta(days=7)).strftime(TS_FORMAT) @@ -43,7 +44,7 @@ def index(request): return render(request, 'index.html', context) -def archive(request, week=None): +def archive(request, year=None, week=None): context = default_context(request) qs = models.Item.public() week, archive = models.Item.public() @@ -71,7 +72,9 @@ def item(request, id): comments = [] for comment in qs: comments.append(comment.json()) - context['comments'] = mark_safe(json.dumps(comments)) + context['comments'] = mark_safe(json.dumps(comments, ensure_ascii=False)) + context['comments'] = json.dumps(comments, ensure_ascii=False) + user = {} if request.user.is_staff: user['is_moderator'] = True @@ -80,6 +83,17 @@ def item(request, id): context['user'] = mark_safe(json.dumps(user)) request.session['item'] = id + qs = models.Item.objects.exclude(published=None).exclude(id=item.id) + if not request.user.is_staff: + now = get_now() + qs = qs.filter(published__lt=now) + previous_item = qs.exclude(published__gt=item.published).order_by('-published').first() + next_item = qs.exclude(published__lt=item.published).order_by('published').first() + if next_item: + context['next'] = next_item.get_absolute_url() + if previous_item: + context['previous'] = previous_item.get_absolute_url() + return render(request, 'item.html', context) diff --git a/app/static/css/style.css b/app/static/css/style.css index 091ba44..209b1f5 100644 --- a/app/static/css/style.css +++ b/app/static/css/style.css @@ -17,7 +17,7 @@ body { } a { - color: var(--blue) + color: var(--fg) } iframe { max-width: 100%; @@ -98,6 +98,10 @@ video, .poster { .more a { color: rgb(144, 144, 144); } +.more nav { + margin-top: 24px; + margin-bottom: 24px; +} .layer.active { padding-top: 8px; } diff --git a/app/static/js/render.js b/app/static/js/render.js index a5872e6..3c846f4 100644 --- a/app/static/js/render.js +++ b/app/static/js/render.js @@ -46,6 +46,31 @@ function renderItem(data) { if (!item.title) { div.querySelector('item-title').remove() } + if (item.next || item.previous) { + var more = div.querySelector('.more') + var nav = document.createElement('nav') + //more.insertBefore(nav, more.firstChild); + more.appendChild(nav) + if (item.previous) { + var a = document.createElement('a') + a.href = item.previous + a.innerText = '<< previous' + nav.appendChild(a) + } + if (item.previous && item.next) { + var e = document.createElement('span') + e.innerText = ' | ' + nav.appendChild(e) + } + if (item.next) { + var a = document.createElement('a') + a.href = item.next + a.innerText = 'next >>' + nav.appendChild(a) + } + + + } if (window.renderComments) { renderComments(div.querySelector('.comments'), data) diff --git a/app/templates/archive.html b/app/templates/archive.html index 4987635..0c93cec 100644 --- a/app/templates/archive.html +++ b/app/templates/archive.html @@ -6,7 +6,9 @@
{% for item in items %} {% ifchanged item.week %} + {% comment %}

{{ item.year }} week {{ item.week }}

+ {% endcomment %} {% endifchanged %} {% include "listitem.html" with item=item %} {% endfor %} diff --git a/app/templates/index.html b/app/templates/index.html index 1a2e5f0..079a418 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -10,7 +10,7 @@ {% endfor %} {% if archive %} {% endif %}
diff --git a/app/templates/item.html b/app/templates/item.html index 8affb44..254da50 100644 --- a/app/templates/item.html +++ b/app/templates/item.html @@ -50,12 +50,14 @@ {% endblock %} {% block end %} {% compress js file m %} diff --git a/app/urls.py b/app/urls.py index 807c972..7207a7f 100644 --- a/app/urls.py +++ b/app/urls.py @@ -30,9 +30,9 @@ urlpatterns = [ path('login/', user_views.login, name='login'), path('logout/', user_views.logout, name='logout'), path('register/', user_views.register, name='register'), - path('archive/', item_views.archive, name='archive'), path('comment/publish/', item_views.publish_comment, name='publish-comment'), path('comment/', item_views.comment, name='comment'), + path('_/', item_views.archive, name='archive'), path('/', item_views.item, name='item'), path('/', page_views.page, name='page'), path('', item_views.index, name='index'), diff --git a/app/views.py b/app/views.py index 0b59a82..b45738f 100644 --- a/app/views.py +++ b/app/views.py @@ -31,15 +31,23 @@ def sitemap_xml(request): priority = ET.SubElement(url, "priority") priority.text = '1.0' - url = ET.SubElement(urlset, "url") - loc = ET.SubElement(url, "loc") - loc.text = request.build_absolute_uri('/archive/') - lastmod = ET.SubElement(url, "lastmod") - lastmod.text = now.strftime("%Y-%m-%d") - changefreq = ET.SubElement(url, "changefreq") - changefreq.text = 'weekly' - priority = ET.SubElement(url, "priority") - priority.text = '1.0' + first = Item.objects.exclude(published=None).exclude(published__gt=now).order_by('published').first() + if first: + for year in reversed(range(first.published.year, now.year + 1)): + url = ET.SubElement(urlset, "url") + loc = ET.SubElement(url, "loc") + loc.text = request.build_absolute_uri('/_%s/' % year) + lastmod = ET.SubElement(url, "lastmod") + changefreq = ET.SubElement(url, "changefreq") + priority = ET.SubElement(url, "priority") + if year == now.year: + lastmod.text = now.strftime("%Y-%m-%d") + changefreq.text = 'weekly' + priority.text = '1.0' + else: + lastmod.text = now.strftime("%s-12-31" % year) + changefreq.text = 'yearly' + priority.text = '0.8' for item in Item.objects.exclude(published=None).exclude(published__gt=now).order_by('-published'): url = ET.SubElement(urlset, "url")