Skip to content

Commit

Permalink
Merge pull request bagisto#10020 from devansh-webkul/sitemap-enhancement
Browse files Browse the repository at this point in the history
feat: sitemap enhancement
  • Loading branch information
jitendra-webkul authored Oct 18, 2024
2 parents fcd8218 + 4c033c5 commit 3ae62e9
Show file tree
Hide file tree
Showing 34 changed files with 2,504 additions and 117 deletions.
219 changes: 219 additions & 0 deletions packages/Webkul/Admin/src/Config/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,225 @@
'locale_based' => true,
],
],
], [
'key' => 'general.sitemap',
'name' => 'admin::app.configuration.index.general.sitemap.title',
'info' => 'admin::app.configuration.index.general.sitemap.info',
'icon' => 'settings/store.svg',
'sort' => 3,
], [
'key' => 'general.sitemap.settings',
'name' => 'admin::app.configuration.index.general.sitemap.settings.title',
'info' => 'admin::app.configuration.index.general.sitemap.settings.info',
'sort' => 1,
'fields' => [
[
'name' => 'enabled',
'title' => 'admin::app.configuration.index.general.sitemap.settings.enabled',
'type' => 'boolean',
'default' => 1,
'channel_based' => true,
],
],
], [
'key' => 'general.sitemap.file_limits',
'name' => 'admin::app.configuration.index.general.sitemap.file-limits.title',
'info' => 'admin::app.configuration.index.general.sitemap.file-limits.info',
'sort' => 1,
'fields' => [
[
'name' => 'max_url_per_file',
'title' => 'admin::app.configuration.index.general.sitemap.file-limits.max-url-per-file',
'type' => 'text',
'default' => 50000,
'validation' => 'integer|min:1',
'channel_based' => true,
],
],
], [
'key' => 'general.sitemap.store_url',
'name' => 'admin::app.configuration.index.general.sitemap.store-url.title',
'info' => 'admin::app.configuration.index.general.sitemap.store-url.info',
'sort' => 1,
'fields' => [
[
'name' => 'frequency',
'title' => 'admin::app.configuration.index.general.sitemap.store-url.frequency.title',
'type' => 'select',
'options' => [
[
'title' => 'admin::app.configuration.index.general.sitemap.store-url.frequency.options.never',
'value' => 'never',
], [
'title' => 'admin::app.configuration.index.general.sitemap.store-url.frequency.options.yearly',
'value' => 'yearly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.store-url.frequency.options.monthly',
'value' => 'monthly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.store-url.frequency.options.weekly',
'value' => 'weekly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.store-url.frequency.options.daily',
'value' => 'daily',
], [
'title' => 'admin::app.configuration.index.general.sitemap.store-url.frequency.options.hourly',
'value' => 'hourly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.store-url.frequency.options.always',
'value' => 'always',
],
],
'default' => 'daily',
'channel_based' => true,
],
[
'name' => 'priority',
'title' => 'admin::app.configuration.index.general.sitemap.store-url.priority',
'type' => 'text',
'validation' => 'decimal:1|min:0|max:1',
'default' => '0.8',
'channel_based' => true,
],
],
], [
'key' => 'general.sitemap.categories',
'name' => 'admin::app.configuration.index.general.sitemap.categories.title',
'info' => 'admin::app.configuration.index.general.sitemap.categories.info',
'sort' => 1,
'fields' => [
[
'name' => 'frequency',
'title' => 'admin::app.configuration.index.general.sitemap.categories.frequency.title',
'type' => 'select',
'options' => [
[
'title' => 'admin::app.configuration.index.general.sitemap.categories.frequency.options.never',
'value' => 'never',
], [
'title' => 'admin::app.configuration.index.general.sitemap.categories.frequency.options.yearly',
'value' => 'yearly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.categories.frequency.options.monthly',
'value' => 'monthly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.categories.frequency.options.weekly',
'value' => 'weekly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.categories.frequency.options.daily',
'value' => 'daily',
], [
'title' => 'admin::app.configuration.index.general.sitemap.categories.frequency.options.hourly',
'value' => 'hourly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.categories.frequency.options.always',
'value' => 'always',
],
],
'default' => 'daily',
'channel_based' => true,
],
[
'name' => 'priority',
'title' => 'admin::app.configuration.index.general.sitemap.categories.priority',
'type' => 'text',
'validation' => 'decimal:1|min:0|max:1',
'default' => '0.8',
'channel_based' => true,
],
],
], [
'key' => 'general.sitemap.products',
'name' => 'admin::app.configuration.index.general.sitemap.products.title',
'info' => 'admin::app.configuration.index.general.sitemap.products.info',
'sort' => 1,
'fields' => [
[
'name' => 'frequency',
'title' => 'admin::app.configuration.index.general.sitemap.products.frequency.title',
'type' => 'select',
'options' => [
[
'title' => 'admin::app.configuration.index.general.sitemap.products.frequency.options.never',
'value' => 'never',
], [
'title' => 'admin::app.configuration.index.general.sitemap.products.frequency.options.yearly',
'value' => 'yearly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.products.frequency.options.monthly',
'value' => 'monthly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.products.frequency.options.weekly',
'value' => 'weekly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.products.frequency.options.daily',
'value' => 'daily',
], [
'title' => 'admin::app.configuration.index.general.sitemap.products.frequency.options.hourly',
'value' => 'hourly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.products.frequency.options.always',
'value' => 'always',
],
],
'default' => 'daily',
'channel_based' => true,
],
[
'name' => 'priority',
'title' => 'admin::app.configuration.index.general.sitemap.products.priority',
'type' => 'text',
'validation' => 'decimal:1|min:0|max:1',
'default' => '0.8',
'channel_based' => true,
],
],
], [
'key' => 'general.sitemap.cms',
'name' => 'admin::app.configuration.index.general.sitemap.cms.title',
'info' => 'admin::app.configuration.index.general.sitemap.cms.info',
'sort' => 1,
'fields' => [
[
'name' => 'frequency',
'title' => 'admin::app.configuration.index.general.sitemap.cms.frequency.title',
'type' => 'select',
'options' => [
[
'title' => 'admin::app.configuration.index.general.sitemap.cms.frequency.options.never',
'value' => 'never',
], [
'title' => 'admin::app.configuration.index.general.sitemap.cms.frequency.options.yearly',
'value' => 'yearly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.cms.frequency.options.monthly',
'value' => 'monthly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.cms.frequency.options.weekly',
'value' => 'weekly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.cms.frequency.options.daily',
'value' => 'daily',
], [
'title' => 'admin::app.configuration.index.general.sitemap.cms.frequency.options.hourly',
'value' => 'hourly',
], [
'title' => 'admin::app.configuration.index.general.sitemap.cms.frequency.options.always',
'value' => 'always',
],
],
'default' => 'daily',
'channel_based' => true,
],
[
'name' => 'priority',
'title' => 'admin::app.configuration.index.general.sitemap.cms.priority',
'type' => 'text',
'validation' => 'decimal:1|min:0|max:1',
'default' => '0.8',
'channel_based' => true,
],
],
],

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function prepareColumns()
'label' => trans('admin::app.marketing.search-seo.sitemaps.index.datagrid.link-for-google'),
'type' => 'string',
'closure' => function ($row) {
return Storage::url($row->path.'/'.$row->file_name);
return Storage::url(clean_path($row->path.'/'.$row->file_name));
},
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
use Webkul\Admin\DataGrids\Marketing\SearchSEO\SitemapDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Sitemap\Jobs\ProcessSitemap;
use Webkul\Sitemap\Repositories\SitemapRepository;

class SitemapController extends Controller
Expand Down Expand Up @@ -38,8 +38,8 @@ public function index()
public function store(): JsonResponse
{
$this->validate(request(), [
'file_name' => 'required',
'path' => 'required',
'file_name' => 'required|regex:/^[\w\-\.]+$/|ends_with:.xml',
'path' => 'required|starts_with:/|regex:/^(?!.*\/\/)[\w\-\.\/]+$/|ends_with:/',
]);

Event::dispatch('marketing.search_seo.sitemap.create.before');
Expand All @@ -49,6 +49,8 @@ public function store(): JsonResponse
'path',
]));

ProcessSitemap::dispatch($sitemap);

Event::dispatch('marketing.search_seo.sitemap.create.after', $sitemap);

return new JsonResponse([
Expand All @@ -66,8 +68,8 @@ public function update(): JsonResponse
$id = request()->id;

$this->validate(request(), [
'file_name' => 'required',
'path' => 'required',
'file_name' => 'required|regex:/^[\w\-\.]+$/|ends_with:.xml',
'path' => 'required|starts_with:/|regex:/^(?!.*\/\/)[\w\-\.\/]+$/|ends_with:/',
]);

Event::dispatch('marketing.search_seo.sitemap.update.before', $id);
Expand All @@ -77,6 +79,8 @@ public function update(): JsonResponse
'path',
]), $id);

ProcessSitemap::dispatch($sitemap);

Event::dispatch('marketing.search_seo.sitemap.update.after', $sitemap);

return new JsonResponse([
Expand All @@ -94,7 +98,7 @@ public function destroy($id)
{
$sitemap = $this->sitemapRepository->findOrFail($id);

Storage::delete($sitemap->path.'/'.$sitemap->file_name);
$sitemap->deleteFromStorage();

try {
Event::dispatch('marketing.search_seo.sitemap.delete.before', $id);
Expand All @@ -105,12 +109,11 @@ public function destroy($id)

return response()->json([
'message' => trans('admin::app.marketing.search-seo.sitemaps.index.edit.delete-success'),
], 200);
]);
} catch (\Exception $e) {
return response()->json([
'message' => trans('admin::app.marketing.search-seo.sitemaps.delete-failed', ['name' => 'admin::app.marketing.search-seo.sitemaps.index.sitemap']),
], 500);
}

return response()->json([
'message' => trans('admin::app.marketing.search-seo.sitemaps.delete-failed', ['name' => 'admin::app.marketing.search-seo.sitemaps.index.sitemap']),
], 500);
}
}
Loading

0 comments on commit 3ae62e9

Please sign in to comment.