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