Sitemap generator with default sitemap

This commit is contained in:
2024-04-15 15:42:59 +02:00
parent 5488559bc9
commit 1427c0d9cc
2 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Spatie\Sitemap\SitemapGenerator;
use Spatie\Crawler\Crawler;
use Spatie\Sitemap\Tags\Url;
class IkeaSitemap extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ikea:sitemap {path}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$path = $this->argument('path');
SitemapGenerator::create('https://prices.soson.eu')
->configureCrawler(function (Crawler $crawler) {
$crawler->ignoreRobots();
})
->getSitemap()
->add(Url::create('https://prices.soson.eu/about/')->setPriority(0.7))
->add(Url::create('https://prices.soson.eu/exchange/')->setPriority(0.5))
->add(Url::create('https://prices.soson.eu/doc/')->setPriority(0.8))
->writeToFile($path);
return 0;
}
}

23
public/sitemap.xml Normal file
View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>https://prices.soson.eu/</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://prices.soson.eu/about/</loc>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://prices.soson.eu/exchange/</loc>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://prices.soson.eu/doc/</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>