Update (front post): Fix parsing issue

This commit is contained in:
2023-10-04 20:19:52 +08:00
parent 1e7b75706e
commit dba3f0f638
8 changed files with 33 additions and 35 deletions

View File

@@ -26,6 +26,7 @@ protected function schedule(Schedule $schedule): void
AISerpGenArticleJob::dispatch()->onQueue('default')->onConnection('default'); AISerpGenArticleJob::dispatch()->onQueue('default')->onConnection('default');
})->everyMinute()->when(function () use ($mins_between_posts, $launched_date) { })->everyMinute()->when(function () use ($mins_between_posts, $launched_date) {
$minutes_since_launch = now()->diffInMinutes($launched_date); $minutes_since_launch = now()->diffInMinutes($launched_date);
return $minutes_since_launch % $mins_between_posts === 0; return $minutes_since_launch % $mins_between_posts === 0;
}); });

View File

@@ -189,21 +189,26 @@ private function injectTableOfContents($html)
} }
// Create the Table of Contents // Create the Table of Contents
$toc = '<div class="p-3 rounded-3 bg-light mb-3"><ol>'; $domDocument = $crawler->getNode(0)->ownerDocument;
$h2Elements->each(function (Crawler $node, $i) use (&$toc) { $tocDiv = $domDocument->createElement('div');
$content = $node->text(); $tocDiv->setAttribute('class', 'p-3 rounded-3 bg-light mb-3');
$id = 'link-'.$i; // Creating a simple id based on the index $ol = $domDocument->createElement('ol');
$node->getNode(0)->setAttribute('id', $id); // Set the id to the h2 tag $tocDiv->appendChild($ol);
$toc .= "<li class=\"py-1\"><a class=\"text-decoration-none hover-text-decoration-underline\" href='#{$id}'>{$content}</a></li>";
$h2Elements->each(function (Crawler $node, $i) use ($ol) {
$content = htmlspecialchars($node->text(), ENT_XML1 | ENT_COMPAT, 'UTF-8');
$id = 'link-'.$i;
$node->getNode(0)->setAttribute('id', $id);
$li = $ol->appendChild(new \DOMElement('li'));
$li->setAttribute('class', 'py-1');
$a = $li->appendChild(new \DOMElement('a', $content));
$a->setAttribute('class', 'text-decoration-none hover-text-decoration-underline');
$a->setAttribute('href', '#'.$id);
}); });
$toc .= '</ol></div>';
// Insert TOC after h1 // Insert TOC after h1
$domDocument = $crawler->getNode(0)->ownerDocument;
$fragment = $domDocument->createDocumentFragment();
$fragment->appendXML($toc);
$h1Node = $crawler->filter('h1')->getNode(0); $h1Node = $crawler->filter('h1')->getNode(0);
$h1Node->parentNode->insertBefore($fragment, $h1Node->nextSibling); $h1Node->parentNode->insertBefore($tocDiv, $h1Node->nextSibling);
// Get the updated HTML // Get the updated HTML
$updatedHtml = $crawler->filter('body')->html(); $updatedHtml = $crawler->filter('body')->html();

View File

@@ -4,7 +4,6 @@
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow; use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
use LaravelGoogleIndexing; use LaravelGoogleIndexing;
@@ -14,8 +13,7 @@ public function indexing(Request $request)
{ {
$url = $request->input('url'); $url = $request->input('url');
if (is_null($url)) if (is_null($url)) {
{
abort(404); abort(404);
} }

View File

@@ -17,11 +17,9 @@ public static function handle($post)
{ {
$keyword = $post->main_keyword; $keyword = $post->main_keyword;
if (is_array($post->keywords)) if (is_array($post->keywords)) {
{ if (count($post->keywords) > 0) {
if (count($post->keywords) > 0) $keyword .= ' '.implode(' ', $post->keywords);
{
$keyword .= " " . implode(" ", $post->keywords);
} }
} }

View File

@@ -10,7 +10,6 @@
use Exception; use Exception;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class GetNewsSerpTask class GetNewsSerpTask
{ {
public static function handle(Category $category, $country_iso) public static function handle(Category $category, $country_iso)
@@ -76,6 +75,7 @@ public static function handle(Category $category, $country_iso)
} catch (Exception $e) { } catch (Exception $e) {
Log::error(json_encode($serp_obj)); Log::error(json_encode($serp_obj));
inspector()->reportException($e); inspector()->reportException($e);
return null; return null;
} }

View File

@@ -6,7 +6,6 @@
use App\Models\Category; use App\Models\Category;
use App\Models\NewsSerpResult; use App\Models\NewsSerpResult;
use App\Models\SerpUrl; use App\Models\SerpUrl;
use Carbon\Carbon;
use Exception; use Exception;
class ParseNewsSerpDomainsTask class ParseNewsSerpDomainsTask

View File

@@ -4,7 +4,6 @@
use App\Models\Post; use App\Models\Post;
use Exception; use Exception;
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow; use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
use LaravelGoogleIndexing; use LaravelGoogleIndexing;

View File

@@ -32,14 +32,12 @@
dd(now()->minute); dd(now()->minute);
}); });
Route::get('/indexing', [App\Http\Controllers\Tests\TestController::class, 'indexing']); Route::get('/indexing', [App\Http\Controllers\Tests\TestController::class, 'indexing']);
Route::get('/serp-ai-gen', function (Request $request) { Route::get('/serp-ai-gen', function (Request $request) {
AISerpGenArticleJob::dispatch()->onQueue('default')->onConnection('default'); AISerpGenArticleJob::dispatch()->onQueue('default')->onConnection('default');
}); });
Route::get('/exponential', function (Request $request) { Route::get('/exponential', function (Request $request) {
$post_counts = get_exponential_posts_gen_by_day($request->input('day', 1)); $post_counts = get_exponential_posts_gen_by_day($request->input('day', 1));