2016-06-17 2 views
3

私は '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」を追加しました。上書きするために、get_sitemap_urls関数をインクルードするようにPageクラスを変更しました。

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のウェブ上の他のドキュメントは非常に軽いです。どんな助けもありがとう。

答えて

2

私はそれを理解しました。私は間違ったクラスの機能を持っていた。それは、一般的なBlockPageクラスではなく、サイトマップに表示するためにそれぞれの特定のPageクラスに入る必要がありました。これにより、必要に応じて各ページごとに異なる優先順位を設定することもできました。

ソリューション:

class HomePage(Page): 
body = RichTextField(blank=True) 

content_panels = Page.content_panels + [ 
    FieldPanel('body', classname='full') 
] 

def get_sitemap_urls(self): 
    return [ 
     { 
      'location': self.full_url, 
      'lastmod': self.latest_revision_created_at, 
      'changefreq': 'monthly', 
      'priority': 1 
     } 
    ] 

class AboutPage(Page): 
body = RichTextField(blank=True) 

content_panels = Page.content_panels + [ 
    FieldPanel('body', classname='full') 
] 

def get_sitemap_urls(self): 
    return [ 
     { 
      'location': self.full_url, 
      'lastmod': self.latest_revision_created_at, 
      'changefreq': 'monthly', 
      'priority': .5 
     } 
    ] 
関連する問題