nucleos/sitemap-bundle

此包已被弃用且不再维护。作者建议使用 nucleos/seo-bundle 包。

此包提供了一些类,用于自动生成 sitemap.xml。

4.4.0 2022-09-18 09:59 UTC

This package is auto-updated.

Last update: 2022-09-18 09:59:27 UTC


README

Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

Continuous Integration Code Coverage Type Coverage

此包提供了一些类,用于自动生成 sitemap.xml

安装

打开命令行,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本

composer require nucleos/sitemap-bundle

启用包

然后,通过将其添加到项目 config/bundles.php 文件中注册的包列表中,来启用该包

// config/bundles.php

return [
    // ...
    Nucleos\SitemapBundle\NucleosSitemapBundle::class => ['all' => true],
];

配置包

创建一个名为 nucleos_sitemap.yaml 的配置文件

# config/routes/nucleos_sitemap.yaml

nucleos_sitemap:
    resource: '@NucleosSitemapBundle/Resources/config/routing/sitemap.yml'
    prefix: /

如果您想使用 symfony 缓存,您应该定义一个新的缓存池(PSR 6)并创建一个适配器,将其映射到简单的缓存(PSR 16)

nucleos_sitemap:
    cache:
        service: 'sitemap.cache.simple'

framework:
    cache:
        pools:
            sitemap.cache:
                adapter: cache.app
                default_lifetime: 60

services:
    sitemap.cache.simple:
        class: 'Symfony\Component\Cache\Psr16Cache'
        arguments:
            - '@sitemap.cache'

添加静态条目

您可以在 yaml 配置中添加静态条目

# config/packages/nucleos_sitemap.yaml

nucleos_sitemap:
    static:
        - { url: 'http://example.com', priority: 75, changefreq: 'weekly' }

添加自定义 sitemap

如果您想创建自定义 sitemap,您需要做的唯一一件事是创建一个使用 Nucleos\SitemapBundle\Sitemap\SitemapServiceInterface 的服务,并用 nucleos.sitemap 标签该服务。

    <service id="App\Sitemap\CustomSitemap">
      <tag name="nucleos.sitemap"/>
    </service>

许可

此包遵循 MIT 许可证