Make tag feeds more discoverable

This commit is contained in:
Gabriel Augendre 2021-03-04 19:33:43 +01:00
parent 5d57bd453d
commit 10edbe2d14
5 changed files with 40 additions and 4 deletions

View file

@ -4,6 +4,7 @@ from functools import cached_property
import rcssmin
import readtime
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.contrib.contenttypes.models import ContentType
from django.db import models
@ -33,6 +34,15 @@ class Tag(models.Model):
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse("tag", kwargs={"slug": self.slug})
def get_feed_title(self):
return f"{self.name} - {settings.BLOG['title']}"
def get_feed_url(self):
return reverse("tag-feed", kwargs={"slug": self.slug})
class Article(models.Model):
DRAFT = "draft"

View file

@ -1,5 +1,12 @@
{% extends 'articles/base.html' %}
{% block feed_link %}
{{ block.super }}
{% if feed_url and feed_title %}
<link rel="alternate" type="application/rss+xml" title="{{ feed_title }}" href="{{ feed_url }}">
{% endif %}
{% endblock %}
{% block append_css %}
<style>{{ article.get_minified_custom_css }}</style>
<style>.pagination{display:flex;justify-content:space-between}</style>

View file

@ -8,7 +8,9 @@
<meta name="author" content="Gabriel Augendre">
<meta name="color-scheme" content="light dark">
<title>{% block title %}Home | {% endblock %}{{ blog_title }} by {{ blog_author }}</title>
<link rel="alternate" type="application/rss+xml" title="Gab's Notes » Feed" href="{% url 'complete-feed' %}">
{% block feed_link %}
<link rel="alternate" type="application/rss+xml" title="{{ blog_title }}" href="{% url 'complete-feed' %}">
{% endblock %}
{% include "articles/snippets/analytics_head.html" %}
{% include "articles/snippets/page_metadata.html" %}

View file

@ -6,7 +6,7 @@ from blog import settings
class CompleteFeed(Feed):
FEED_LIMIT = 15
title = "Gab's Notes"
title = settings.BLOG["title"]
link = settings.BLOG["base_url"]
description = settings.BLOG["description"]
@ -31,3 +31,9 @@ class TagFeed(CompleteFeed):
def get_queryset(self, tag):
return super().get_queryset(tag).filter(tags=tag)
def title(self, tag):
return tag.get_feed_title()
def link(self, tag):
return tag.get_absolute_url()

View file

@ -88,9 +88,20 @@ class SearchArticlesListView(PublicArticleListView):
class TagArticlesListView(PublicArticleListView):
tag = None
def dispatch(self, request, *args, **kwargs):
self.tag = get_object_or_404(Tag, slug=self.kwargs.get("slug"))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["feed_title"] = self.tag.get_feed_title()
context["feed_url"] = self.tag.get_feed_url()
return context
def get_queryset(self):
tag = get_object_or_404(Tag, slug=self.kwargs.get("slug"))
return super().get_queryset().filter(tags=tag)
return super().get_queryset().filter(tags=self.tag)
class DraftsListView(LoginRequiredMixin, BaseArticleListView):