Socialify

Folder ..

Viewing sitemaps.py
81 lines (60 loc) • 1.8 KB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os

from django.contrib.sitemaps import Sitemap
from django.urls import reverse
from dotenv import load_dotenv
from github import Github

from blog.models import Category, Post, Tag

load_dotenv()

class PostSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.9
    protocol = 'http'

    def items(self):
        return Post.objects.filter(is_public=True).order_by('id')

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

    def location(self, obj):
        return reverse('blog:post', args=[obj.slug])

class CategorySitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.9
    protocol = 'http'

    def items(self):
        return Category.objects.all().order_by('id')

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

    def location(self, obj):
        return '/weblog/categories/%s' % obj.slug

class TagSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.9
    protocol = 'http'

    def items(self):
        return Tag.objects.all().order_by('id')

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

    def location(self, obj):
        return '/weblog/tags/%s' % obj.slug

class StaticViewSitemap(Sitemap):
    changefreq = "always"
    priority = 0.9
    protocol = 'http'

    def items(self):
        return ['blog:home', 'blog:register']

    def location(self, item):
        return reverse(item)

class GithubSitemap(Sitemap):
    g = Github(os.getenv('GH_TOKEN'))
    changefreq = "always"
    priority = 0.9
    protocol = 'http'

    # get list of all public repos
    public_repos = g.get_user().get_repos(type='public')
    repo_names = []
    for repo in public_repos:
        if 'luciferreeves' in repo.full_name:
            repo_names.append(repo.name)

    def items(self):
        return self.repo_names

    def location(self, item):
        return '/repositories/{}'.format(item)