【发布时间】:2019-02-12 07:37:07
【问题描述】:
我正在为 Django + Wagtail 项目生成sitemap.xml。
我通过覆盖get_sitemap_urls 方法为文章实现了xml 生成。但问题是 Wagtail 站点地图生成器 没有“看到”博客标签网址(不会将它们添加到站点地图中)。
...
from taggit.models import TaggedItemBase
class BlogPageTag(TaggedItemBase):
content_object = ParentalKey(
'BlogInnerPage',
related_name='tagged_items',
on_delete=models.CASCADE,
)
class BlogInnerPage(Page):
icon = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=False,
on_delete=models.SET_NULL,
related_name='+'
)
...
post_date = models.DateTimeField(auto_now_add=True, null=True)
tags = ClusterTaggableManager(through=BlogPageTag, blank=False)
@property
def sidebar_tags(self):
blogs = BlogInnerPage.objects.live().all()
tags = {}
for post in blogs:
for tag in post.tags.all():
if tag.slug in tags:
tags[tag.slug]['count'] += 1
else:
tags[tag.slug] = {
'name': tag.name,
'count': 1
}
return sorted(tags.items())
...
def get_sitemap_urls(self):
return [
{
'location': self.full_url,
'lastmod': self.last_published_at,
'changefreq': 'weekly',
'priority': .8
}
]
我希望看到以下标签结果:
<url>
<loc>https://example.com/?tag=design</loc>
<lastmod>2019-01-31T12:24:01+00:00</lastmod>
<priority>0.80</priority>
</url>
这是我的博客文章:
<url>
<loc>
http://example.com/trends-booming-todays-it-industry/
</loc>
<lastmod>2018-10-04</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
【问题讨论】:
标签: django web-applications sitemap wagtail django-taggit