Compare commits

...
Sign in to create a new pull request.

4 commits

Author SHA1 Message Date
Jérémy Munsch
efba1910dc
bump ldc/sitemap-generator to 1.0.3 2023-08-11 16:42:28 +02:00
Jérémy Munsch
229ca43cdf
Composer update for security fix 2023-08-11 14:51:50 +02:00
Jérémy Munsch
01391a8ca5
REmove kwaadpepper/refresh-sitemap 2023-08-11 13:51:46 +02:00
Jérémy Munsch
3e3432b97e
Ajout du nouveau package SiteMap generator sans JS 2023-08-11 13:50:59 +02:00
4 changed files with 1334 additions and 1039 deletions

View file

@ -0,0 +1,37 @@
<?php
namespace App\Lib;
use App\Enums\Advices\AdviceTypeEnum;
use App\Models\Advice;
use App\Models\Product;
use LDC\SitemapGenerator\Lib\Sitemap;
class CompleteSitemapWith
{
/**
* Use this method to append a list of links to the sitemap
*
* * Please call $sitemap->mergeUrls to append url for any specific route name.
*
* @param \LDC\SitemapGenerator\Lib\Sitemap $sitemap
* @return void
*/
public static function append(Sitemap $sitemap): void
{
// * Ajouts des éléments qui sont affichés en random
$sitemap->mergeUrls(Product::query()->where('status', true)->pluck('slug')->transform(function (string $slug) {
return \route('products.show', $slug);
}));
$sitemap->mergeUrls(Advice::query()
->where('status', true)->where('type', AdviceTypeEnum::recipes())
->pluck('slug')->transform(function (string $slug) {
return \route('recipes.show', $slug);
}));
$sitemap->mergeUrls(Advice::query()
->where('status', true)->where('type', AdviceTypeEnum::tips())
->pluck('slug')->transform(function (string $slug) {
return \route('tips.show', $slug);
}));
}
}

View file

@ -16,10 +16,10 @@
"guzzlehttp/guzzle": "^7.0.1", "guzzlehttp/guzzle": "^7.0.1",
"kaishiyoku/laravel-color-validation": "^1.6", "kaishiyoku/laravel-color-validation": "^1.6",
"kwaadpepper/image-resizer": "^0.1.2", "kwaadpepper/image-resizer": "^0.1.2",
"kwaadpepper/refresh-sitemap": "^1.0",
"laravel/framework": "^8.83", "laravel/framework": "^8.83",
"laravel/tinker": "^2.5", "laravel/tinker": "^2.5",
"laravel/ui": "^3.4", "laravel/ui": "^3.4",
"ldc/sitemap-generator": "^1.0",
"ldc/web-admin-secure-laravel": "^1.0", "ldc/web-admin-secure-laravel": "^1.0",
"ldc/web-status-checker-laravel": "^1.0", "ldc/web-status-checker-laravel": "^1.0",
"mews/purifier": "^3.3", "mews/purifier": "^3.3",
@ -77,7 +77,8 @@
"preferred-install": "dist", "preferred-install": "dist",
"sort-packages": true, "sort-packages": true,
"allow-plugins": { "allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true "dealerdirect/phpcodesniffer-composer-installer": true,
"php-http/discovery": true
}, },
"gitlab-domains": [ "gitlab-domains": [
"lab.s-web.fr" "lab.s-web.fr"

2249
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
<?php <?php
use App\Models\Range; use App\Lib\CompleteSitemapWith;
use Spatie\Sitemap\Tags\Url; use Spatie\Sitemap\Tags\Url;
return [ return [
@ -12,56 +12,30 @@ return [
* *
* For example, if you want to ignore all routes * For example, if you want to ignore all routes
* of the backoffice group * of the backoffice group
* just add '/backoffice' into this table * just add 'bo' into this table
*
* * Note that this can take route names (both partially or full)
* * You can use a wild card just as for routeIs method
*/ */
'ignoreRoutes' => [ 'ignoreRoutes' => [
'/bo', 'back.*',
'/produits/gamme/{range}/ajax' 'bo.*',
'front.frame',
'cspReportUri',
], ],
/** /**
* This table is needed to resolve models matching * This should be filled using the command `php artisan sitemap:install-completer`
* routes
* *
* it has to be filled like following * 'completeWith' => [CLASS, 'METHOD'],
* eg : 'completeWith' => [CompleteSitemapWith::class, 'append'],
* *
* 'products.meat-type' => [ * This should point to a static method which will be called with the folowing parameter
* 'slugMeatType' => [MeatTypes::class, 'slug'] * (LDC\SitemapGenerator\Lib\Sitemap $sitemap)
* ],
* 'kitchen-side.health-nutrition.balanced-menu.menu' => [
* 'type' => [BalancedMenuType::class, 'type']
* ]
* *
* The index is the complete route name, the array content is an array * You may now use $sitemap->addLinks('route.myRouteName', string[] $links)
* 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' => [ 'completeWith' => [CompleteSitemapWith::class, 'append'],
'products.range-products' => [
'range' => [Range::class, 'slug']
],
],
/**
* 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' => [
'status' => true,
],
/** /**
* The default route frequency to use with sitemap generator * The default route frequency to use with sitemap generator
@ -80,13 +54,21 @@ return [
* Frequencies for routes * Frequencies for routes
* use the full or partial route name as index * use the full or partial route name as index
* and a frequency within \Spatie\Sitemap\Tags\Url constants * and a frequency within \Spatie\Sitemap\Tags\Url constants
*
* eg: 'engagments.*' => \Spatie\Sitemap\Tags\Url::CHANGE_FREQUENCY_HOURLY
*/ */
'routeFrequencies' => [], 'routeFrequencies' => [
'news.show' => Url::CHANGE_FREQUENCY_HOURLY
],
/** /**
* Priorities for routes * Priorities for routes
* use the full or partial route name as index * use the full or partial route name as index
* and a priority number between 0 and 1 * and a priority in 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, and 0.0.
*
* 1.0 is the Highest
*
* eg: 'engagments.*' => 1.0
*/ */
'routePriorities' => [], 'routePriorities' => [],
@ -102,11 +84,19 @@ return [
* instruction for when to schedule job * instruction for when to schedule job
* you can set this with a cron instruction * you can set this with a cron instruction
* You can generate one using https://crontab.guru/ * You can generate one using https://crontab.guru/
* https://laravel.com/docs/8.x/scheduling#schedule-frequency-options
* *
* schedule must be set to true * schedule must be set to true
* *
* Default is every day at 15:45 * Default is every day at 15:45
*/ */
'cron' => '45 15 * * *' 'cron' => '45 15 * * *',
/**
* The sitemap generator can execute JavaScript on each page so it will
* discover links that are generated by your JS scripts. This feature
* is powered by headless Chrome.
*
* ! This needs pupetter installed with npm : npm i puppeteer (not to put in dev dependencies)
*/
'executeJavascript' => false,
]; ];