LoginSignup
3
3

More than 5 years have passed since last update.

Pelican のサイトマップの作り方

Posted at

Pelican での Web サイトのサイトマップの作り方です。

まずは、サイトマップ用の jinja テンプレートを用意します。

sitemap.html

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

{% for article in articles %}
  <url>
    <loc>{{ SITEURL }}/{{ article.url }}</loc>
    <priority>0.8</priority>
  </url>

  {% for translation in article.translations %}
  <url>
    <loc>{{ SITEURL }}/{{ translation.url }}</loc>
    <priority>0.8</priority>
  </url>
  {% endfor %}
{% endfor %}

{% for page in pages %}
  <url>
    <loc>{{ SITEURL }}/{{ page.url }}</loc>
    <priority>1.0</priority>
  </url>

  {% for translation in page.translations %}
  <url>
    <loc>{{ SITEURL }}/{{ translation.url }}</loc>
    <priority>1.0</priority>
  </url>
  {% endfor %}
{% endfor %}

</urlset>

テンプレートは、他の HTML テンプレートと同じように、使っているテーマの templates ディレクトリに置きます。

次に、設定ファイルに以下の設定を追加します。

DIRECT_TEMPLATES = ('index', 'tags', 'categories', 'archives', 'sitemap')

上記の設定後に HTML を生成すると、sitemap.xml が生成されるようになります。
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3