This is a package to make it easier to generate and maintain multilingual XML sitemaps for Google. Once I figured out the convoluted requirements for hreflang tags and return tags I quickly realized it would be a nightmare to manually maintain multilingual sitemaps so I wrote this package to automate it.
composer require escuccim/sitemap
Then register the components in /config/app.php:
Add the following to the 'providers' array:
Escuccim\Sitemap\sitemapServiceProvider::class,
And add the following to 'aliases' array:
Run the database migrations to create the blog tables and update the users table:
php artisan migrate
By default I use a middleware I call 'admin' to verify if the user has permission to access the administrative pages. If you wish to use this you need to register the middleware in /app/Http/Kernel.php in $routeMiddleware:
'admin' => \Escuccim\Sitemap\Middleware\AdminMiddleware::class,
If you wish to use your own middleware or stick with Laravel's Auth middleware you can do so by updating the config (see below).
This package contains its own routes, models, controllers and views so should work after installation. To access it just go to /sitemapadmin. By default it will generate two sitemaps, one is a sitemap index available at /sitemap, the other is a sitemap for the static pages available at /sitemap/pages.
If you wish to edit my views or other files you can publish them to your application:
php artisan vendor:publish
This will publish all of the files. To only publish certain files add --tag=[group]
, using the groups listed below:
The administrative page at /sitemapadmin will have three sections:
Should be fairly self-explanatory. To associate images with the page add them in the edit screen for the appropriate page. All of the values associated with each page are used in the sitemap except 'name'.
Allows you to list additional sitemaps in your sitemap index. For example I have an additional sitemap for blog articles. Note you will need to create these sitemaps on your own, but it should be relatively easy if you copy the view file for pages and change the PHP variables accordingly.
Each sitemap has two fields you can edit:
This is where you list your subdomains and their associated languages. Each subdomain has two fields in the edit and add screens:
From the main page you can also specify a default subdomain which will be listed in the sitemap as the x-default.
The sitemap generated will have an entry for each page and each subdomain, along with hreflang tags again for each page and each subdomain.
To access the configuration files you need to publish the config file to /config/sitemap.php with
php artisan vendor:publish --tag=config
.
The config file has the following values: