generated from rapidez/package-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59e7932
commit f82c36e
Showing
11 changed files
with
223 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Sitemap Storage Settings | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Configure where the sitemap files should be stored. The disk should be | ||
| configured in your application's filesystems.php config file. | ||
| For public access, use the 'public' disk. | ||
| | ||
*/ | ||
'disk' => 'public', | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Sitemap Base Path | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The base path where sitemap files will be stored on the specified disk. | ||
| Store-specific sitemaps will be stored in {path}/{store_id}/sitemap.xml | ||
| | ||
*/ | ||
'path' => 'rapidez-sitemaps', | ||
]; |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Rapidez\Sitemap\Actions; | ||
|
||
class GenerateSitemapAction | ||
{ | ||
public function createSitemapIndex(array $sitemapIndexes): string | ||
{ | ||
$sitemap = '<?xml version="1.0" encoding="UTF-8"?>'; | ||
$sitemap .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | ||
|
||
foreach ($sitemapIndexes as $sitemapIndex) { | ||
$sitemap .= $this->addUrl($sitemapIndex['loc'] ?? null, $sitemapIndex['lastmod'] ?? null); | ||
} | ||
|
||
$sitemap .= '</sitemapindex>'; | ||
|
||
return $sitemap; | ||
} | ||
|
||
public function createSitemapUrlset(array $sitemapUrls): string | ||
{ | ||
$sitemap = '<?xml version="1.0" encoding="UTF-8"?>'; | ||
$sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">'; | ||
|
||
foreach ($sitemapUrls as $sitemapUrl) { | ||
$sitemap .= $this->addUrl($sitemapUrl['loc'] ?? null, $sitemapUrl['lastmod'] ?? null, false); | ||
} | ||
|
||
$sitemap .= '</urlset>'; | ||
|
||
return $sitemap; | ||
} | ||
|
||
public function addUrl(?string $url = null, ?string $lastMod = null, bool $isIndex = true): string | ||
{ | ||
$sitemap = $isIndex ? '<sitemap>' : '<url>'; | ||
|
||
if ($url) { | ||
$sitemap .= '<loc>'.url($url).'</loc>'; | ||
} | ||
|
||
if ($lastMod) { | ||
$sitemap .= '<lastmod>'.substr($lastMod, 0, 10).'</lastmod>'; | ||
} | ||
|
||
$sitemap .= $isIndex ? '</sitemap>' : '</url>'; | ||
|
||
return $sitemap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Rapidez\Sitemap\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Rapidez\Core\Facades\Rapidez; | ||
use Rapidez\Sitemap\Jobs\GenerateSitemapJob; | ||
use TorMorten\Eventy\Facades\Eventy; | ||
|
||
class GenerateSitemap extends Command | ||
{ | ||
protected $signature = 'rapidez:sitemap:generate'; | ||
|
||
protected $description = 'Generate the sitemap and run sitemap generate action'; | ||
|
||
public function handle(): int | ||
{ | ||
Eventy::action('rapidez.sitemap.generate'); | ||
|
||
foreach (Rapidez::getStores() ?: [] as $store) { | ||
GenerateSitemapJob::dispatch($store['store_id']); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Rapidez\Sitemap\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Storage; | ||
use Rapidez\Core\Facades\Rapidez; | ||
use Rapidez\Sitemap\Actions\GenerateSitemapAction; | ||
use Rapidez\Sitemap\Models\Sitemap; | ||
use TorMorten\Eventy\Facades\Eventy; | ||
|
||
class GenerateSitemapJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable; | ||
|
||
public function __construct(protected int $storeId) {} | ||
|
||
public function handle(GenerateSitemapAction $action): void | ||
{ | ||
Rapidez::setStore($this->storeId); | ||
|
||
// Get sitemaps for the store | ||
$sitemaps = Sitemap::getByStoreId($this->storeId); | ||
|
||
// Allow additional sitemaps via Eventy filter | ||
/** @phpstan-ignore-next-line */ | ||
$sitemaps = Eventy::filter('rapidez.sitemap.'.$this->storeId, $sitemaps); | ||
|
||
// Generate sitemap content | ||
$sitemapContent = $action->createSitemapIndex((array) $sitemaps); | ||
|
||
// Get storage disk and path from config | ||
$disk = Storage::disk(config('rapidez-sitemap.disk', 'public')); | ||
$basePath = trim(config('rapidez-sitemap.path', 'rapidez-sitemaps'), '/'); | ||
|
||
// Generate store-specific path | ||
$storePath = $basePath.'/'.$this->storeId; | ||
|
||
// Ensure directory exists and save sitemap | ||
$disk->put($storePath.'/sitemap.xml', $sitemapContent); | ||
|
||
// Clear cache | ||
Cache::forget('rapidez.sitemaps.'.$this->storeId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters