Update (kernel): Auto submit index

This commit is contained in:
2023-11-23 03:38:45 +08:00
parent b2762ecef2
commit 416f06b344
8 changed files with 139 additions and 11 deletions

View File

@@ -5,6 +5,8 @@
use App\Jobs\BrowseDFSAndWriteWithAIJob;
use App\Jobs\BrowseRSSPostJob;
use App\Jobs\PublishIndexPostJob;
use App\Jobs\PublishRssSearchResultJob;
use App\Models\HybridTopRssPostKeywords;
use App\Models\Post;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -22,6 +24,17 @@ protected function schedule(Schedule $schedule): void
BrowseRSSPostJob::dispatch(1)->onQueue('default')->onConnection('default');
})->hourly()->name('browse-rss-post-job-hourly');
$schedule->call(function () {
$top_rss_keywords = HybridTopRssPostKeywords::get(1, 20);
foreach ($top_rss_keywords as $rss_keyword)
{
PublishRssSearchResultJob::dispatch($rss_keyword->value_lowercased)->onQueue('default')->onConnection('default');
}
})->twiceDaily(0, 12)->name('top-rss-keywords-indexing-daily');
// $schedule->call(function () {
// BrowseDFSAndWriteWithAIJob::dispatch()->onQueue('default')->onConnection('default');
// })->everySixHours()->name('write-a-job-6hrs');

View File

@@ -5,6 +5,8 @@
use App\Http\Controllers\Controller;
use App\Models\Post;
use App\Models\RssPost;
use App\Models\HybridTopRssPostKeywords;
use Artesaos\SEOTools\Facades\SEOMeta;
use Artesaos\SEOTools\Facades\SEOTools;
use GrahamCampbell\Markdown\Facades\Markdown;
@@ -25,9 +27,11 @@ public function home(Request $request)
// $query->whereNotIn('id', $featured_posts->pluck('id')->toArray());
// })->where('status', 'publish')->where('published_at', '<=', now())->orderBy('published_at', 'desc')->limit(10)->get();
$top_rss_keywords = HybridTopRssPostKeywords::get(1, 10);
$rss_posts = RssPost::with('entities_keywords')->where('status', 'published')->orderBy('published_at', 'desc')->paginate(15);
return response(view('front.welcome', compact('rss_posts')), 200);
return response(view('front.welcome', compact('rss_posts','top_rss_keywords')), 200);
}
public function terms(Request $request)

View File

@@ -29,7 +29,7 @@ public function searchResults(Request $request, $query)
$breadcrumbs = collect([
['name' => 'Home', 'url' => route('front.home')],
['name' => 'News Bites', 'url' => route('front.all')],
['name' => $query, 'url' => null],
['name' => '#'.$query, 'url' => null],
]);
$title = 'Latest News about '.ucwords($query).' in FutureWalker';

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Jobs;
use App\Jobs\Tasks\PublishIndexPostTask;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
use LaravelGoogleIndexing;
use Exception;
class PublishRssSearchResultJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $query;
public $timeout = 30;
/**
* Create a new job instance.
*/
public function __construct(string $query)
{
$this->query = $query;
}
/**
* Execute the job.
*/
public function handle(): void
{
if ((app()->environment() == 'production') && (config('platform.global.indexing'))) {
$url = get_route_search_result(strtolower($this->query));
try {
IndexNow::submit($url);
} catch (Exception) {
}
try {
LaravelGoogleIndexing::create()->update($url);
} catch (Exception) {
}
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
class HybridTopRssPostKeywords extends Model
{
// Disable timestamps as this is not a table model
public $timestamps = false;
// Define fillable attributes
protected $fillable = ['value', 'value_lowercased', 'value_count'];
// Override the table and primary key as this is an abstract model
protected $table = null;
protected $primaryKey = null;
// Disable incrementing as this is an abstract model
public $incrementing = false;
// Static method to get top keywords
public static function get($days = 1, $limit = 10)
{
return Cache::remember('top_rss_post_keywords_by_day_'.$days.'_'.$limit, 180, function () use ($days, $limit) {
$queryResults = DB::table('rss_post_keywords')
->select('value', 'value_lowercased', DB::raw('COUNT(value_lowercased) as value_count'))
->where('created_at', '>=', now()->subDays($days))
->groupBy('value', 'value_lowercased')
->orderBy(DB::raw('COUNT(value_lowercased)'), 'desc')
->limit($limit)
->get();
return self::hydrate($queryResults->toArray());
});
}
}

View File

@@ -2,9 +2,9 @@
@foreach ($rss_posts as $key => $post)
<div class="accordion-item">
<h2 class="accordion-header" id="heading{{ $post->id }}">
<h2 class="accordion-header" id="heading{{ $key }}">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapse{{ $post->id }}" aria-controls="collapse{{ $post->id }}">
data-bs-target="#collapse{{ $key }}" aria-controls="collapse{{ $key }}">
<div>
<h3 class="h6 mb-2 fw fw-semibold font-family-roboto-condensed">
{{ $post->title }}
@@ -55,8 +55,8 @@ class="font-family-roboto-condensed mb-1 pb-1 d-inline badge bg-danger border-da
</div>
</button>
</h2>
<div id="collapse{{ $post->id }}" class="accordion-collapse collapse"
aria-labelledby="heading{{ $post->id }}" data-bs-parent="#accordionTechBites">
<div id="collapse{{ $key }}" class="accordion-collapse collapse"
aria-labelledby="heading{{ $key }}" data-bs-parent="#accordionTechBites">
<div class="accordion-body small">
<div class="fw-bold">The Bite:</div>
<div class="mb-3">{{ $post->bites }}</div>

View File

@@ -3,7 +3,7 @@
<main>
<div class="w-full py-5 bg-hero">
<div class="container-lg">
<div class="text-center row justify-content-center">
<div class="text-center row justify-content-center mb-4">
<div class="col-12 col-md-10 col-lg-8">
<div class="display-6 fw-bold font-family-roboto-condensed mb-2">Your Future Depends<wbr> on Today's
News</div>
@@ -11,10 +11,24 @@
optional—it's critical for your future success. Stay updated with daily news 🍪 bites from
<strong>FutureWalker</strong>.
</h1>
<a href="#latest-news" class="btn btn-primary px-4 rounded-pill text-decoration-none">Start reading
now</a>
</div>
</div>
<div class="text-center row justify-content-center">
<div class="col-12 col-md-10 col-lg-6">
<h2 class="h4 fw-semibold mb-3">Monitoring top tags for the past 24 hours</h2>
@foreach ($top_rss_keywords as $rss_keyword)
<a href="{{ get_route_search_result($rss_keyword->value_lowercased) }}" class="mb-1 pb-1 badge text-bg-light border me-1 fw-bold shadow">
<span class="h6">#{{ $rss_keyword->value }}</span>
</a>
@endforeach
</div>
</div>
</div>
</div>
@@ -53,7 +67,7 @@ class="text-secondary">{{ $post->published_at->diffForHumans() }}</small>
@endif --}}
<div class="container-lg py-4">
<div id="latest-news" class="container-lg py-4">
<div class="row">
<div class="col-12 col-lg-8 mb-3">
@@ -61,7 +75,7 @@ class="text-secondary">{{ $post->published_at->diffForHumans() }}</small>
@if ($rss_posts->count() > 0)
<div class="text-start mb-3">
<div class="d-flex">
<h2 id="latest-news" class="align-self-center fw-bold font-family-roboto-condensed mb-1 h2">
<h2 class="align-self-center fw-bold font-family-roboto-condensed mb-1 h2">
🍪 Tech Bites </h2>
<div class="align-self-center">
<span
@@ -71,7 +85,10 @@ class="bi bi-clock-history me-1"></i> UPDATED HOURLY</span>
</div>
<h5>1 minute news bites worth every second</h5>
<h5 class="h6">
Tap on <i class="bi bi-chevron-down"></i> to read the 1 minute news bite worth every second
</h5>
</div>

View File

@@ -25,4 +25,4 @@
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '{{ $id }}');
</script>
@endif
@endif