From 0116d220d4df8b8ceb95be5085833d31422b2ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 16 Nov 2026 10:35:40 +0100 Subject: [PATCH] feat(sitemap): implement sitemap generation and configuration - Added new sitemap generation configuration. - Removed deprecated refresh-sitemap configuration. - Updated Product model to implement Sitemapable interface. - Upgraded sitemap-generator dependency to version 8.1. --- app/Models/Product.php | 17 +++- composer.json | 2 +- composer.lock | 157 ++++++++++++++++------------------- config/refresh-sitemap.php | 118 -------------------------- config/sitemap-generator.php | 100 ++++++++++++++++++++++ public/sitemap.xml | 24 ------ 6 files changed, 188 insertions(+), 230 deletions(-) delete mode 100644 config/refresh-sitemap.php create mode 100644 config/sitemap-generator.php delete mode 100644 public/sitemap.xml diff --git a/app/Models/Product.php b/app/Models/Product.php index 2e99e54a..17830478 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -34,8 +34,10 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Date; use Illuminate\Support\Str; use Ramsey\Uuid\Uuid; +use Spatie\Sitemap\Tags\Url; use Uwil\Laravel\Redirections\Interfaces\RedirectableInterface; use Uwil\Laravel\Redirections\Traits\IsRedirectable; +use Uwil\SitemapGenerator\Contracts\Sitemapable; /** * @property string $id @@ -110,7 +112,7 @@ use Uwil\Laravel\Redirections\Traits\IsRedirectable; 'picture_large_title', 'picture_large', ])] -class Product extends Model implements ModelWithOrder, ModelWithStar, ModelWithStatus, RedirectableInterface +class Product extends Model implements ModelWithOrder, ModelWithStar, ModelWithStatus, RedirectableInterface, Sitemapable { use HasOrder; use HasStar; @@ -121,6 +123,19 @@ class Product extends Model implements ModelWithOrder, ModelWithStar, ModelWithS public const CREATED_AT = null; + #[\Override] + public function getLocalizedUrl(string $locale): string + { + return route('fo.products.show', ['productWithPricingPublished' => $this->slug]); + } + + /** @return Url|string|string[] */ + #[\Override] + public function toSitemapTag(): Url | string | array + { + return $this->getLocalizedUrl(app()->getLocale()); + } + public function getId(): ProductId { return new ProductId(Uuid::fromString($this->id)); diff --git a/composer.json b/composer.json index d946e3de..38fd9b2f 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "uwil/k8s-laravel": "^3.0", "uwil/laravel-admin-secure": "^6.0", "uwil/laravel-redirections": "^3.0", - "uwil/sitemap-generator": "^7.0", + "uwil/sitemap-generator": "^8.1", "uwil/storage-laravel": "*", "webmozart/assert": "^2.4" }, diff --git a/composer.lock b/composer.lock index db280ac1..29b821fb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4153b2dd831c9e7586484890903f713e", + "content-hash": "e234de4cf50bd7d34ad2b9914bd1660f", "packages": [ { "name": "aws/aws-crt-php", @@ -3604,82 +3604,6 @@ }, "time": "2022-12-02T22:17:43+00:00" }, - { - "name": "mcamara/laravel-localization", - "version": "v2.4.2", - "source": { - "type": "git", - "url": "https://github.com/mcamara/laravel-localization.git", - "reference": "dbfa563ea0ceb6d072adc280a8830999ade9ed74" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mcamara/laravel-localization/zipball/dbfa563ea0ceb6d072adc280a8830999ade9ed74", - "reference": "dbfa563ea0ceb6d072adc280a8830999ade9ed74", - "shasum": "" - }, - "require": { - "laravel/framework": "^11.0|^12.0|^13.0", - "php": "^8.2" - }, - "require-dev": { - "orchestra/testbench": "^9.0|^10.0|^11.0", - "phpunit/phpunit": "^10.1|^11.0|^12.5.12" - }, - "suggest": { - "ext-intl": "*" - }, - "type": "library", - "extra": { - "laravel": { - "aliases": { - "LaravelLocalization": "Mcamara\\LaravelLocalization\\Facades\\LaravelLocalization" - }, - "providers": [ - "Mcamara\\LaravelLocalization\\LaravelLocalizationServiceProvider" - ] - } - }, - "autoload": { - "psr-0": { - "Mcamara\\LaravelLocalization": "src/" - }, - "classmap": [] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marc Cámara", - "email": "mcamara88@gmail.com", - "role": "Developer" - } - ], - "description": "Easy localization for Laravel", - "homepage": "https://github.com/mcamara/laravel-localization", - "keywords": [ - "laravel", - "localization", - "php" - ], - "support": { - "issues": "https://github.com/mcamara/laravel-localization/issues", - "source": "https://github.com/mcamara/laravel-localization/tree/v2.4.2" - }, - "funding": [ - { - "url": "https://github.com/iwasherefirst2", - "type": "github" - }, - { - "url": "https://github.com/mcamara", - "type": "github" - } - ], - "time": "2026-08-24T08:07:04+00:00" - }, { "name": "mews/purifier", "version": "3.4.4", @@ -10508,27 +10432,38 @@ }, { "name": "uwil/sitemap-generator", - "version": "7.1.1", + "version": "8.1.1", "source": { "type": "git", "url": "git@lab.s-web.fr:ldc-web/projets/sitemap-generator.git", - "reference": "1f789eca239e9c064f9eab8acc1dc5fca3428b00" + "reference": "5ee3a5f748a186cd9aa2ab3c3959f1594d8c4949" }, "dist": { "type": "zip", - "url": "https://lab.s-web.fr/api/v4/projects/108/packages/composer/archives/uwil/sitemap-generator.zip?sha=1f789eca239e9c064f9eab8acc1dc5fca3428b00", - "reference": "1f789eca239e9c064f9eab8acc1dc5fca3428b00", + "url": "https://lab.s-web.fr/api/v4/projects/108/packages/composer/archives/uwil/sitemap-generator.zip?sha=5ee3a5f748a186cd9aa2ab3c3959f1594d8c4949", + "reference": "5ee3a5f748a186cd9aa2ab3c3959f1594d8c4949", "shasum": "" }, "require": { - "illuminate/support": "~11|~12|~13", - "laravel/framework": "~11|~12|~13", - "mcamara/laravel-localization": "^2.4", + "illuminate/support": "^13.0", + "laravel/framework": "^13.0", + "php": "^8.5", "spatie/laravel-sitemap": "^8.1" }, "require-dev": { + "ace-of-aces/intellipest": "^1.0", + "larastan/larastan": "^3.0", + "laravel/pint": "^1.32", + "mcamara/laravel-localization": "^2.4", + "orchestra/testbench": "^11.3", + "pestphp/pest": "^5.3", + "php-parallel-lint/php-parallel-lint": "^1.4", "slevomat/coding-standard": "^8.15" }, + "suggest": { + "league/flysystem-aws-s3-v3": "Required to store the sitemap on an Amazon S3 disk", + "mcamara/laravel-localization": "Required for localized route name translations" + }, "type": "library", "extra": { "laravel": { @@ -10542,7 +10477,57 @@ "Uwil\\SitemapGenerator\\": "src/" } }, - "description": "Create sitemap.xml" + "autoload-dev": { + "psr-4": { + "Uwil\\SitemapGenerator\\Tests\\": "tests/" + } + }, + "scripts": { + "lint": [ + "./vendor/bin/phpcs && ./vendor/bin/pint --test" + ], + "test": [ + "./vendor/bin/pest" + ], + "format": [ + "./vendor/bin/pint" + ], + "analyze": [ + "./vendor/bin/phpstan analyse" + ], + "lint:fix": [ + "./vendor/bin/phpcbf && ./vendor/bin/pint" + ], + "lint:php": [ + "./vendor/bin/parallel-lint --exclude vendor ." + ], + "lint:pint": [ + "./vendor/bin/pint --test" + ], + "lint:phpcs": [ + "./vendor/bin/phpcs" + ], + "lint:phpstan": [ + "./vendor/bin/phpstan analyse" + ], + "test:coverage": [ + "./vendor/bin/pest --log-junit=junit.xml --coverage --coverage-html=tests/coverage --coverage-clover=coverage.xml" + ] + }, + "license": [ + "proprietary" + ], + "authors": [ + { + "name": "LDC Digital", + "email": "digital@ldc.com" + } + ], + "description": "Create sitemap.xml", + "keywords": [ + "laravel", + "sitemap" + ] }, { "name": "uwil/storage-laravel", @@ -17503,5 +17488,5 @@ "php": "^8.5" }, "platform-dev": {}, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.11.0" } diff --git a/config/refresh-sitemap.php b/config/refresh-sitemap.php deleted file mode 100644 index 4e97a901..00000000 --- a/config/refresh-sitemap.php +++ /dev/null @@ -1,118 +0,0 @@ - [ - '/login', - '/bo', - '/activer', - '/reinitialiser-mdp', - '/gammes-de-produits', - '/gamme-de-produits', - // Hack ignore laravel debug bar. - '/_debugbar', - // Ignore ignition route. - '_ignition/health-check', - // Ignore ignition route. - '_ignition/scripts/{script}', - // Ignore ignition route. - '_ignition/styles/{style}', - ], - - /** - * This table is needed to resolve models matching - * routes - * - * it has to be filled like following - * - * 'products.meat-type' => [ - * 'slugMeatType' => [MeatTypes::class, 'slug'] - * ], - * 'kitchen-side.health-nutrition.balanced-menu.menu' => [ - * 'type' => [BalancedMenuType::class, 'type'] - * ] - * - * The index is the complete route name, the array content is an array - * within index is the argument name with its model class. - * This will allow the generator to generate a route for each of the models - * in this table - */ - 'routesBinder' => [], - - /** - * You can put route conditions here - * These will be used to decide whether the route should appear - * in the sitemap or not - * - * These are called in Eloquent where - * - * example - * - * 'queryConditions' => [ - * 'status' => true, - * 'ocbStatus' => EleveurOcbStatus::yes()->value, - * 'star_moment' => true - * ] - */ - 'queryConditions' => [], - - /** - * The default route frequency to use with sitemap generator - */ - 'routeDefaultFrequency' => Url::CHANGE_FREQUENCY_DAILY, - - /** - * The default route priority to use with sitemap generator - * - * priority should be a number between 0 and 1 - * https://www.sitemaps.org/protocol.html - */ - 'routeDefaultPriority' => 0.5, - - /** - * Frequencies for routes - * use the full or partial route name as index - * and a frequency within \Spatie\Sitemap\Tags\Url constants - */ - 'routeFrequencies' => [], - - /** - * Priorities for routes - * use the full or partial route name as index - * and a priority number between 0 and 1 - */ - 'routePriorities' => [], - - /** - * Enable or disable schedule for the job - * If set to true the sitemap generator will be run - * using the 'cron' instruction - */ - 'schedule' => true, - - /** - * If you want to set specific - * instruction for when to schedule job - * you can set this with a cron instruction - * You can generate one using https://crontab.guru/ - * https://laravel.com/docs/8.x/scheduling#schedule-frequency-options - * - * schedule must be set to true - * - * Default is every day at 15:45 - */ - 'cron' => '45 15 * * *', -]; diff --git a/config/sitemap-generator.php b/config/sitemap-generator.php new file mode 100644 index 00000000..8fcca003 --- /dev/null +++ b/config/sitemap-generator.php @@ -0,0 +1,100 @@ + [ + * 'homepage', + * ], + */ + 'single_pages' => [ + 'fo.pages.home', + 'fo.pages.terms', + 'fo.pages.contact', + 'fo.pages.privacy', + 'fo.pages.faq', + 'fo.pages.legal-notice', + 'fo.products.index', + ], + + /** + * Model namespaces with filters + * + * Ex: (model_filters & relation_filters are not necessaries) + * 'cruds' => [ + * [ + * 'model' => 'App\Models\Product', + * 'model_filters' => [ + * ['published', '=', true] + * ], + * 'relation_filters' => [ + * 'range' => fn(Builder $q) => $q->where('status', true), + * ], + * 'allow_null_relation' => ['range'], + * ], + * [ + * 'model' => 'App\Models\Article', + * ] + * ], + */ + 'cruds' => [ + [ + 'model' => Product::class, + 'model_filters' => [ + ['status', '=', true], + ], + 'relation_filters' => [ + 'range' => fn (Builder $q) => $q->where('status', true), + ], + ], + ], + + /** + * Enable or disable schedule for the job + * If set to true the sitemap generator will be run + * using the 'cron' instruction + */ + 'schedule' => true, + + /** + * If you want to set specific + * instruction for when to schedule job + * you can set this with a cron instruction + * You can generate one using https://crontab.guru/ + * + * schedule must be set to true + * + * Default is every day at 15:45 + */ + 'cron' => '45 15 * * *', + + /** + * All supported locales in the project. + * When used with mcamara/laravel-localization, you can get the values from the package config : + * 'supported_locales' => array_keys(config('laravellocalization.supportedLocales', ['fr' => "Fr"])) + */ + 'supported_locales' => ['fr'], + + /** + * The location where the sitemap file should be generated. + */ + 'output' => [ + 'storage_disk' => 's3-public', + 'path' => 'sitemap.xml', + ], + + /** + * The route localizer strategy to use. + * Supported: 'default', 'mcamara', or a custom class implementing RouteLocalizerInterface. + */ + 'localizer' => 'default', +]; diff --git a/public/sitemap.xml b/public/sitemap.xml deleted file mode 100644 index efc06382..00000000 --- a/public/sitemap.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - https://www.laboutiquedecocotte.fr/ - monthly - 1.0 - - - https://www.laboutiquedecocotte.fr/contactez-nous - - - https://www.laboutiquedecocotte.fr/mentions-legales - - - https://www.laboutiquedecocotte.fr/faq - - - https://www.laboutiquedecocotte.fr/cgv - - - https://www.laboutiquedecocotte.fr/charte-de-confidentialite - - \ No newline at end of file