|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 | 3 |
|
| 4 | +# ============================================================================= |
| 5 | +# Docstring |
| 6 | +# ============================================================================= |
| 7 | + |
4 | 8 | """
|
5 |
| -StaticSitemap |
6 |
| -============= |
| 9 | +Provides Static Sitemap |
| 10 | +======================= |
| 11 | +
|
| 12 | +This module provides a `StaticSitemap` class for generating sitemaps of static |
| 13 | +views in a Django application. It is based on a custom `BaseSitemap` class, |
| 14 | +which provides the core functionality for building sitemaps. |
| 15 | +
|
| 16 | +Classes: |
| 17 | + - StaticSitemap: A class for creating sitemaps for static views. |
| 18 | +
|
| 19 | +Links: |
| 20 | + - https://github.com/django/django/blob/master/docs/ref/contrib/sitemaps.txt |
7 | 21 |
|
8 |
| -https://github.com/django/django/blob/master/docs/ref/contrib/sitemaps.txt |
9 | 22 | """
|
10 | 23 |
|
11 |
| -# Standard Library Modules |
12 |
| -# import os.path |
13 | 24 |
|
14 |
| -# Third-Party Modules |
| 25 | +# ============================================================================= |
| 26 | +# Imports |
| 27 | +# ============================================================================= |
| 28 | + |
| 29 | +# Import | Standard Library |
| 30 | +from typing import Any, Dict, List |
| 31 | + |
| 32 | +# Import | Libraries |
15 | 33 | from django.contrib.sitemaps import Sitemap
|
16 | 34 | from django.urls import reverse
|
| 35 | +from django.utils.translation import gettext as _ |
| 36 | + |
| 37 | +# Import | Local Modules |
| 38 | +from swing_sitemap.sitemaps.sitemap_base import BaseSitemap |
17 | 39 |
|
18 |
| -# Local Application Modules |
19 | 40 |
|
| 41 | +# ============================================================================= |
| 42 | +# Class |
| 43 | +# ============================================================================= |
20 | 44 |
|
21 |
| -class StaticSitemap(Sitemap): |
| 45 | +class StaticSitemap(BaseSitemap): |
22 | 46 | """
|
23 |
| - Reverse static views for XML sitemap. |
| 47 | + Static Sitemap |
| 48 | + ============== |
| 49 | +
|
| 50 | +
|
| 51 | + A sitemap class for generating URLs of static views to be included in an |
| 52 | + XML sitemap. |
| 53 | +
|
| 54 | + Attributes: |
| 55 | + changefreq (str): The frequency with which the content is expected |
| 56 | + to change. |
| 57 | + priority (float): The priority of this URL relative to other URLs. |
| 58 | +
|
24 | 59 | """
|
25 |
| - changefreq = "weekly" |
26 |
| - priority = 0.9 |
27 | 60 |
|
28 |
| - def __init__(self, items_in=[]): |
29 |
| - """ |
30 |
| - """ |
31 |
| - self.items_list = items_in |
32 |
| - # self.lastmod_list = lastmod_in |
33 |
| - # self.items_list = items_in[0] |
34 |
| - # self.lastmod = items_in[1] |
| 61 | + # Parameters |
| 62 | + # ========================================================================= |
35 | 63 |
|
36 |
| - def items(self): |
37 |
| - """ |
38 |
| - """ |
39 |
| - # Return list of url names for views to include in sitemap |
40 |
| - items = self.items_list |
41 |
| - return items |
| 64 | + changefreq = "weekly" |
| 65 | + priority = 0.9 |
42 | 66 |
|
43 |
| - # def lastmod(self, obj): |
44 |
| - # """ |
45 |
| - # """ |
46 |
| - # lastmod = self.lastmod_list |
47 |
| - # return lastmod |
48 | 67 |
|
49 |
| - def location(self, item): |
| 68 | + # Utility Methods |
| 69 | + # ========================================================================= |
| 70 | + |
| 71 | + def items(self) -> List[Dict[str, Any]]: |
50 | 72 | """
|
| 73 | + Retrieve the list of static views to include in the sitemap. |
| 74 | +
|
| 75 | + Returns: |
| 76 | + List[Dict[str, Any]]: A list of items to include in the sitemap, |
| 77 | + where each item is a dictionary containing the 'view_name' and |
| 78 | + optional 'kwargs'. |
51 | 79 | """
|
52 |
| - # if kwargs not in item set as None |
53 |
| - kwargs = item["kwargs"] if "kwargs" in item else None |
54 |
| - return reverse(item["view_name"], kwargs=kwargs) |
| 80 | + return self.items_list |
| 81 | + |
| 82 | + |
| 83 | +# ============================================================================= |
| 84 | +# Module Exports |
| 85 | +# ============================================================================= |
| 86 | + |
| 87 | +__all__ = [ |
| 88 | + "StaticSitemap", |
| 89 | +] |
0 commit comments