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
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)

View file

@ -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;
}

View file

@ -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)

View file

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

View file

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

View file

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

View file

@ -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('_<int:year>/', item_views.archive, name='archive'),
path('<int:id>/', item_views.item, name='item'),
path('<str:slug>/', page_views.page, name='page'),
path('', item_views.index, name='index'),

View file

@ -31,15 +31,23 @@ def sitemap_xml(request):
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('/archive/')
loc.text = request.build_absolute_uri('/_%s/' % year)
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")
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")