△ grav-plugin-sitemap

https://github.com/getgrav/grav-plugin-sitemap

Sitemap は、検索エンジンが理解しやすく、インデックスしやすい XML 形式のページマップを生成する Grav Plugin です。

Installation

Installing the Sitemap plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.

GPM Installation (Preferred)

The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's Terminal (also called the command line). From the root of your Grav install type:

bin/gpm install sitemap

This will install the Sitemap plugin into your /user/plugins directory within Grav. Its files can be found under /your/site/grav/user/plugins/sitemap.

Manual Installation
To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins. Then, rename the folder to sitemap. You can find these files either on GitHub or via GetGrav.org.

You should now have all the plugin files under

/your/site/grav/user/plugins/sitemap

NOTE: This plugin is a modular component for Grav which requires Grav, the Error and Problems plugins, and a theme to be installed in order to operate.

使用方法

Sitemap Plugin により、http://yoursite.com/sitemap にアクセスすると、生成されたXMLを見ることができます。

設定デフォルト

enabled: true
route: '/sitemap'
ignore_external: true
ignore_protected: true
ignore_redirect: true
ignores:
  - /blog/blog-post-to-ignore
  - /ignore-this-route
  - /ignore-children-of-this-route/.*
whitelist:
html_support: false
urlset: 'http://www.sitemaps.org/schemas/sitemap/0.9'
short_date_format: true
include_changefreq: true
changefreq: daily
include_priority: true
priority: !!float 1
additions:
  -
    location: /something-special
    lastmod: '2020-04-16'
    changefreq: hourly
    priority: 0.3
  -
    location: /something-else
    lastmod: '2020-04-17'
    changefreq: weekly
    priority: 0.2

無効にする route リストを提供することで、対象ページを無効することができます。また、ページの Frontmatter を使って、サイトマップがそれを無視するように指示することもできます。

sitemap:
    ignore: true

多言語対応

最新のサイトマップv3.0は、最新の Google SEO 推奨事項を利用した新しい多言語サポートを含み、利用可能な各言語に対して双方向の hreflang エントリーを作成します。

これは、Gravの多言語システム構成に基づいて自動的に処理されます。

画像

ページの Frontmatter にエントリーを追加することで、サイトマップに画像を追加することができます。

sitemap:
    images:
        your_image:
            loc: your-image.png
            caption: A caption for the image
            geoloc: Amsterdam, The Netherlands
            title: The title of your image
            license: A URL to the license of the image.

サイトマップにおける画像の詳細については、Google image sitemaps を参照してください。

.xmlファイルへのアクセスのみを許可する

Redirect 301 /sitemap /sitemap.xml

HTML サポート

Sitemap バージョン 3.0.1 では、設定で html_support を有効にすると、/sitemap または /sitemap.html にアクセスしたときに、テンプレート /sitemap.html.twig に従ってHTML 形式のサイトマップを表示することができます。

このTwigテンプレートをコピーして、お使いのテーマで拡張し、ニーズに合わせてカスタマイズすることができます。

サイトマップに手動でページを追加する

管理者設定を使用して手動でサイトマップに URL を追加するか、以下のフォーマットで sitemap.yaml にエントリを追加することができます。

additions:
  -
    location: /something-special
    lastmod: '2020-04-16'
    changefreq: hourly
    priority: 0.3

正規表現に対応していることに注意してください。パスの後に .* を追加するだけで、そのパスの子パスをすべて無視することができます。

サイトマップへの動的なページ追加

他のプラグインやサードパーティの API を使ってサイトに動的なコンテンツを追加している場合、簡単なイベントでサイトマップに動的にコンテンツを追加できるようになりました。

onSitemapProcessedイベントに登録していることを確認し、次のようにサイトマップにエントリーを追加します。

public function onSitemapProcessed(\RocketTheme\Toolbox\Event\Event $e)
    {
        $sitemap = $e['sitemap'];
        $location = \Grav\Common\Utils::url('/foo-location', true);
        $sitemap['/foo'] = new \Grav\Plugin\Sitemap\SitemapEntry($location, '2020-07-02', 'weekly', '2.0');
        $e['sitemap'] = $sitemap;
    }

Utils::url() メソッドは、ルートとオプションの true パラメータを渡すことで、正しい完全な URL を簡単に作成することができます。