{"id":29203541,"url":"https://github.com/rumendamyanov/php-sitemap","last_synced_at":"2025-07-02T14:10:44.573Z","repository":{"id":8721017,"uuid":"10392044","full_name":"RumenDamyanov/php-sitemap","owner":"RumenDamyanov","description":"Framework-agnostic PHP package for generating sitemaps in XML, TXT, HTML, and Google News formats.","archived":false,"fork":false,"pushed_at":"2025-06-08T08:26:31.000Z","size":265,"stargazers_count":1307,"open_issues_count":41,"forks_count":275,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-06-27T06:37:59.807Z","etag":null,"topics":["laravel","php","sitemap-generator","sitemap-xml","sitemapindex","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"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/RumenDamyanov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2013-05-30T21:09:32.000Z","updated_at":"2025-06-22T07:38:48.000Z","dependencies_parsed_at":"2025-06-25T13:43:19.147Z","dependency_job_id":"c80d9082-a414-4b0b-9bcb-797f026c9918","html_url":"https://github.com/RumenDamyanov/php-sitemap","commit_stats":null,"previous_names":["laravelium/laravel-sitemap","rumendamyanov/php-sitemap","rumendamyanov/larapal-sitemap","larapalcom/laravel-sitemap"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/RumenDamyanov/php-sitemap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RumenDamyanov%2Fphp-sitemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RumenDamyanov%2Fphp-sitemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RumenDamyanov%2Fphp-sitemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RumenDamyanov%2Fphp-sitemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RumenDamyanov","download_url":"https://codeload.github.com/RumenDamyanov/php-sitemap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RumenDamyanov%2Fphp-sitemap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263154352,"owners_count":23422011,"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":["laravel","php","sitemap-generator","sitemap-xml","sitemapindex","symfony"],"created_at":"2025-07-02T14:10:43.855Z","updated_at":"2025-07-02T14:10:44.550Z","avatar_url":"https://github.com/RumenDamyanov.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **[php-sitemap](https://github.com/RumenDamyanov/php-sitemap) package**\n\n[![CI](https://github.com/RumenDamyanov/php-sitemap/actions/workflows/ci.yml/badge.svg)](https://github.com/RumenDamyanov/php-sitemap/actions)\n[![codecov](https://codecov.io/gh/RumenDamyanov/php-sitemap/branch/master/graph/badge.svg)](https://codecov.io/gh/RumenDamyanov/php-sitemap)\n\n**php-sitemap** is a modern, framework-agnostic PHP package for generating sitemaps in XML, TXT, HTML, and Google News formats. It works seamlessly with Laravel, Symfony, or any PHP project. Features include high test coverage, robust CI, extensible adapters, and support for images, videos, translations, alternates, and Google News.\n\n\n---\n\n## Features\n\n- **Framework-agnostic**: Use in Laravel, Symfony, or any PHP project\n- **Multiple formats**: XML, TXT, HTML, Google News, mobile\n- **Rich content**: Supports images, videos, translations, alternates, Google News\n- **Modern PHP**: Type-safe, extensible, and robust\n- **High test coverage**: 100% code coverage, CI/CD ready\n- **Easy integration**: Simple API, drop-in for controllers/routes\n- **Extensible**: Adapters for Laravel, Symfony, and more\n\n---\n\n## Installation\n\n```bash\ncomposer require rumenx/php-sitemap\n```\n\n---\n\n## Usage\n\n### Laravel Example\n\n**Controller method:**\n\n```php\nuse Rumenx\\Sitemap\\Sitemap;\n\npublic function sitemap(Sitemap $sitemap)\n{\n    $sitemap-\u003eadd('https://example.com/', now(), '1.0', 'daily');\n    $sitemap-\u003eadd('https://example.com/about', now(), '0.8', 'monthly', images: [\n        ['url' =\u003e 'https://example.com/img/about.jpg', 'title' =\u003e 'About Us']\n    ]);\n    // Add more items as needed...\n    return response($sitemap-\u003erender('xml'), 200, ['Content-Type' =\u003e 'application/xml']);\n}\n```\n\n**Route registration:**\n\n```php\nRoute::get('/sitemap.xml', [SitemapController::class, 'sitemap']);\n```\n\n**Advanced:**\n\n```php\n// Add with translations, videos, alternates, Google News\n$sitemap-\u003eadd(\n    'https://example.com/news',\n    now(),\n    '0.7',\n    'weekly',\n    images: [['url' =\u003e 'https://example.com/img/news.jpg', 'title' =\u003e 'News Image']],\n    title: 'News Article',\n    translations: [['language' =\u003e 'fr', 'url' =\u003e 'https://example.com/fr/news']],\n    videos: [['title' =\u003e 'News Video', 'description' =\u003e 'Video description']],\n    googlenews: [\n        'sitename' =\u003e 'Example News',\n        'language' =\u003e 'en',\n        'publication_date' =\u003e now(),\n    ],\n    alternates: [['media' =\u003e 'print', 'url' =\u003e 'https://example.com/news-print']]\n);\n```\n\n---\n\n### Symfony Example\n\n**Controller:**\n\n```php\nuse Rumenx\\Sitemap\\Sitemap;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass SitemapController\n{\n    public function sitemap(): Response\n    {\n        $sitemap = new Sitemap();\n        $sitemap-\u003eadd('https://example.com/', (new \\DateTime())-\u003eformat(DATE_ATOM), '1.0', 'daily');\n        $sitemap-\u003eadd('https://example.com/contact', (new \\DateTime())-\u003eformat(DATE_ATOM), '0.5', 'monthly');\n        // Add more items as needed...\n        return new Response($sitemap-\u003erender('xml'), 200, ['Content-Type' =\u003e 'application/xml']);\n    }\n}\n```\n\n**Route registration:**\n\n```yaml\n# config/routes.yaml\nsitemap:\n    path: /sitemap.xml\n    controller: App\\Controller\\SitemapController::sitemap\n```\n\n---\n\n### Generic PHP Example\n\n```php\nrequire 'vendor/autoload.php';\n\nuse Rumenx\\Sitemap\\Sitemap;\n\n$sitemap = new Sitemap();\n$sitemap-\u003eadd('https://example.com/', date('c'), '1.0', 'daily');\n$sitemap-\u003eadd('https://example.com/products', date('c'), '0.9', 'weekly', [\n    ['url' =\u003e 'https://example.com/img/product.jpg', 'title' =\u003e 'Product Image']\n]);\nheader('Content-Type: application/xml');\necho $sitemap-\u003erender('xml');\n```\n\n---\n\n### Advanced Features\n\n```php\n// Add with all supported fields\n$sitemap-\u003eadd(\n    'https://example.com/news',\n    date('c'),\n    '0.8',\n    'daily',\n    images: [['url' =\u003e 'https://example.com/img/news.jpg', 'title' =\u003e 'News Image']],\n    title: 'News Article',\n    translations: [['language' =\u003e 'fr', 'url' =\u003e 'https://example.com/fr/news']],\n    videos: [['title' =\u003e 'News Video', 'description' =\u003e 'Video description']],\n    googlenews: [\n        'sitename' =\u003e 'Example News',\n        'language' =\u003e 'en',\n        'publication_date' =\u003e date('c'),\n    ],\n    alternates: [['media' =\u003e 'print', 'url' =\u003e 'https://example.com/news-print']]\n);\n\n// Render as TXT\nfile_put_contents('sitemap.txt', $sitemap-\u003erender('txt'));\n\n// Render as HTML\nfile_put_contents('sitemap.html', $sitemap-\u003erender('html'));\n```\n\n---\n\n### add() vs addItem()\n\nYou can add sitemap entries using either the `add()` or `addItem()` methods:\n\n**add() — Simple, type-safe, one-at-a-time:**\n\n```php\n// Recommended for most use cases\n$sitemap-\u003eadd(\n    'https://example.com/',\n    date('c'),\n    '1.0',\n    'daily',\n    images: [['url' =\u003e 'https://example.com/img.jpg', 'title' =\u003e 'Image']],\n    title: 'Homepage'\n);\n```\n\n**addItem() — Advanced, array-based, supports batch:**\n\n```php\n// Add a single item with an array (all fields as keys)\n$sitemap-\u003eaddItem([\n    'loc' =\u003e 'https://example.com/about',\n    'lastmod' =\u003e date('c'),\n    'priority' =\u003e '0.8',\n    'freq' =\u003e 'monthly',\n    'title' =\u003e 'About Us',\n    'images' =\u003e [['url' =\u003e 'https://example.com/img/about.jpg', 'title' =\u003e 'About Us']],\n]);\n\n// Add multiple items at once (batch add)\n$sitemap-\u003eaddItem([\n    [\n        'loc' =\u003e 'https://example.com/page1',\n        'title' =\u003e 'Page 1',\n    ],\n    [\n        'loc' =\u003e 'https://example.com/page2',\n        'title' =\u003e 'Page 2',\n    ],\n]);\n```\n\n- Use `add()` for simple, explicit, one-at-a-time additions (recommended for most users).\n- Use `addItem()` for advanced, batch, or programmatic additions with arrays (e.g., when looping over database results).\n\n---\n\n## Testing\n\n```bash\n./vendor/bin/pest\n```\n\n---\n\n## License\n\n[MIT License](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumendamyanov%2Fphp-sitemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frumendamyanov%2Fphp-sitemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumendamyanov%2Fphp-sitemap/lists"}