move into sonardesk
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
return ['name' => 'Sitemap'];
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sitemap\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Blog\Models\Blog;
|
||||
use Modules\News\Models\News;
|
||||
use Modules\Pages\Models\Page;
|
||||
|
||||
final class SitemapController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
{
|
||||
$urls = collect();
|
||||
$urls->push(['loc' => url('/'), 'updated_at' => now()]);
|
||||
Page::query()->where('status', 'published')->get()->each(fn ($r) => $urls->push(['loc' => route('pages.public.show', $r->slug), 'updated_at' => $r->updated_at]));
|
||||
Blog::published()->get()->each(fn ($r) => $urls->push(['loc' => route('blog.public.show', $r->slug), 'updated_at' => $r->updated_at]));
|
||||
News::published()->get()->each(fn ($r) => $urls->push(['loc' => route('news.public.show', $r->slug), 'updated_at' => $r->updated_at]));
|
||||
|
||||
return response()->view('sitemap::index', compact('urls'))->header('Content-Type', 'application/xml; charset=UTF-8');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sitemap\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
final class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
Route::middleware('web')->group(module_path('Sitemap', 'Routes/web.php'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sitemap\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
final class SitemapServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->mergeConfigFrom(module_path('Sitemap', 'Config/config.php'), 'sitemap');
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
$this->loadMigrationsFrom(module_path('Sitemap', 'Database/Migrations'));
|
||||
$this->loadViewsFrom(module_path('Sitemap', 'Resources/views'), 'sitemap');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{!! '<?xml version="1.0" encoding="UTF-8"?>' !!}
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">@foreach($urls as $url)
|
||||
<url>
|
||||
<loc>{{ $url['loc'] }}</loc>
|
||||
<lastmod>{{ $url['updated_at']->toAtomString() }}</lastmod>
|
||||
</url>
|
||||
@endforeach</urlset>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Sitemap\Http\Controllers\SitemapController;
|
||||
|
||||
Route::get('/sitemap.xml', [SitemapController::class, 'index'])->name('sitemap.index');
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sitemap\Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
final class ModuleBootTest extends TestCase
|
||||
{
|
||||
public function test_module_configuration_is_available(): void
|
||||
{
|
||||
$this->assertSame('Sitemap', config('sitemap.name'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "Sitemap",
|
||||
"alias": "sitemap",
|
||||
"version": "1.0.0",
|
||||
"description": "Sitemap publishing module.",
|
||||
"keywords": ["publishing", "sitemap"],
|
||||
"priority": 30,
|
||||
"providers": ["Modules\\Sitemap\\Providers\\SitemapServiceProvider"],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": ["Core", "Administration"]
|
||||
}
|
||||
Reference in New Issue
Block a user