{"id":14984084,"url":"https://github.com/werkspot/sitemap-bundle","last_synced_at":"2025-04-10T19:43:48.698Z","repository":{"id":49238347,"uuid":"39082129","full_name":"Werkspot/sitemap-bundle","owner":"Werkspot","description":"Bundle for generating dynamic sitemap.xml content with support for multiple sections","archived":false,"fork":false,"pushed_at":"2024-01-30T23:40:29.000Z","size":90,"stargazers_count":10,"open_issues_count":4,"forks_count":4,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-04-02T22:37:23.707Z","etag":null,"topics":["bundle","php","sitemap","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Werkspot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-14T15:07:59.000Z","updated_at":"2023-09-20T10:53:23.000Z","dependencies_parsed_at":"2024-09-25T00:30:12.473Z","dependency_job_id":null,"html_url":"https://github.com/Werkspot/sitemap-bundle","commit_stats":{"total_commits":60,"total_committers":13,"mean_commits":4.615384615384615,"dds":0.8166666666666667,"last_synced_commit":"61468b04eb0898ed03e9cb625c08b2fe8b69b391"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Werkspot%2Fsitemap-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Werkspot%2Fsitemap-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Werkspot%2Fsitemap-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Werkspot%2Fsitemap-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Werkspot","download_url":"https://codeload.github.com/Werkspot/sitemap-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281424,"owners_count":21077423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bundle","php","sitemap","symfony","symfony-bundle"],"created_at":"2024-09-24T14:08:25.279Z","updated_at":"2025-04-10T19:43:48.673Z","avatar_url":"https://github.com/Werkspot.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Werkspot sitemap bundle\nBundle for generating dynamic sitemap.xml content with support for multiple sections and pages per section.\n\n[![Travis build status](https://travis-ci.org/Werkspot/sitemap-bundle.svg?branch=master)](https://travis-ci.org/Werkspot/sitemap-bundle)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Werkspot/sitemap-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Werkspot/sitemap-bundle/?branch=master)\n\n### Install\n\n`# composer require werkspot/sitemap-bundle`\n\n#### Update your routing\n\n```yaml\nwerkspot_sitemap:\n    resource: \"@WerkspotSitemapBundle/Resources/config/routing.yml\"\n    prefix:   /\n```\nThat will make the bundle listen to `/sitemap.xml`, `/sitemap.{section}.xml` and `/sitemap.{section}.{page}.xml`\n\n### Usage\n\nThe bundle generates a sitemap by looking for data providers.\n\nA provider is a class that implements [ProviderInterface](Provider/ProviderInterface.php) and is tagged as `werkspot.sitemap_provider` in the service container.\n\nThe bundle's service will gather data from all providers and create a sitemap section for everyone of them.\n\nEach section can generate one or more pages.\n\n#### Single page provider\n\nTo facilitate sitemap creation for static lists things or pages that do not need to be created dynamically [AbstractSinglePageSitemapProvider](Provider/AbstractSinglePageSitemapProvider.php) can be extended. That will only require providing a section name and a SitemapSectionPage with Url objects.\n\n##### Example\n\n```php\nnamespace AppBundle\\Sitemap;\n\nuse Werkspot\\Bundle\\SitemapBundle\\Provider\\AbstractSinglePageSitemapProvider;\nuse Werkspot\\Bundle\\SitemapBundle\\Sitemap\\SitemapSectionPage;\nuse Werkspot\\Bundle\\SitemapBundle\\Sitemap\\Url;\n\nclass StaticPageSitemapProvider extends AbstractSinglePageSitemapProvider\n{\n    /**\n     * @return string\n     */\n    public function getSectionName()\n    {\n        return 'default';\n    }\n\n    /**\n     * @return SitemapSectionPage\n     */\n    public function getSinglePage()\n    {\n        $page = new SitemapSectionPage();\n\n        $urlRoute = $this-\u003egenerateUrl('home');\n        $page-\u003eaddUrl(new Url($urlRoute, Url::CHANGEFREQ_WEEKLY, 1.0));\n\n        $urlRoute = $this-\u003egenerateUrl('some_page');\n        $page-\u003eaddUrl(new Url($urlRoute, Url::CHANGEFREQ_WEEKLY, 0.6));\n\n        $urlRoute = $this-\u003egenerateUrl('another_page');\n        $page-\u003eaddUrl(new Url($urlRoute, Url::CHANGEFREQ_WEEKLY, 0.6));\n    \n        return $page;\n    }\n}\n```\n\nThis will generate `/sitemap.default.xml` with 3 pages and put a link to it in `/sitemap.xml`\n\n#### Multiple page provider\n\nA more complex provider can extend [AbstractSitemapProvider](Provider/AbstractSitemapProvider.php).\nIn that case the provider can select how many pages it wants to generate and what results to return in every page.\n\n##### Example\n\nThe following will generate `/sitemap.products.xml` and if the count is too high it will split in multiple pages: `/sitemap.products.1.xml`, `/sitemap.products.2.xml` etc and put all the right links to these in `/sitemap.xml` for indexing to happen.\n\n```php\nnamespace AppBundle\\Sitemap;\n\nuse Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface;\nuse Werkspot\\Bundle\\SitemapBundle\\Provider\\AbstractSitemapProvider;\nuse Werkspot\\Bundle\\SitemapBundle\\Sitemap\\SitemapSectionPage;\nuse Werkspot\\Bundle\\SitemapBundle\\Sitemap\\Url;\nuse AppBundle\\Domain\\Entity\\Repository\\ProductRepository;\nuse AppBundle\\Domain\\Entity\\Product;\n\nclass ProductSitemapProvider extends AbstractSitemapProvider\n{\n    /**\n     * @var ProductRepository\n     */\n    private $productRepository;\n\n    /**\n     * @param UrlGeneratorInterface $urlGenerator\n     * @param ProductRepository $productRepository\n     */\n    public function __construct(UrlGeneratorInterface $urlGenerator, ProductRepository $productRepository)\n    {\n        parent::__construct($urlGenerator);\n        $this-\u003eproductRepository = $productRepository;\n    }\n\n    /**\n     * @param int $pageNumber\n     * @return SitemapSectionPage\n     */\n    public function getPage($pageNumber)\n    {\n        $products = $this-\u003eproductRepository-\u003egetProductsForSitemapPage(\n            $pageNumber,\n            $this-\u003egetMaxItemsPerPage()\n        );\n\n        $page = new SitemapSectionPage();\n        foreach ($products as $product) {\n            $urlRoute = $this-\u003egenerateUrl('product_details', [\n                'slug' =\u003e $product-\u003egetSlug()\n            ]);\n            $page-\u003eaddUrl(new Url($urlRoute, Url::CHANGEFREQ_MONTHLY, 0.6));\n        }\n        return $page;\n    }\n\n    /**\n     * @return string\n     */\n    public function getSectionName()\n    {\n        return 'products';\n    }\n\n    /**\n     * @return int\n     */\n    public function getCount()\n    {\n        return $this-\u003eproductRepository-\u003egetTotalCount();\n    }\n}\n```\n\n### Adding alternate language pages\n\nTo add links to translations for pages to the sitemap, you can use `AlternateLink` and add these to a Url.\n\nGoogle Guidelines: https://support.google.com/webmasters/answer/2620865?hl=en\n\n*Note: The alternate links should include the Url itself, see the second note in the link above*\n\n#### Example\n\n```php\n    /**\n     * @return SitemapSectionPage\n     */\n    public function getSinglePage()\n    {\n        $page = new SitemapSectionPage();\n\n        $urlRoute = $this-\u003egenerateUrl('home');\n        $urlRouteDe = $this-\u003egenerateUrl('home', ['_locale' =\u003e 'de']);\n        $urlRouteFr = $this-\u003egenerateUrl('home', ['_locale' =\u003e 'fr']);\n        \n        $sitemapUrl = new Url($urlRoute, Url::CHANGEFREQ_WEEKLY, 1.0);\n        $sitemapUrl-\u003eaddAlternateLink(new AlternateLink($urlRouteDe, 'de'));\n        $sitemapUrl-\u003eaddAlternateLink(new AlternateLink($urlRouteFr, 'fr'));\n        $sitemapUrl-\u003eaddAlternateLink(new AlternateLink($urlRoute, 'x-default')); // Country select page\n        // Or\n        $sitemapUrl-\u003eaddAlternateLink(new AlternateLink($urlRoute, 'en')); \n        \n        $page-\u003eaddUrl($sitemapUrl);\n\n        return $page;\n    }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwerkspot%2Fsitemap-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwerkspot%2Fsitemap-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwerkspot%2Fsitemap-bundle/lists"}