Add (auto indexing): when set to publish

This commit is contained in:
2023-09-10 21:48:39 +08:00
parent ef58f62e57
commit 645d0f1d02
4 changed files with 43 additions and 26 deletions

View File

@@ -3,18 +3,19 @@
use Illuminate\Support\Str; use Illuminate\Support\Str;
if (! function_exists('str_first_sentence')) { if (! function_exists('str_first_sentence')) {
function str_first_sentence($str) { function str_first_sentence($str)
// Split the string at ., !, or ? {
$sentences = preg_split('/(\.|!|\?)(\s|$)/', $str, 2); // 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 the first part of the array if available
return trim($sentences[0]); 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;
}
} }

View File

@@ -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 a response indicating a successful update
return response()->json(['message' => 'Post updated successfully', 'action' => 'redirect_back']); return response()->json(['message' => 'Post updated successfully', 'action' => 'redirect_back']);
} else { } 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 a response indicating a successful creation
return response()->json(['message' => 'Post created successfully', 'action' => 'redirect_back']); return response()->json(['message' => 'Post created successfully', 'action' => 'redirect_back']);
} }

View File

@@ -16,21 +16,21 @@
], ],
'level' => [1, 2, 3, 4, 5, 6], 'level' => [1, 2, 3, 4, 5, 6],
], ],
'list' => [ 'list' => [
'style' => [ 'style' => [
'type' => 'string', 'type' => 'string',
'allowedValues' => ['ordered', 'unordered'] 'allowedValues' => ['ordered', 'unordered'],
], ],
'items' => [ 'items' => [
'type' => 'array', 'type' => 'array',
'data' => [ 'data' => [
'-' => [ '-' => [
'type' => 'string', 'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]', 'allowedTags' => 'i,b,a[href],code[class],mark[class]',
],
],
],
], ],
],
],
],
'linkTool' => [ 'linkTool' => [
'link' => 'string', 'link' => 'string',
'meta' => [ 'meta' => [

View File

@@ -30,7 +30,8 @@ class="text-decoration-none">{{ $post->title }}</a>
</div> </div>
@else @else
<div class="mb-3"> <div class="mb-3">
<small class="text-secondary">{{ str_first_sentence($post->excerpt) }}</small> <small
class="text-secondary">{{ str_first_sentence($post->excerpt) }}</small>
</div> </div>
@endif @endif