larapulse / sitemap-bundle
提供了一种生成网站地图以及静态和动态路由的方法,这些路由需要使用Propel、Doctrine等。
Requires
- php: >=7.0
- kphoen/sitemap-generator: ~1.0
- symfony/console: ^3.0
- symfony/framework-bundle: ~3.0
Requires (Dev)
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: ^2.3
- symfony/browser-kit: ^3.0
- symfony/translation: ^3.0
- symfony/validator: ^3.0
This package is not auto-updated.
Last update: 2024-09-20 02:17:14 UTC
README
此Bundle提供了一种使用任何您想要的源(Doctrine、Propel、MongoDB、Faker等)创建XML网站地图的方法。
此Bundle旨在生成符合标准的网站地图。有关网站地图的更多信息,请访问 sitemaps.org。
网站地图生成部分由 SitemapGenerator 库处理,此Bundle简化了其与Symfony2应用的集成。
主要功能
- 静态网站地图生成
- 动态网站地图生成
- 网站地图索引生成
- 内存高效
- 数据源独立
- 支持媒体内容(目前为图片和视频)
安装
通过Composer
$ composer require larapulse/sitemap-bundle
在 app/AppKernel.php
中注册 SitemapBundle
# app/AppKernel.php public function registerBundles() { $bundles = [ // ... new Larapulse\SitemapBundle\LarapulseSitemapBundle(), ]; }
配置
将以下选项添加到 app/config/config.yml
文件中
larapulse_sitemap: base_host: http://www.foo.com base_host_sitemap: http://www.foo.com limit: 50000
注意
base_host
将被添加到网站地图中的相对URL前。base_host_sitemap
将被添加到网站地图文件名前(用于网站地图索引)limit
是同一网站地图中允许的URL数量,如果定义,它将创建一个网站地图索引
路由
如果您不想使用控制台生成网站地图,请导入路由
larapulse_sitemap: resource: "@LarapulseSitemapBundle/Resources/config/routing.yml"
这将使网站地图通过 /sitemap.xml
URL可用。
用法
将此行 /web/sitemap.xml*
添加到您的 .gitignore
中,以防止版本控制系统跟踪 sitemap.xml
文件。
提供商
为了支持任何类型的数据源,网站地图使用提供商来获取数据。
示例提供商
<?php namespace SitemapGenerator\Provider; use SitemapGenerator\Entity\Url; use SitemapGenerator\Provider\ProviderInterface; use SitemapGenerator\Sitemap\Sitemap; class CustomProvider implements ProviderInterface { public function populate(Sitemap $sitemap) { $url = new Url(); $url->setLoc('http://www.google.de'); $url->setChangefreq(Url::CHANGEFREQ_NEVER); $url->setLastmod('2012-12-19 02:28'); $sitemap->add($url); } }
所有提供商都实现了 ProviderInterface
,该接口定义了 populate()
方法。
注意:因此,提供商必须使用 sitemap.provider
标签在DIC中描述,以便它们可以自动由网站地图使用
services: sitemap_custom_provider: class: SitemapGenerator\Provider\CustomProvider tags: - { name: sitemap.provider }
所有标记为 sitemap.provider
的服务都将用于生成网站地图。
简单提供商
一个提供商,可以轻松地将静态路由添加到网站地图中。
parameters: sitemap.simple_options: routes: - {name: homepage} - name: foo params: {foo: bar} lastmod: '2017-11-23' changefreq: monthly priority: 0.5 # the following parameters are optionnal lastmod: '2015-01-01' changefreq: never priority: 0.2 services: sitemap_simple_provider: class: SitemapGenerator\Provider\SimpleProvider arguments: [ @router, %sitemap.simple_options% ] tags: - { name: sitemap.provider }
Propel提供商
此Bundle中包含了一个Propel提供商。它允许使用表的内容填充网站地图。
以下是如何配置提供商的示例
# app/config/parameters.yml parameters: sitemap.propel_options: model: ACME\DemoBundle\Model\News # /news/{id} loc: {route: news_show, params: {id: slug}} # the following parameters are optionnal filters: ['filterByIsValid'] lastmod: date changefreq: daily priority: 0.2 # app/config/services.yml services: sitemap_propel_provider: class: SitemapGenerator\Provider\PropelProvider arguments: - "@router" - "%sitemap.propel_options%" tags: - { name: sitemap.provider }
Doctrine提供商
此Bundle中包含了一个Doctrine提供商。它允许使用表的内容填充网站地图。
以下是如何配置提供商的示例
# app/config/parameters.yml parameters: sitemap.doctrine_options: entity: AcmeDemoBundle:News # /news/{id} loc: {route: news_show, params: {id: slug}} # the following parameters are optionnal query_method: findValidQuery lastmod: updatedAt changefreq: daily priority: 0.2 # app/config/services.yml services: sitemap_doctrine_provider: class: SitemapGenerator\Provider\DoctrineProvider arguments: - "@doctrine.orm.entity_manager" - "@router" - "%sitemap.doctrine_options%" tags: - { name: sitemap.provider }
变更日志
请参阅 CHANGELOG 以获取有关最近更改的更多信息。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT 以获取详细信息。
安全
如果您发现任何与安全相关的问题,请通过 :author_email 发送电子邮件,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。请参阅 许可证文件 以获取更多信息。此项目是从 sitemap-php/KPhoenSitemapBundle 分支出来的