项目作者: bolt

项目描述 :
Bolt Sitemap extension - create XML sitemaps for your Bolt website.
高级语言: PHP
项目地址: git://github.com/bolt/Sitemap.git
创建时间: 2014-08-13T13:58:40Z
项目社区:https://github.com/bolt/Sitemap

开源协议:MIT License

下载


Sitemap

This extension will automatically create XML sitemaps for your Bolt sites.
After enabling the extension, go to http://example.org/sitemap.xml to see it.

The bigger search-engines like Google and Bing will automatically pick up your
sitemap after a while, but it’s always a good idea to explicitly tell the
search engines where to find it. To do so, this extension automatically adds
the link to the <head> section of your pages:

  1. <link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml" />

Apart from that, it’s good practice to also add the following line to your
robots.txt file:

  1. Sitemap: http://example.org/sitemap.xml

Obviously, you should replace ‘example.org’ with the domain name of your
website.

This extension adds a ‘route’ for /sitemap.xml and /sitemap by default, but
it has lower priority than user defined routes.

If you use the pagebinding in routing.yml, or anything similar route that
would match ‘sitemap’ first, you will need to add the following above that
route. You should also do this if you have an extension that might override the
default routing, like the AnimalDesign/bolt-translate extension.

  1. sitemap:
  2. path: /sitemap
  3. defaults: { _controller: sitemap.controller:sitemap }
  4. sitemapXml:
  5. path: /sitemap.xml
  6. defaults: { _controller: sitemap.controller:sitemapXml }

Note, if you have a ContentType with the property searchable: false, that
content type will be ignored.

If you have your own bundled extension you can add, remove or change links
before the sitemap is rendered. You need to subscribe to the
SitemapEvents::AFTER_COLLECTING_LINKS event. The object you will get is
an instance of SitemapEvent class which has a getLinks method that returns
a MutableBag object. The last one is an array-like list of links. See example:

  1. protected function subscribe($dispatcher)
  2. {
  3. $dispatcher->addListener(SitemapEvents::AFTER_COLLECTING_LINKS,
  4. function ($event) {
  5. /** @var SitemapEvent $event */
  6. $links = $event->getLinks();
  7. $links->add([
  8. 'link' => '/lorem-ipsum',
  9. 'title' => 'Hello World!',
  10. 'depth' => 1,
  11. ]);
  12. }
  13. );
  14. }

Sitemap stylesheets

You can customize the sitemap with an xslt stylesheet if you copy the templates/sitemap_xml.twig
file and the web/sitemap.xsl file to your theme directory and by adding the xsl-stylesheet declaration
after the xml declaration so the first two lines of the themes/{yourthemename}/sitemap_xml.twig look like:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="{{ paths.theme }}/sitemap.xsl"?>