Update (route)

This commit is contained in:
2023-11-21 21:24:40 +08:00
parent 27035c1a9b
commit 4827130183
6 changed files with 60 additions and 5 deletions

View File

@@ -4,3 +4,4 @@
require 'geo_helper.php';
require 'platform_helper.php';
require 'proxy_helper.php';
require 'route_helper.php';

View File

@@ -0,0 +1,13 @@
<?php
if (! function_exists('get_route_search_result')) {
function get_route_search_result($query)
{
return route('front.search.results',
[
'query' => strtolower(urlencode($query)),
]);
}
}

View File

@@ -17,14 +17,14 @@ public function search(Request $request)
return redirect()->back();
}
return redirect()->to(route('front.search.results',['query' => $request->input('query')]));
return redirect()->to(get_route_search_result($request->input('query')));
}
public function searchResults(Request $request, $query)
{
$page_type = 'search';
$query = strtolower($query);
$query = urldecode($query);
$breadcrumbs = collect([
['name' => 'Home', 'url' => route('front.home')],

View File

@@ -4,6 +4,7 @@
use App\Jobs\ParseRssPostMetadataJob;
use App\Models\RssPost;
use App\Models\ServiceCostUsage;
use Exception;
use Illuminate\Support\Facades\Http;
use League\HTMLToMarkdown\HtmlConverter;
@@ -34,7 +35,16 @@ public static function handle(int $rss_post_id)
if ($response->successful()) {
$raw_html = $response->body();
$costs['unblocker'] = calculate_smartproxy_cost(round(strlen($raw_html) / 1024, 2), 'rotating_global');
$cost = calculate_smartproxy_cost(round(strlen($raw_html) / 1024, 2), 'rotating_global');
$service_cost_usage = new ServiceCostUsage;
$service_cost_usage->cost = $cost;
$service_cost_usage->name = 'smartproxy-CrawlRssPostTask';
$service_cost_usage->reference_1 = 'rss_post';
$service_cost_usage->reference_2 = strval($rss_post_id);
$service_cost_usage->output = null;
$service_cost_usage->save();
} else {
$raw_html = null;
$response->throw();

View File

@@ -8,6 +8,9 @@
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;
/**
* Class RssPost
@@ -33,7 +36,7 @@
* @property Carbon|null $updated_at
* @property Category|null $category
*/
class RssPost extends Model
class RssPost extends Model implements Feedable
{
protected $table = 'rss_posts';
@@ -68,4 +71,31 @@ public function category()
{
return $this->belongsTo(Category::class);
}
public function getAllKeywordsAttribute()
{
if (!is_empty($this->keyword_list))
{
return array_unique(explode(",",$this->keyword_list));
}
return [];
}
public function toFeedItem(): FeedItem
{
return FeedItem::create([
'id' => $this->id,
'title' => $this->title,
'summary' => $this->bites,
'updated' => $this->published_at,
// 'link' => route('front.post', ['slug' => $this->slug, 'category_slug' => $this->category->slug]),
'authorName' => 'FutureWalker',
]);
}
public static function getFeedItems()
{
return self::with('category')->where('status', 'published')->latest('published_at')->take(60)->get();
}
}

View File

@@ -57,6 +57,7 @@ class="d-inline text-secondary small">{{ min_read($post->bites) }}</span>
<div id="collapse{{ $post->id }}" class="accordion-collapse collapse" aria-labelledby="heading{{ $post->id }}"
data-bs-parent="#accordionTechBites">
<div class="accordion-body small">
<div class="fw-bold">The Bite:</div>
<div class="mb-3">{{ $post->bites }}</div>
@if (in_array($post->impact_level, ['medium','high']))
@@ -69,7 +70,7 @@ class="d-inline text-secondary small">{{ min_read($post->bites) }}</span>
@endif
@if ($post->entities)
<div class="mb-2">
More about: @foreach( $post->keywords as $keyword) <a class="ms-1" href="{{ route('front.search.results',['query' => strtolower($keyword) ]) }}">{{ $keyword }}</a> @endforeach
More about: @foreach( $post->all_keywords as $keyword) <a class="ms-1" href="{{ get_route_search_result($keyword) }}">{{ $keyword }}</a> @endforeach
</div>
@endif
<div>