dpn/xml-sitemap-bundle
Composer 安装命令:
composer require dpn/xml-sitemap-bundle
包简介
Generates XML sitemaps for your favourite search engine by extracting sitemap information out of the site's routes.
关键字:
README 文档
README
This bundle generates XML sitemaps for your favourite search engine by extracting sitemap information out of your application's routes. Additionally, you can create your own generators to provide URLs. The sitemap(s) generated follow the sitemap protocol.
Installation
-
Install with composer:
composer require dpn/xml-sitemap-bundle -
Enable the bundle in the kernel:
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Dpn\XmlSitemapBundle\DpnXmlSitemapBundle(), ); }
-
Register the routing in
app/config/routing.yml(this step is optional if using the console command to pre-generate the sitemaps)DpnXmlSitemapBundle: resource: "@DpnXmlSitemapBundle/Resources/config/routing.xml"
Usage
Exposing Routes
To expose a route to the sitemap add the option sitemap to your route definition:
blog_index: path: /blog defaults: { _controller: AppBundle:Blog:index } options: sitemap: true
This will expose this route to your sitemap using the default options from your config. To control the options
for this sitemap entry, add them to the sitemap option:
blog_index: path: /blog defaults: { _controller: AppBundle:Blog:index } options: sitemap: priority: 0.7 changefreq: hourly
NOTE: Only routes without parameters may be exposed in this way. For routes with parameters, you must create a custom generator (see below).
Custom Generator
For more complex routes that have parameters, you must create a custom generator.
-
Create a generator class that implements
Dpn\XmlSitemapBundle\Sitemap\GeneratorInterface. This class must have agenerate()method that returns an array ofDpn\XmlSitemapBundle\Sitemap\Entryobjects.use Dpn\XmlSitemapBundle\Sitemap\Entry; use Dpn\XmlSitemapBundle\Sitemap\GeneratorInterface; class MySitemapGenerator implements GeneratorInterface { public function generate() { $entries = array(); $entries[] = new Entry('http://example.com/foobar'); // must be absolute URL // add more entries - perhaps fetched from database return $entries; } }
-
Add this class as a service tagged with
dpn_xml_sitemap.generator:services: my_sitemap_generator: class: MySitemapGenerator tags: - { name: dpn_xml_sitemap.generator }
Sitemap Index
According to sitemaps.org the maximum number of entries a sitemap.xml
may have is 50,000. When the number of sitemap entries exceeds this, the entries are split across multiple sitemaps
(ie /sitemap1.xml,/sitemap2.xml.../sitemapN.xml).
A sitemap index is accessible at /sitemap_index.xml.
The maximum entries per sitemap is configurable:
dpn_xml_sitemap: max_per_sitemap: 50000 #default
HTTP Caching
You can enable http caching for the sitemap(n).xml/sitemap_index.xml URI's by setting the number of
seconds in your config:
dpn_xml_sitemap: http_cache: 3600
Console Dump Command
The dpn:xml-sitemap:dump command is available to pre-generate sitemap.xml files:
Usage:
dpn:xml-sitemap:dump [--target="..."] host
Arguments:
host The full hostname for your website (ie http://www.google.com)
Options:
--target Override the target directory to dump sitemap(s) in
Help:
Dumps your sitemap(s) to the filesystem (defaults to web/)
NOTE: The command requires Symfony 2.4+.
Full Default Configuration
The following is the default configuration for this bundle:
dpn_xml_sitemap: # The length of time (in seconds) to cache the sitemap/sitemap_index xml\'s (a reverse proxy is required) http_cache: ~ # The number of url entries in a single sitemap max_per_sitemap: 50000 # The default options for sitemap URL entries to be used if not overridden defaults: # Value between 0.0 and 1.0 or null for sitemap protocol default priority: ~ # One of [always, hourly, daily, weekly, monthly, yearly, never] or null for sitemap protocol default changefreq: ~
License
See Resources/meta/LICENSE.
dpn/xml-sitemap-bundle 适用场景与选型建议
dpn/xml-sitemap-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.23k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2012 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Sitemap」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dpn/xml-sitemap-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dpn/xml-sitemap-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dpn/xml-sitemap-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony sitemap generator
PHP Simple Sitemap Generator
Interfaces for web resource models and services to retrieve and create them
Sitemap crawler/generator. For the given URL it will return sitemap XML file with URLs and images.
Sitemap and sitemap index builder for Jigsaw.
Sitemap for seo
统计信息
- 总下载量: 34.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 26
- 点击次数: 20
- 依赖项目数: 1
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2012-12-05