nepttune / sitemap
Nette 框架组件,渲染为 xml 网站地图。
v2.0.1
2019-04-26 12:35 UTC
Requires
- nette/application: ^3.0
- nette/caching: ^3.0
- nette/di: ^3.0
README
🔧 网站地图生成组件
简介
该组件自动从注解的控制器操作中生成网站地图。找到的操作被缓存以提高性能。
安装
使用 composer 安装包
composer require nepttune/sitemap
依赖项
如何使用
- 实现
\Nepttune\TI\ISitemap
接口并在选定的控制器中使用\Nepttune\TI\TSitemap
特性(那些应该在网站地图中包含链接的控制器)。 - 将
@sitemap
注解添加到选定的操作。 - 在配置文件中将
\Nepttune\Component\ISitemapFactory
注册为服务。 - 将其注入到例如 SitemapPresenter 中,编写
createComponent
方法并在模板文件中使用宏{control}
。- 就像任何其他组件一样。
- 内容类型自动设置为
application/xml
。
示例配置
services:
- Nepttune\Component\ISitemapFactory
您可以可选地提供配置数组并启用为每个条目包含 hreflang 链接(需要在控制器中提供翻译器)。
parameters:
sitemap:
hreflang: true
services:
sitemapFactory:
implement: Nepttune\Component\ISitemapFactory
arguments:
- '%sitemap%'
示例控制器
class ExamplePresenter implements IPresenter, ISitemap
{
use TSitemap;
/** @var \Nepttune\Component\ISitemapFactory */
protected $iSitemapFactory;
public function __construct(\Nepttune\Component\ISitemapFactory $ISitemapFactory)
{
$this->iSitemapFactory = $ISitemapFactory;
}
public function actionSitemap()
{
$this->getHttpResponse()->setContentType('application/xml');
}
/**
* @sitemap
*/
public function actionExample()
{
}
protected function createComponentSitemap()
{
return $this->iSitemapFactory->create();
}
}