diff --git a/.gitignore b/.gitignore index 62f0130..7a8d494 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ /public/hot /public/storage /public/ -!/public/sitemap.xml +/public/sitemap.xml /storage/*.key /vendor .env diff --git a/app/Lib/Sitemap/PrefixedRouteLocalizer.php b/app/Lib/Sitemap/PrefixedRouteLocalizer.php new file mode 100644 index 0000000..97073bf --- /dev/null +++ b/app/Lib/Sitemap/PrefixedRouteLocalizer.php @@ -0,0 +1,33 @@ +hasMany(Product::class); } + + /** + * Return the localized URL for a given locale. + */ + public function getLocalizedUrl(string $locale): string + { + $routeName = $locale === 'fr' ? 'gammes.show' : $locale . '.gammes.show'; + + return route($routeName, [ + 'gammeSlug' => $this->getTranslation('slug', $locale), + ]); + } + + /** + * toSitemapTag method + * + * @return Url|string|array + */ + public function toSitemapTag(): Url | string | array + { + $model = $this; + $route = 'gammes.show'; + $params = ['publishedProduct' => $model]; + return SitemapHelper::generateUrl($route, $params, $model); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 12b776d..660e974 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -6,9 +6,12 @@ use App\Lib\Utils; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\File; +use Spatie\Sitemap\Tags\Url; use Spatie\Translatable\HasTranslations; +use Uwil\SitemapGenerator\Contracts\Sitemapable; +use Uwil\SitemapGenerator\SitemapHelper; -class Product extends Model +class Product extends Model implements Sitemapable { use HasFactory; use HasTranslations; @@ -105,4 +108,30 @@ class Product extends Model { return $this->belongsTo(Gamme::class); } + + /** + * Return the localized URL for a given locale. + */ + public function getLocalizedUrl(string $locale): string + { + $routeName = $locale === 'fr' ? 'product.show' : $locale . '.product.show'; + + return route($routeName, [ + 'gammeSlug' => $this->gamme->getTranslation('slug', $locale), + 'productSlug' => $this->getTranslation('slug', $locale), + ]); + } + + /** + * toSitemapTag method + * + * @return Url|string|array + */ + public function toSitemapTag(): Url | string | array + { + $model = $this; + $route = 'gammes.show'; + $params = ['publishedProduct' => $model]; + return SitemapHelper::generateUrl($route, $params, $model); + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index f3cedc0..61b86c3 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,11 +2,23 @@ namespace App\Providers; +use App\Lib\Sitemap\PrefixedRouteLocalizer; use Illuminate\Support\Facades\URL; use Illuminate\Support\ServiceProvider; +use Uwil\SitemapGenerator\Localizers\DefaultRouteLocalizer; class AppServiceProvider extends ServiceProvider { + /** + * Register any application services. + * + * @return void + */ + public function register() + { + $this->app->bind(DefaultRouteLocalizer::class, PrefixedRouteLocalizer::class); + } + /** * Bootstrap any application services. * diff --git a/composer.json b/composer.json index 7c0bc11..e5e204a 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "mews/purifier": "^3.3", "sentry/sentry-laravel": "^4.1", "spatie/laravel-translatable": "^6.0", - "uwil/laravel-k8s": "*" + "uwil/laravel-k8s": "*", + "uwil/sitemap-generator": "^8.0" }, "require-dev": { "driftingly/rector-laravel": "^2.5", diff --git a/composer.lock b/composer.lock index 5bdc0b2..4298515 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": "ffcb3d9c1af884d4bf7da3051c30429b", + "content-hash": "34983c0189d28a600f3bcbb5f9b6c104", "packages": [ { "name": "brick/math", @@ -4281,6 +4281,86 @@ ], "time": "2026-10-08T12:31:48+00:00" }, + { + "name": "spatie/crawler", + "version": "9.4.2", + "source": { + "type": "git", + "url": "https://github.com/spatie/crawler.git", + "reference": "937bcf5786e66bca20da50db004f6d1443e81418" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/crawler/zipball/937bcf5786e66bca20da50db004f6d1443e81418", + "reference": "937bcf5786e66bca20da50db004f6d1443e81418", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^7.8.2 || ^8.0", + "guzzlehttp/psr7": "^2.6.3 || ^3.0", + "php": "^8.4", + "psr/http-client": "^1.0", + "spatie/robots-txt": "^2.0", + "symfony/css-selector": "^7.0|^8.0", + "symfony/dom-crawler": "^7.0|^8.0" + }, + "require-dev": { + "pestphp/pest": "^4.0", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "spatie/invade": "^2.1", + "spatie/ray": "^1.37" + }, + "suggest": { + "spatie/browsershot": "Required for JavaScript rendering with BrowsershotRenderer (^5.0.5)" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-v9": "9.x-dev" + } + }, + "autoload": { + "psr-4": { + "Spatie\\Crawler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be" + } + ], + "description": "Crawl all internal links found on a website", + "homepage": "https://github.com/spatie/crawler", + "keywords": [ + "crawler", + "link", + "spatie", + "website" + ], + "support": { + "issues": "https://github.com/spatie/crawler/issues", + "source": "https://github.com/spatie/crawler/tree/9.4.2" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2026-08-07T07:19:51+00:00" + }, { "name": "spatie/laravel-package-tools", "version": "1.93.3", @@ -4342,6 +4422,80 @@ ], "time": "2026-09-28T07:16:50+00:00" }, + { + "name": "spatie/laravel-sitemap", + "version": "8.2.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-sitemap.git", + "reference": "51f52030ab22abf5e95ed037fea5f8073114e784" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-sitemap/zipball/51f52030ab22abf5e95ed037fea5f8073114e784", + "reference": "51f52030ab22abf5e95ed037fea5f8073114e784", + "shasum": "" + }, + "require": { + "illuminate/support": "^12.0|^13.0", + "nesbot/carbon": "^2.71|^3.0", + "php": "^8.4", + "spatie/crawler": "^9.0", + "spatie/laravel-package-tools": "^1.16.1" + }, + "require-dev": { + "larastan/larastan": "^3.0", + "laravel/pint": "^1.13", + "orchestra/testbench": "^10.0|^11.0", + "pestphp/pest": "^4.0", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "spatie/pest-plugin-snapshots": "^2.1", + "spatie/temporary-directory": "^2.2" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\Sitemap\\SitemapServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\Sitemap\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Create and generate sitemaps with ease", + "homepage": "https://github.com/spatie/laravel-sitemap", + "keywords": [ + "laravel-sitemap", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/laravel-sitemap/tree/8.2.0" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + } + ], + "time": "2026-06-24T07:59:14+00:00" + }, { "name": "spatie/laravel-translatable", "version": "6.15.0", @@ -4426,6 +4580,66 @@ ], "time": "2026-10-19T00:09:37+00:00" }, + { + "name": "spatie/robots-txt", + "version": "2.5.5", + "source": { + "type": "git", + "url": "https://github.com/spatie/robots-txt.git", + "reference": "b451e56b67ab9c852d354de75e88e3b797729b9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/robots-txt/zipball/b451e56b67ab9c852d354de75e88e3b797729b9e", + "reference": "b451e56b67ab9c852d354de75e88e3b797729b9e", + "shasum": "" + }, + "require": { + "php": "^8.1" + }, + "require-dev": { + "phpunit/phpunit": "^11.5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\Robots\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brent Roose", + "email": "brent@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Determine if a page may be crawled from robots.txt and robots meta tags", + "homepage": "https://github.com/spatie/robots-txt", + "keywords": [ + "robots-txt", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/robots-txt/issues", + "source": "https://github.com/spatie/robots-txt/tree/2.5.5" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2026-10-17T08:57:09+00:00" + }, { "name": "symfony/clock", "version": "v8.1.9", @@ -4743,6 +4957,76 @@ ], "time": "2026-06-05T06:23:12+00:00" }, + { + "name": "symfony/dom-crawler", + "version": "v8.1.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/dom-crawler.git", + "reference": "94f70e1b2e5b7b8f8618871fd9eaad3e39e9f03d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/94f70e1b2e5b7b8f8618871fd9eaad3e39e9f03d", + "reference": "94f70e1b2e5b7b8f8618871fd9eaad3e39e9f03d", + "shasum": "" + }, + "require": { + "php": ">=8.4.1", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.0" + }, + "require-dev": { + "symfony/css-selector": "^7.4|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\DomCrawler\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Eases DOM navigation for HTML and XML documents", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/dom-crawler/tree/v8.1.5" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-08-21T17:47:34+00:00" + }, { "name": "symfony/error-handler", "version": "v8.1.8", @@ -7275,6 +7559,105 @@ "issues": "https://lab.s-web.fr/ldc-web/projets/laravel-k8s/-/issues" } }, + { + "name": "uwil/sitemap-generator", + "version": "8.0.1", + "source": { + "type": "git", + "url": "git@lab.s-web.fr:ldc-web/projets/sitemap-generator.git", + "reference": "bab3583abd3be0b780df9ca1540b2207b587e18f" + }, + "dist": { + "type": "zip", + "url": "https://lab.s-web.fr/api/v4/projects/108/packages/composer/archives/uwil/sitemap-generator.zip?sha=bab3583abd3be0b780df9ca1540b2207b587e18f", + "reference": "bab3583abd3be0b780df9ca1540b2207b587e18f", + "shasum": "" + }, + "require": { + "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": { + "providers": [ + "Uwil\\SitemapGenerator\\SitemapGeneratorServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Uwil\\SitemapGenerator\\": "src/" + } + }, + "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": "vlucas/phpdotenv", "version": "v5.8.0", diff --git a/config/sitemap-generator.php b/config/sitemap-generator.php new file mode 100644 index 0000000..488448e --- /dev/null +++ b/config/sitemap-generator.php @@ -0,0 +1,99 @@ + [ + * 'homepage', + * ], + */ + 'single_pages' => [ + 'home', + 'wasup', + 'gammes.index', + 'news', + 'food', + 'cgu', + 'policy', + 'search', + 'contact', + ], + + /** + * 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' => 'App\Models\Gamme', + ], + [ + 'model' => 'App\Models\Product', + 'model_filters' => [ + ['is_published', '=', 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', 'en', 'es'], + + /** + * The location where the sitemap file should be generated. + */ + 'output' => [ + 'storage_disk' => '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 293e91c..0000000 --- a/public/sitemap.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - https://www.doux.com/ - monthly - 1.0 - - - https://www.doux.com/marque - - - https://www.doux.com/gammes - - - https://www.doux.com/actualites - - - https://www.doux.com/food-service - - - https://www.doux.com/mentions-legales - - - https://www.doux.com/charte-confidentialite - - - https://www.doux.com/contact - - - - https://www.doux.com/es/marca - - - https://www.doux.com/es/productos - - - https://www.doux.com/es/noticias - - - https://www.doux.com/es/food-service - - - https://www.doux.com/es/terminos-y-condiciones-de-uso - - - https://www.doux.com/es/polĂ­tica-de-privacidad - - - https://www.doux.com/es/contacto - - - - - https://www.doux.com/en/brand - - - https://www.doux.comen/en/products - - - https://www.doux.com/en/news - - - https://www.doux.com/en/food-service - - - https://www.doux.com/en/terms-and-conditions - - - https://www.doux.com/en/privacy-policy - - - https://www.doux.com/en/contact - - \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index aa1d920..a6c13df 100644 --- a/routes/web.php +++ b/routes/web.php @@ -114,60 +114,58 @@ Route::prefix('bo') } ); -if (!app()->runningInConsole()) { - $langs = ['en', 'es', '']; +$langs = ['en', 'es', '']; - foreach ($langs as $lang) { - Route::middleware(['front-end-globals']) - ->prefix($lang) - ->name($lang == '' ? '' : $lang . '.') - ->group( - function () use ($lang): void { - Route::get('/', [ControllersHomeController::class, 'index'])->name('home'); +foreach ($langs as $lang) { + Route::middleware(['front-end-globals']) + ->prefix($lang) + ->name($lang == '' ? '' : $lang . '.') + ->group( + function () use ($lang): void { + Route::get('/', [ControllersHomeController::class, 'index'])->name('home'); - Route::get( - '/' . Str::slug(Lang::get('urls.marque', [], $lang)), - [ControllersMarqueController::class, 'index'] - )->name('wasup'); - Route::get( - '/' . Str::slug(Lang::get('urls.gammes', [], $lang)), - [ControllersGammesController::class, 'index'] - )->name('gammes.index'); - Route::get( - '/' . Str::slug(Lang::get('urls.gamme', [], $lang)) . '/{gammeSlug:slug}', - [ControllersGammesController::class, 'show'] - )->name('gammes.show'); - Route::get( - '/' . Str::slug(Lang::get('urls.produit', [], $lang)) . '/{gammeSlug:slug}/{productSlug:slug}', - [ControllersProductsController::class, 'show'] - )->name('product.show'); - Route::get( - '/' . Str::slug(Lang::get('urls.news', [], $lang)), - [ControllersNewsController::class, 'index'] - )->name('news'); - Route::get( - '/' . Str::slug(Lang::get('urls.food-service', [], $lang)), - [ControllersFoodServiceController::class, 'index'] - )->name('food'); - Route::get( - '/' . Str::slug(Lang::get('urls.legals', [], $lang)), - [ControllersLegalsController::class, 'index'] - )->name('cgu'); - Route::get( - '/' . Str::slug(Lang::get('urls.policy', [], $lang)), - [ControllersPolicyController::class, 'index'] - )->name('policy'); - Route::get( - '/' . Str::slug(Lang::get('urls.search', [], $lang)), - [ControllersProductsController::class, 'search'] - )->name('search'); - // Classic. - Route::get( - '/' . Str::slug(Lang::get('urls.contact', [], $lang)), - [ControllersContactController::class, 'contact'] - )->name('contact'); - Route::post('/contact', [ControllersContactController::class, 'contactSubmit'])->name('contact.submit'); - } - ); - }//end foreach -}//end if + Route::get( + '/' . Str::slug(Lang::get('urls.marque', [], $lang)), + [ControllersMarqueController::class, 'index'] + )->name('wasup'); + Route::get( + '/' . Str::slug(Lang::get('urls.gammes', [], $lang)), + [ControllersGammesController::class, 'index'] + )->name('gammes.index'); + Route::get( + '/' . Str::slug(Lang::get('urls.gamme', [], $lang)) . '/{gammeSlug:slug}', + [ControllersGammesController::class, 'show'] + )->name('gammes.show'); + Route::get( + '/' . Str::slug(Lang::get('urls.produit', [], $lang)) . '/{gammeSlug:slug}/{productSlug:slug}', + [ControllersProductsController::class, 'show'] + )->name('product.show'); + Route::get( + '/' . Str::slug(Lang::get('urls.news', [], $lang)), + [ControllersNewsController::class, 'index'] + )->name('news'); + Route::get( + '/' . Str::slug(Lang::get('urls.food-service', [], $lang)), + [ControllersFoodServiceController::class, 'index'] + )->name('food'); + Route::get( + '/' . Str::slug(Lang::get('urls.legals', [], $lang)), + [ControllersLegalsController::class, 'index'] + )->name('cgu'); + Route::get( + '/' . Str::slug(Lang::get('urls.policy', [], $lang)), + [ControllersPolicyController::class, 'index'] + )->name('policy'); + Route::get( + '/' . Str::slug(Lang::get('urls.search', [], $lang)), + [ControllersProductsController::class, 'search'] + )->name('search'); + // Classic. + Route::get( + '/' . Str::slug(Lang::get('urls.contact', [], $lang)), + [ControllersContactController::class, 'contact'] + )->name('contact'); + Route::post('/contact', [ControllersContactController::class, 'contactSubmit'])->name('contact.submit'); + } + ); +}//end foreach