From 38c53b4045781e11d3b51aba472efe4ca306c6f4 Mon Sep 17 00:00:00 2001 From: Charles Teh Date: Sun, 3 Dec 2023 11:20:03 +0800 Subject: [PATCH] Update (copies) --- .../SitemapCrawler/CustomCrawlProfile.php | 4 +- app/Helpers/Global/string_helper.php | 10 +- .../Controllers/Front/FrontHomeController.php | 8 +- app/Http/Controllers/Tests/TestController.php | 4 +- app/Jobs/Tasks/BrowseRSSLatestNewsTask.php | 12 +- app/Jobs/Tasks/ParseRssPostMetadataTask.php | 15 +-- app/Models/HybridTopRssPostKeywords.php | 2 +- config/platform/global.php | 4 +- config/sitemap.php | 1 - .../views/front/partials/news_bites.blade.php | 113 +++++++++--------- resources/views/front/welcome.blade.php | 11 +- routes/tests.php | 10 +- routes/web.php | 13 +- 13 files changed, 103 insertions(+), 104 deletions(-) diff --git a/app/Helpers/FirstParty/SitemapCrawler/CustomCrawlProfile.php b/app/Helpers/FirstParty/SitemapCrawler/CustomCrawlProfile.php index 5b231f5..87c1db3 100644 --- a/app/Helpers/FirstParty/SitemapCrawler/CustomCrawlProfile.php +++ b/app/Helpers/FirstParty/SitemapCrawler/CustomCrawlProfile.php @@ -2,8 +2,8 @@ namespace App\Helpers\FirstParty\SitemapCrawler; -use Spatie\Crawler\CrawlProfiles\CrawlProfile; use Psr\Http\Message\UriInterface; +use Spatie\Crawler\CrawlProfiles\CrawlProfile; class CustomCrawlProfile extends CrawlProfile { @@ -20,9 +20,7 @@ public function shouldCrawl(UriInterface $url): bool if ($url->getQuery() !== '') { return false; } - return ($this->callback)($url); } - } diff --git a/app/Helpers/Global/string_helper.php b/app/Helpers/Global/string_helper.php index 48a09ee..dced2c5 100644 --- a/app/Helpers/Global/string_helper.php +++ b/app/Helpers/Global/string_helper.php @@ -4,7 +4,8 @@ use Illuminate\Support\Str; if (! function_exists('count_words')) { - function count_words($string) { + function count_words($string) + { // Remove punctuation and line breaks $cleanString = preg_replace('/[\p{P}\s]/u', ' ', $string); @@ -16,9 +17,9 @@ function count_words($string) { } } - if (! function_exists('get_country_names')) { - function get_country_names($lowercase = false) { + function get_country_names($lowercase = false) + { $countryCodes = config('platform.country_codes'); $countryNames = []; @@ -34,7 +35,6 @@ function get_country_names($lowercase = false) { } } - if (! function_exists('is_valid_url')) { function is_valid_url($url) { @@ -195,7 +195,7 @@ function get_domain_from_url($url) $parse = parse_url($url); // Check if 'host' key exists in the parsed URL array - if (!isset($parse['host'])) { + if (! isset($parse['host'])) { return null; // or you can throw an exception or handle this case as per your requirement } diff --git a/app/Http/Controllers/Front/FrontHomeController.php b/app/Http/Controllers/Front/FrontHomeController.php index 8d5fe1e..71fdcd3 100644 --- a/app/Http/Controllers/Front/FrontHomeController.php +++ b/app/Http/Controllers/Front/FrontHomeController.php @@ -26,11 +26,15 @@ 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(); + $rss_count = RssPost::where('status', 'published') + ->where('published_at', '>=', now()->subDay()) + ->count(); + $top_rss_keywords = HybridTopRssPostKeywords::get(1, 16); - $rss_posts = RssPost::with('entities_keywords')->whereNotNull('keywords')->where('status', 'published')->orderBy('published_at', 'desc')->paginate(15); + $rss_posts = RssPost::with('entities_keywords')->whereNotNull('keywords')->where('status', 'published')->orderBy('published_at', 'desc')->paginate(30); - return response(view('front.welcome', compact('rss_posts', 'top_rss_keywords')), 200); + return response(view('front.welcome', compact('rss_posts', 'top_rss_keywords', 'rss_count')), 200); } public function terms(Request $request) diff --git a/app/Http/Controllers/Tests/TestController.php b/app/Http/Controllers/Tests/TestController.php index 8f39de7..7350e31 100644 --- a/app/Http/Controllers/Tests/TestController.php +++ b/app/Http/Controllers/Tests/TestController.php @@ -18,9 +18,9 @@ class TestController extends Controller { public function blacklistkw(Request $request) { - $country_names = get_country_names(true); + $country_names = get_country_names(true); - dd($country_names); + dd($country_names); } diff --git a/app/Jobs/Tasks/BrowseRSSLatestNewsTask.php b/app/Jobs/Tasks/BrowseRSSLatestNewsTask.php index ce3418a..a237709 100644 --- a/app/Jobs/Tasks/BrowseRSSLatestNewsTask.php +++ b/app/Jobs/Tasks/BrowseRSSLatestNewsTask.php @@ -51,16 +51,12 @@ public static function handleSingle($rss_url, $hours = 3) $blacklist_rss_post_keywords = array_merge($blacklist_rss_post_keywords, get_country_names(true)); - foreach ($blacklist_rss_post_keywords as $blacklist_keyword) - { - if (str_contains(strtolower($title), $blacklist_keyword)) - { - continue 2; - } + foreach ($blacklist_rss_post_keywords as $blacklist_keyword) { + if (str_contains(strtolower($title), $blacklist_keyword)) { + continue 2; + } } - - $raw_posts[] = (object) [ 'source' => $f->get_title(), 'source_url' => $rss_url, diff --git a/app/Jobs/Tasks/ParseRssPostMetadataTask.php b/app/Jobs/Tasks/ParseRssPostMetadataTask.php index 7faeed5..51ab5e0 100644 --- a/app/Jobs/Tasks/ParseRssPostMetadataTask.php +++ b/app/Jobs/Tasks/ParseRssPostMetadataTask.php @@ -28,7 +28,6 @@ public static function handle(int $rss_post_id) $final_content = "TITLE: {$rss_post->title}"; - if (in_array($rss_post->status, ['blocked', 'trashed'])) { return; } @@ -160,12 +159,9 @@ public static function handle(int $rss_post_id) $rss_post->status = 'published'; - if (!$rss_post->status != 'blocked') - { - if (isset($post_meta_response->output->is_ai_or_tech_news)) - { - if ($post_meta_response->output->is_ai_or_tech_news != true) - { + if (! $rss_post->status != 'blocked') { + if (isset($post_meta_response->output->is_ai_or_tech_news)) { + if ($post_meta_response->output->is_ai_or_tech_news != true) { $rss_post->status = 'blocked'; } // else @@ -182,9 +178,8 @@ public static function handle(int $rss_post_id) } - if (count($words_to_save) <= 0) - { - $rss_post->status = 'blocked'; + if (count($words_to_save) <= 0) { + $rss_post->status = 'blocked'; } if ($rss_post->save()) { diff --git a/app/Models/HybridTopRssPostKeywords.php b/app/Models/HybridTopRssPostKeywords.php index 72d981a..a93d44b 100644 --- a/app/Models/HybridTopRssPostKeywords.php +++ b/app/Models/HybridTopRssPostKeywords.php @@ -31,7 +31,7 @@ public static function get($days = 1, $limit = 10) $queryResults = DB::table('rss_post_keywords') ->select('value', 'value_lowercased', DB::raw('COUNT(value_lowercased) as value_count')) ->where('created_at', '>=', now()->subDays($days)) - ->whereNotIn('value_lowercased', ['techcrunch', 'the verge', 'forbes', 'producthunt', 'vox media','engadget']) + ->whereNotIn('value_lowercased', ['techcrunch', 'the verge', 'forbes', 'producthunt', 'vox media', 'engadget']) ->groupBy('value', 'value_lowercased') ->orderBy(DB::raw('COUNT(value_lowercased)'), 'desc') ->limit($limit) diff --git a/config/platform/global.php b/config/platform/global.php index c58ce2e..4bf496d 100644 --- a/config/platform/global.php +++ b/config/platform/global.php @@ -18,8 +18,8 @@ ], 'blacklist_rss_post_keywords' => [ - 'deal' - ], + 'deal', + ], 'rss' => [ 'http://news.ycombinator.com/rss', diff --git a/config/sitemap.php b/config/sitemap.php index 2007c5e..ce2bc85 100644 --- a/config/sitemap.php +++ b/config/sitemap.php @@ -2,7 +2,6 @@ use App\Helpers\FirstParty\SitemapCrawler\CustomCrawlProfile; use GuzzleHttp\RequestOptions; -use Spatie\Sitemap\Crawler\Profile; return [ diff --git a/resources/views/front/partials/news_bites.blade.php b/resources/views/front/partials/news_bites.blade.php index c51bc22..8862187 100644 --- a/resources/views/front/partials/news_bites.blade.php +++ b/resources/views/front/partials/news_bites.blade.php @@ -1,38 +1,36 @@ @foreach ($rss_posts as $key => $post) -
-
-
-
-

- {{ $post->title }} -

+
+
+
+
+

+ {{ $post->title }} +

- @if ($post->entities_keywords->count() > 0) + @if ($post->entities_keywords->count() > 0)
- {{-- @if ($post->entities) --}} - @foreach ($post->entities_keywords as $keyword) - {{-- @if ($keyword->type == 'entity') --}} - @if ($loop->iteration <= 2) - @if ($keyword->is_main) -

- {{ $keyword->value }} -

- @else -

- {{ $keyword->value }} -

- @endif - @elseif ($loop->iteration == 3) -

- +{{ count($post->entities_keywords) - 3 }} more -

- @break - @endif - {{-- @endif --}} - @endforeach +{{-- @if ($post->entities) --}} +@foreach ($post->entities_keywords as $keyword) + {{-- @if ($keyword->type == 'entity') --}} + @if ($loop->iteration <= 3) + @if ($keyword->is_main) +

+ {{ $keyword->value }} +

+ @else +

+ {{ $keyword->value }} +

+ @endif + @elseif ($loop->iteration > 3 && count($post->entities_keywords) > 3) +

+ +{{ count($post->entities_keywords) - 3 }} more +

+ @break + @endif +{{-- @endif --}} +@endforeach + {{-- @endif --}} @if ($post->impact_level == 'high') @@ -42,41 +40,42 @@ class="font-family-roboto-condensed mb-0 pb-1 d-inline badge bg-danger border-da @endif
+ @endif + +
+ @if ($post->category) + {{ $post->category->name }} + @endif -
- @if ($post->category) - {{ $post->category->name }} - + + @if ($post->published_at->isBetween(now()->subDays(1), now())) + {{ $post->published_at->diffForHumans() }} + @else + {{ $post->published_at->format('d M') }} @endif - - @if ($post->published_at->isBetween(now()->subDays(1), now())) - {{ $post->published_at->diffForHumans() }} - @else - {{ $post->published_at->format('d M') }} - @endif + - - - @if (!is_empty($post->bites)) + @if (!is_empty($post->bites)) - {{ min_read($post->bites) }} - @endif + {{ min_read($post->bites) }} + @endif - - + + {{ get_domain_from_url($post->post_url) }} - -
+ +
-
- -
-
@endforeach diff --git a/resources/views/front/welcome.blade.php b/resources/views/front/welcome.blade.php index ba36a9e..5824ee1 100644 --- a/resources/views/front/welcome.blade.php +++ b/resources/views/front/welcome.blade.php @@ -5,21 +5,24 @@
-
Your Future Depends on Today's + + +

Latest AI & tech news in 1 hyper-focused platform

+{{--
Your Future Depends on Today's News

In the fast-evolving world of AI and tech, staying updated is not - optional—it's critical for your future success. Stay updated with hourly news + optional—it's critical for your future success. Stay updated with hourly news FutureWalker.

Start reading now -
+
--}}
-

📡 Monitoring top tags for the past 24 hours

+

📡 Top keywords identified for the past 24 hours across {{ $rss_count }} articles identified by GPT

@foreach ($top_rss_keywords as $rss_keyword) take(50)->orderBy('published_at','DESC')->get(); + $rss_posts = RssPost::whereNull('bites')->take(50)->orderBy('published_at', 'DESC')->get(); - foreach ($rss_posts as $rss_post) - { - ParseRssPostMetadataJob::dispatch($rss_post->id)->onQueue('default')->onConnection('default'); + foreach ($rss_posts as $rss_post) { + ParseRssPostMetadataJob::dispatch($rss_post->id)->onQueue('default')->onConnection('default'); } - - }); Route::get('/seed', function (Request $request) { diff --git a/routes/web.php b/routes/web.php index 5b9435e..40edcc0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -23,11 +23,20 @@ Route::get('/disclaimer', [App\Http\Controllers\Front\FrontHomeController::class, 'disclaimer'])->name('front.disclaimer')->middleware('cacheResponse:2630000'); -Route::get('/bites', [App\Http\Controllers\Front\FrontListController::class, 'index'])->name('front.all')->middleware('cacheResponse:1800'); + +Route::get('/bites/', function ($query) { + return redirect()->route('front.all', 301); +}); + +Route::get('/digest', [App\Http\Controllers\Front\FrontListController::class, 'index'])->name('front.all')->middleware('cacheResponse:1800'); Route::post('/search', [App\Http\Controllers\Front\FrontListController::class, 'search'])->name('front.search'); -Route::get('/bites/{query}', [App\Http\Controllers\Front\FrontListController::class, 'searchResults'])->name('front.search.results')->middleware('cacheResponse:1800'); +Route::get('/bites/{query}', function ($query) { + return redirect()->route('front.search.results', ['query' => $query], 301); +}); + +Route::get('/digest/{query}', [App\Http\Controllers\Front\FrontListController::class, 'searchResults'])->name('front.search.results')->middleware('cacheResponse:1800'); Route::get('/{category_slug}/{slug}', [App\Http\Controllers\Front\FrontPostController::class, 'index'])->name('front.post');