├── .gitignore ├── .styleci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── SitemapController.php ├── SitemapServiceProvider.php ├── composer.json ├── meta.yaml └── resources └── views └── index.blade.php /.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | vendor 3 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: psr2 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to the `statamic-sitemap` add-on will be documented in this file 4 | 5 | ## 1.0.0 - 2016-12-10 6 | 7 | - First release 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 46 | 47 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 48 | 49 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 50 | 51 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 52 | 53 | **Happy coding**! -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Marbles 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Automatically add a Sitemap to your website 2 | 3 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 4 | [![SensioLabsInsight](https://img.shields.io/sensiolabs/i/008aab6e-0ac1-4a38-b712-2cb63d2ea2e4.svg?style=flat-square)](https://insight.sensiolabs.com/projects/008aab6e-0ac1-4a38-b712-2cb63d2ea2e4) 5 | [![Quality Score](https://img.shields.io/scrutinizer/g/marbles/statamic-sitemap.svg?style=flat-square)](https://scrutinizer-ci.com/g/marbles/statamic-sitemap) 6 | [![StyleCI](https://styleci.io/repos/76188779/shield?branch=master)](https://styleci.io/repos/76188779) 7 | 8 | ## Installation 9 | 10 | Download or clone the repository, rename the folder to `Sitemap` then copy the folder to your site's `Addons` directory, then refresh the add-ons to install the dependencies. 11 | 12 | ``` bash 13 | php please update:addons 14 | ``` 15 | 16 | ## Usage 17 | 18 | All you need to do is install the add-on, a sitemap based on all your content will be available at `/sitemap.xml` 19 | 20 | ## Changelog 21 | 22 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 23 | 24 | ## Contributing 25 | 26 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 27 | 28 | ## Security 29 | 30 | If you discover any security related issues, please email rias@marbles.be instead of using the issue tracker. 31 | 32 | ## Credits 33 | 34 | - [Rias Van der Veken](https://github.com/rias500) 35 | - [All Contributors](../../contributors) 36 | 37 | ## About Marbles 38 | Marbles is a digital communication agency based in Antwerp, Belgium. Learn more about us [on our website](https://www.marbles.be). 39 | 40 | ## License 41 | 42 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 43 | -------------------------------------------------------------------------------- /SitemapController.php: -------------------------------------------------------------------------------- 1 | filter(function (DataContent $entry) { 24 | /** 25 | * Check if the entry has a route set up 26 | * Only accept the front page with an empty url. 27 | */ 28 | $hasRoute = $entry instanceof Page || $entry->url() !== '/'; 29 | 30 | return $entry->published() && $hasRoute; 31 | })->map(function (DataContent $entry) use ($defaultLocale) { 32 | try { 33 | if (method_exists($entry, 'date')) { 34 | $date = $entry->date(); 35 | } 36 | } catch (InvalidEntryTypeException $e) { 37 | // Don't do anything when there's no date field 38 | } 39 | 40 | // set up alternate locales 41 | $alternates = []; 42 | foreach ($entry->locales() as $locale) { 43 | // skip default locale 44 | if ($locale === $defaultLocale) { 45 | continue; 46 | } 47 | 48 | // locale and generate url 49 | $entry->locale($locale); 50 | $alternates[$locale] = $entry->absoluteUrl(); 51 | } 52 | 53 | // reset locale of the entry to generate correct url 54 | $entry->locale($defaultLocale); 55 | 56 | return [ 57 | 'url' => $entry->absoluteUrl(), 58 | 'date' => isset($date) ? $date : null, 59 | 'alternates' => $alternates, 60 | ]; 61 | })->unique('url'); 62 | 63 | return response()->make($this->view('index', compact('content')), '200')->header('Content-Type', 'text/xml'); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /SitemapServiceProvider.php: -------------------------------------------------------------------------------- 1 | getRoutes(); 27 | $new_routes = new RouteCollection(); 28 | 29 | foreach ($old_routes as $i => $route) { 30 | if ($route->getUri() == '{segments?}') { 31 | $sitemap_route = new Route(['GET'], 'sitemap.xml', ['uses' => '\Statamic\Addons\Sitemap\SitemapController@index']); 32 | 33 | $new_routes->add($sitemap_route); 34 | } 35 | 36 | $new_routes->add($route); 37 | } 38 | 39 | app('router')->setRoutes($new_routes); 40 | } 41 | 42 | /** 43 | * Register the application services. 44 | * 45 | * @return void 46 | */ 47 | public function register() 48 | { 49 | // 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "marbles/sitemap", 3 | "description": "Automatically add a Sitemap.xml to your website", 4 | "license": "MIT", 5 | "require": { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /meta.yaml: -------------------------------------------------------------------------------- 1 | name: Sitemap 2 | version: "1.0" 3 | description: Automatically add a Sitemap.xml to your website 4 | url: https://github.com/marbles/statamic-sitemap 5 | developer: Marbles 6 | developer_url: https://www.marbles.be 7 | -------------------------------------------------------------------------------- /resources/views/index.blade.php: -------------------------------------------------------------------------------- 1 | ' . PHP_EOL; ?> 2 | 3 | @foreach ($content as $entry) 4 | 5 | {{ $entry['url'] }} 6 | @if (!is_null($entry['date'])) 7 | 8 | {{ $entry['date']->toAtomString() }} 9 | 10 | @endif 11 | @foreach ($entry['alternates'] as $locale => $url) 12 | 17 | @endforeach 18 | 19 | @endforeach 20 | 21 | --------------------------------------------------------------------------------