keep archive per year, don't call it archive

This commit is contained in:
j 2023-08-23 14:44:37 +02:00
parent d995ea0c6f
commit cf2efd7fb3
8 changed files with 72 additions and 17 deletions

View file

@ -35,7 +35,8 @@ def index(request):
now = None now = None
week, archive = models.Item.public(now) week, archive = models.Item.public(now)
context['items'] = week context['items'] = week
context['archive'] = archive.exists() if archive.exists():
context['archive'] = '/_%s/' % now.year
if now: if now:
context['now'] = now context['now'] = now
context['previous_week'] = (now - timedelta(days=7)).strftime(TS_FORMAT) context['previous_week'] = (now - timedelta(days=7)).strftime(TS_FORMAT)
@ -43,7 +44,7 @@ def index(request):
return render(request, 'index.html', context) return render(request, 'index.html', context)
def archive(request, week=None): def archive(request, year=None, week=None):
context = default_context(request) context = default_context(request)
qs = models.Item.public() qs = models.Item.public()
week, archive = models.Item.public() week, archive = models.Item.public()
@ -71,7 +72,9 @@ def item(request, id):
comments = [] comments = []
for comment in qs: for comment in qs:
comments.append(comment.json()) 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 = {} user = {}
if request.user.is_staff: if request.user.is_staff:
user['is_moderator'] = True user['is_moderator'] = True
@ -80,6 +83,17 @@ def item(request, id):
context['user'] = mark_safe(json.dumps(user)) context['user'] = mark_safe(json.dumps(user))
request.session['item'] = id 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) return render(request, 'item.html', context)

View file

@ -17,7 +17,7 @@ body {
} }
a { a {
color: var(--blue) color: var(--fg)
} }
iframe { iframe {
max-width: 100%; max-width: 100%;
@ -98,6 +98,10 @@ video, .poster {
.more a { .more a {
color: rgb(144, 144, 144); color: rgb(144, 144, 144);
} }
.more nav {
margin-top: 24px;
margin-bottom: 24px;
}
.layer.active { .layer.active {
padding-top: 8px; padding-top: 8px;
} }

View file

@ -46,6 +46,31 @@ function renderItem(data) {
if (!item.title) { if (!item.title) {
div.querySelector('item-title').remove() 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) { if (window.renderComments) {
renderComments(div.querySelector('.comments'), data) renderComments(div.querySelector('.comments'), data)

View file

@ -6,7 +6,9 @@
<div class="index archive"> <div class="index archive">
{% for item in items %} {% for item in items %}
{% ifchanged item.week %} {% ifchanged item.week %}
{% comment %}
<h2 class="week">{{ item.year }} week {{ item.week }}</h2> <h2 class="week">{{ item.year }} week {{ item.week }}</h2>
{% endcomment %}
{% endifchanged %} {% endifchanged %}
{% include "listitem.html" with item=item %} {% include "listitem.html" with item=item %}
{% endfor %} {% endfor %}

View file

@ -10,7 +10,7 @@
{% endfor %} {% endfor %}
{% if archive %} {% if archive %}
<div class="archive"> <div class="archive">
<a href="/archive/">previous weeks</a> <a href="{{ archive }}">previous weeks</a>
</div> </div>
{% endif %} {% endif %}
</div> </div>

View file

@ -50,12 +50,14 @@
{% endblock %} {% endblock %}
{% block end %} {% block end %}
<script> <script>
var comments = {{ comments }};
var user = {{ user }}; var user = {{ user }};
var item = { var item = {
id: {{ item.id }}, id: {{ item.id }},
title: '{{ item.title|escapejs }}' title: '{{ item.title|escapejs }}',
next: '{{ next }}',
previous: '{{ previous }}',
}; };
var comments = JSON.parse("{{ comments|escapejs }}");
</script> </script>
{% compress js file m %} {% compress js file m %}
<script src="/static/js/utils.js"></script> <script src="/static/js/utils.js"></script>

View file

@ -30,9 +30,9 @@ urlpatterns = [
path('login/', user_views.login, name='login'), path('login/', user_views.login, name='login'),
path('logout/', user_views.logout, name='logout'), path('logout/', user_views.logout, name='logout'),
path('register/', user_views.register, name='register'), 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/publish/', item_views.publish_comment, name='publish-comment'),
path('comment/', item_views.comment, name='comment'), path('comment/', item_views.comment, name='comment'),
path('_<int:year>/', item_views.archive, name='archive'),
path('<int:id>/', item_views.item, name='item'), path('<int:id>/', item_views.item, name='item'),
path('<str:slug>/', page_views.page, name='page'), path('<str:slug>/', page_views.page, name='page'),
path('', item_views.index, name='index'), path('', item_views.index, name='index'),

View file

@ -31,15 +31,23 @@ def sitemap_xml(request):
priority = ET.SubElement(url, "priority") priority = ET.SubElement(url, "priority")
priority.text = '1.0' priority.text = '1.0'
url = ET.SubElement(urlset, "url") first = Item.objects.exclude(published=None).exclude(published__gt=now).order_by('published').first()
loc = ET.SubElement(url, "loc") if first:
loc.text = request.build_absolute_uri('/archive/') for year in reversed(range(first.published.year, now.year + 1)):
lastmod = ET.SubElement(url, "lastmod") url = ET.SubElement(urlset, "url")
lastmod.text = now.strftime("%Y-%m-%d") loc = ET.SubElement(url, "loc")
changefreq = ET.SubElement(url, "changefreq") loc.text = request.build_absolute_uri('/_%s/' % year)
changefreq.text = 'weekly' lastmod = ET.SubElement(url, "lastmod")
priority = ET.SubElement(url, "priority") changefreq = ET.SubElement(url, "changefreq")
priority.text = '1.0' 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'): for item in Item.objects.exclude(published=None).exclude(published__gt=now).order_by('-published'):
url = ET.SubElement(urlset, "url") url = ET.SubElement(urlset, "url")