From 645d0f1d0271b1d28e06695b2d9af9c2439b6b75 Mon Sep 17 00:00:00 2001 From: Charles T Date: Sun, 10 Sep 2023 21:48:39 +0800 Subject: [PATCH] Add (auto indexing): when set to publish --- app/Helpers/Global/string_helper.php | 23 +++++++-------- app/Http/Controllers/Admin/PostController.php | 15 ++++++++++ config/laravel_editorjs.php | 28 +++++++++---------- .../partials/featured_post_card.blade.php | 3 +- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/app/Helpers/Global/string_helper.php b/app/Helpers/Global/string_helper.php index be6d0e7..a01227a 100644 --- a/app/Helpers/Global/string_helper.php +++ b/app/Helpers/Global/string_helper.php @@ -3,18 +3,19 @@ use Illuminate\Support\Str; if (! function_exists('str_first_sentence')) { -function str_first_sentence($str) { - // Split the string at ., !, or ? - $sentences = preg_split('/(\.|!|\?)(\s|$)/', $str, 2); - - // Return the first part of the array if available - if (isset($sentences[0])) { - return trim($sentences[0]); + function str_first_sentence($str) + { + // Split the string at ., !, or ? + $sentences = preg_split('/(\.|!|\?)(\s|$)/', $str, 2); + + // Return the first part of the array if available + if (isset($sentences[0])) { + return trim($sentences[0]); + } + + // If no sentence ending found, return the whole string + return $str; } - - // If no sentence ending found, return the whole string - return $str; -} } diff --git a/app/Http/Controllers/Admin/PostController.php b/app/Http/Controllers/Admin/PostController.php index dcc9ca7..2efc21f 100644 --- a/app/Http/Controllers/Admin/PostController.php +++ b/app/Http/Controllers/Admin/PostController.php @@ -125,6 +125,14 @@ public function postUpsert(Request $request) ]); } + if ($existingPost->status == 'publish') { + + $post_url = route('home.country.post', ['country' => $existingPost->post_category?->category?->country_locale_slug, 'post_slug' => $existingPost->slug]); + + LaravelGoogleIndexing::create()->update($post_url); + IndexNow::submit($post_url); + } + // Return a response indicating a successful update return response()->json(['message' => 'Post updated successfully', 'action' => 'redirect_back']); } else { @@ -143,6 +151,13 @@ public function postUpsert(Request $request) ]); } + if ($newPost->status == 'publish') { + $post_url = route('home.country.post', ['country' => $newPost->post_category?->category?->country_locale_slug, 'post_slug' => $newPost->slug]); + + LaravelGoogleIndexing::create()->update($post_url); + IndexNow::submit($post_url); + } + // Return a response indicating a successful creation return response()->json(['message' => 'Post created successfully', 'action' => 'redirect_back']); } diff --git a/config/laravel_editorjs.php b/config/laravel_editorjs.php index 874019e..d267da5 100644 --- a/config/laravel_editorjs.php +++ b/config/laravel_editorjs.php @@ -16,21 +16,21 @@ ], 'level' => [1, 2, 3, 4, 5, 6], ], -'list' => [ - 'style' => [ - 'type' => 'string', - 'allowedValues' => ['ordered', 'unordered'] - ], - 'items' => [ - 'type' => 'array', - 'data' => [ - '-' => [ - 'type' => 'string', - 'allowedTags' => 'i,b,a[href],code[class],mark[class]', + 'list' => [ + 'style' => [ + 'type' => 'string', + 'allowedValues' => ['ordered', 'unordered'], + ], + 'items' => [ + 'type' => 'array', + 'data' => [ + '-' => [ + 'type' => 'string', + 'allowedTags' => 'i,b,a[href],code[class],mark[class]', + ], + ], + ], ], - ], - ], -], 'linkTool' => [ 'link' => 'string', 'meta' => [ diff --git a/resources/views/front/partials/featured_post_card.blade.php b/resources/views/front/partials/featured_post_card.blade.php index e7f19b5..b8db502 100644 --- a/resources/views/front/partials/featured_post_card.blade.php +++ b/resources/views/front/partials/featured_post_card.blade.php @@ -30,7 +30,8 @@ class="text-decoration-none">{{ $post->title }} @else
- {{ str_first_sentence($post->excerpt) }} + {{ str_first_sentence($post->excerpt) }}
@endif