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');
})->everyMinute()->when(function () use ($mins_between_posts, $launched_date) {
$minutes_since_launch = now()->diffInMinutes($launched_date);
return $minutes_since_launch % $mins_between_posts === 0;
});

View File

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

View File

@@ -4,22 +4,20 @@
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
use LaravelGoogleIndexing;
class TestController extends Controller
{
public function indexing(Request $request)
{
$url = $request->input('url');
if (is_null($url))
public function indexing(Request $request)
{
abort(404);
}
$url = $request->input('url');
IndexNow::submit($url);
LaravelGoogleIndexing::create()->update($url);
}
if (is_null($url)) {
abort(404);
}
IndexNow::submit($url);
LaravelGoogleIndexing::create()->update($url);
}
}

View File

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

View File

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

View File

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

View File

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