「changefreq」と「priority」を含むカスタム Wagtail サイトマップを作成しようとしています。デフォルトは、'lastmod' と 'url' だけです。
Wagtail のドキュメント ( http://docs.wagtail.io/en/latest/reference/contrib/sitemaps.html ) によると、/wagtailsitemaps/sitemap.xml にサイトマップを作成することで、デフォルトのテンプレートを上書きできます。
私はこれをしました。サイトマップ テンプレートは次のようになります。
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% spaceless %}
{% for url in urlset %}
<url>
<loc>{{ url.location }}</loc>
{% if url.lastmod %}<lastmod>{{ url.lastmod|date:"Y-m-d" }} </lastmod>{% endif %}
{% if url.changefreq %}<changefreq>{{ url.changefreq }}</changefreq>{% endif %}
{% if url.priority %}<priority>{{ url.priority }}</priority>{% endif %}
</url>
{% endfor %}
{% endspaceless %}
</urlset>
設定のインストール済みアプリに「wagtail.contrib.wagtailsitemaps」を追加しました。上書きしようとして、Page クラスを変更して get_sitemap_urls 関数を含めました。
class BlockPage(Page):
author = models.CharField(max_length=255)
date = models.DateField("Post date")
body = StreamField([
('heading', blocks.CharBlock(classname='full title')),
('paragraph', blocks.RichTextBlock()),
('html', blocks.RawHTMLBlock()),
('image', ImageChooserBlock()),
])
search_fields = Page.search_fields + (
index.SearchField('heading', partial_match=True),
index.SearchField('paragraph', partial_match=True),
)
content_panels = Page.content_panels + [
FieldPanel('author'),
FieldPanel('date'),
StreamFieldPanel('body'),
]
def get_sitemap_urls(self):
return [
{
'location': self.full_url,
'lastmod': self.latest_revision_created_at,
'changefreq': 'monthly',
'priority': .5
}
]
まだ機能していません。他に何か不足していますか?Wagtail のドキュメントはこれ以上の情報を提供しておらず、Wagtail に関する Web 上の他のドキュメントは非常に軽量です。どんな助けでも大歓迎です。