from django.contrib.sitemaps import Sitemap
from posts.models import Post


class PostSitemap(Sitemap):
    changefreq = "daily"
    priority = 1

    def items(self):
        return Post.objects.filter(is_hidden=False)

    def lastmod(self, obj):
        return obj.date_modified

    def location(self, obj):
        return f"/posts/{obj.slug}"


sitemaps = {"posts": PostSitemap()}
