core23 / sitemap-bundle
4.4.0
2022-09-18 09:59 UTC
Requires
- php: ^8.0
- psr/cache: ^1.0 || ^2.0 || ^3.0
- psr/simple-cache: ^1.0 || ^2.0 || ^3.0
- symfony/config: ^5.4 || ^6.0
- symfony/dependency-injection: ^5.4 || ^6.0
- symfony/expression-language: ^5.4 || ^6.0
- symfony/framework-bundle: ^5.4 || ^6.0
- symfony/http-foundation: ^5.4 || ^6.0
- symfony/http-kernel: ^5.4 || ^6.0
- symfony/options-resolver: ^5.4 || ^6.0
- symfony/routing: ^5.4 || ^6.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.0.1
- symfony/browser-kit: ^5.4 || ^6.0
README
此包提供了一些用于自动生成 sitemap.xml 的类。
安装
打开命令行,进入您的项目目录,然后执行以下命令以下载此包的最新稳定版本
composer require nucleos/sitemap-bundle
启用 Bundle
然后,通过将其添加到项目 config/bundles.php
文件中已注册的包列表中来启用此包
// config/bundles.php return [ // ... Nucleos\SitemapBundle\NucleosSitemapBundle::class => ['all' => true], ];
配置 Bundle
创建一个名为 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 许可证 的约束。