This commit is contained in:
2023-11-20 00:32:26 +08:00
parent 9ce3e5c82a
commit 2559d4be1c
37 changed files with 288 additions and 12419 deletions

View File

@@ -4,11 +4,10 @@
use App\Jobs\BrowseAndWriteWithAIJob;
use App\Jobs\PublishIndexPostJob;
use App\Models\Post;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Models\Post;
class Kernel extends ConsoleKernel
{
/**
@@ -22,10 +21,9 @@ protected function schedule(Schedule $schedule): void
})->dailyAt('00:00');
$schedule->call(function () {
$future_post = Post::whereNotNull('published_at')->where('status','future')->where('published_at', '>=', now())->orderBy('published_at','ASC')->first();
PublishIndexPostJob::dispatch($future_post->id)->onQueue('default')->onConnection('default');
$future_post = Post::whereNotNull('published_at')->where('status', 'future')->where('published_at', '>=', now())->orderBy('published_at', 'ASC')->first();
PublishIndexPostJob::dispatch($future_post->id)->onQueue('default')->onConnection('default');
})->everyMinute();

View File

@@ -21,9 +21,8 @@ public static function liveAdvanced($se, $se_type, $keyword, $location_name, $la
'language_code' => $language_code,
];
if (!is_empty($search_param))
{
$query['search_param'] = $search_param;
if (! is_empty($search_param)) {
$query['search_param'] = $search_param;
}
try {

View File

@@ -12,55 +12,51 @@
class FrontListController extends Controller
{
public function search(Request $request)
{
$page_type = 'search';
public function search(Request $request)
{
$page_type = 'search';
$query = $request->get('query', '');
$query = $request->get('query', '');
$breadcrumbs = collect([
['name' => 'Home', 'url' => route('front.home')],
['name' => 'Search', 'url' => null],
['name' => $query, 'url' => url()->current()],
]);
$breadcrumbs = collect([
['name' => 'Home', 'url' => route('front.home')],
['name' => 'Search', 'url' => null],
['name' => $query, 'url' => url()->current()],
]);
$title = 'Latest News about '.ucwords($query).' in FutureWalker';
SEOTools::metatags();
SEOTools::twitter();
SEOTools::opengraph();
SEOTools::jsonLd();
SEOTools::setTitle($title, false);
// Use full-text search capabilities of your database
// For example, using MySQL's full-text search with MATCH...AGAINST
$posts = Post::with('category')
->where('status', 'publish')
->whereRaw("to_tsvector('english', title || ' ' || bites) @@ to_tsquery('english', ?)", [$query])
->orderBy('published_at', 'desc')
->cursorPaginate(10);
$title = 'Latest News about ' . ucwords($query) . ' in FutureWalker';
// breadcrumb json ld
$listItems = [];
SEOTools::metatags();
SEOTools::twitter();
SEOTools::opengraph();
SEOTools::jsonLd();
SEOTools::setTitle($title, false);
foreach ($breadcrumbs as $index => $breadcrumb) {
$listItems[] = [
'name' => $breadcrumb['name'],
'url' => $breadcrumb['url'],
];
}
// Use full-text search capabilities of your database
// For example, using MySQL's full-text search with MATCH...AGAINST
$posts = Post::with('category')
->where('status', 'publish')
->whereRaw("to_tsvector('english', title || ' ' || bites) @@ to_tsquery('english', ?)", [$query])
->orderBy('published_at', 'desc')
->cursorPaginate(10);
$breadcrumb_context = Context::create('breadcrumb_list', [
'itemListElement' => $listItems,
]);
// breadcrumb json ld
$listItems = [];
foreach ($breadcrumbs as $index => $breadcrumb) {
$listItems[] = [
'name' => $breadcrumb['name'],
'url' => $breadcrumb['url'],
];
return view('front.post_list', compact('posts', 'breadcrumbs', 'breadcrumb_context', 'title', 'page_type'));
}
$breadcrumb_context = Context::create('breadcrumb_list', [
'itemListElement' => $listItems,
]);
return view('front.post_list', compact('posts', 'breadcrumbs', 'breadcrumb_context', 'title','page_type'));
}
public function index(Request $request)
{
$page_type = 'default';
@@ -96,7 +92,7 @@ public function index(Request $request)
'itemListElement' => $listItems,
]);
return view('front.post_list', compact('posts', 'breadcrumbs', 'breadcrumb_context','page_type'));
return view('front.post_list', compact('posts', 'breadcrumbs', 'breadcrumb_context', 'page_type'));
}
public function category(Request $request, $category_slug)
@@ -147,6 +143,6 @@ public function category(Request $request, $category_slug)
'itemListElement' => $listItems,
]);
return view('front.post_list', compact('category', 'posts', 'breadcrumbs', 'breadcrumb_context','page_type'));
return view('front.post_list', compact('category', 'posts', 'breadcrumbs', 'breadcrumb_context', 'page_type'));
}
}

View File

@@ -3,7 +3,6 @@
namespace App\Jobs;
use App\Jobs\Tasks\PublishIndexPostTask;
use App\Models\Post;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

View File

@@ -5,11 +5,11 @@
use App\Helpers\FirstParty\OpenAI\OpenAI;
use App\Helpers\FirstParty\OSSUploader\OSSUploader;
use App\Jobs\SchedulePublishPost;
use App\Models\Entity;
use App\Models\PostEntity;
use App\Models\Category;
use App\Models\Entity;
use App\Models\Post;
use App\Models\PostCategory;
use App\Models\PostEntity;
use App\Models\SerpUrlResearch;
use App\Models\ServiceCostUsage;
use Exception;
@@ -78,100 +78,84 @@ public static function handle(int $post_id)
$post = self::setPostImage($post);
}
if (isset($post_meta_response->output->society_impact))
{
if (!is_empty($post_meta_response->output->society_impact))
{
$post->society_impact = $post_meta_response->output->society_impact;
}
if (isset($post_meta_response->output->society_impact)) {
if (! is_empty($post_meta_response->output->society_impact)) {
$post->society_impact = $post_meta_response->output->society_impact;
}
}
if (isset($post_meta_response->output->society_impact_level))
{
if (!is_empty($post_meta_response->output->society_impact_level))
{
$post->society_impact = $post_meta_response->output->society_impact_level;
}
if (isset($post_meta_response->output->society_impact_level)) {
if (! is_empty($post_meta_response->output->society_impact_level)) {
$post->society_impact = $post_meta_response->output->society_impact_level;
}
}
if ($post->save()) {
// Set Category
// Set Category
$category_name = 'Updates';
$category_name = 'Updates';
if ((isset($post_meta_response->output->category)) && (!is_empty($post_meta_response->output->category)))
{
$category_name = $post_meta_response?->output?->category;
}
$category = Category::where('name', $category_name)->first();
if (is_null($category))
{
$category = Category::where('name', 'Updates')->first();
}
// Set Post Category
$post_category = PostCategory::where('post_id', $post->id)->first();
if (is_null($post_category))
{
$post_category = new PostCategory;
$post_category->post_id = $post->id;
}
$post_category->category_id = $category->id;
$post_category->save();
// Set Post Entities
if (isset($post_meta_response->output->entities))
{
$entity_names = [];
if (is_array($post_meta_response->output->entities))
{
$entity_names = $post_meta_response->output->entities;
if ((isset($post_meta_response->output->category)) && (! is_empty($post_meta_response->output->category))) {
$category_name = $post_meta_response?->output?->category;
}
if (count($entity_names) > 0)
{
$previous_post_entities = PostEntity::where('post_id', $post->id)->delete();
$category = Category::where('name', $category_name)->first();
foreach ($entity_names as $entity_name)
{
$entity_name = trim($entity_name);
$entity = Entity::where('name', $entity_name)->first();
if (is_null($entity))
{
$entity = new Entity;
$entity->name = $entity_name;
$entity->slug = str_slug($entity_name);
$entity->save();
}
$post_entity = PostEntity::where('post_id', $post->id)
->where('entity_id', $entity->id)
->first();
if (is_null($post_entity))
{
$post_entity = new PostEntity;
$post_entity->post_id = $post->id;
$post_entity->entity_id = $entity->id;
$post_entity->save();
}
}
if (is_null($category)) {
$category = Category::where('name', 'Updates')->first();
}
}
// Set Schedule Publish
SchedulePublishPost::dispatch($post->id, 'future')->onQueue('default')->onConnection('default');
// Set Post Category
$post_category = PostCategory::where('post_id', $post->id)->first();
if (is_null($post_category)) {
$post_category = new PostCategory;
$post_category->post_id = $post->id;
}
$post_category->category_id = $category->id;
$post_category->save();
// Set Post Entities
if (isset($post_meta_response->output->entities)) {
$entity_names = [];
if (is_array($post_meta_response->output->entities)) {
$entity_names = $post_meta_response->output->entities;
}
if (count($entity_names) > 0) {
$previous_post_entities = PostEntity::where('post_id', $post->id)->delete();
foreach ($entity_names as $entity_name) {
$entity_name = trim($entity_name);
$entity = Entity::where('name', $entity_name)->first();
if (is_null($entity)) {
$entity = new Entity;
$entity->name = $entity_name;
$entity->slug = str_slug($entity_name);
$entity->save();
}
$post_entity = PostEntity::where('post_id', $post->id)
->where('entity_id', $entity->id)
->first();
if (is_null($post_entity)) {
$post_entity = new PostEntity;
$post_entity->post_id = $post->id;
$post_entity->entity_id = $entity->id;
$post_entity->save();
}
}
}
}
// Set Schedule Publish
SchedulePublishPost::dispatch($post->id, 'future')->onQueue('default')->onConnection('default');
}
}

View File

@@ -13,9 +13,8 @@ public static function handle(int $post_id)
{
$post = Post::find($post_id);
if (is_null($post))
{
return ;
if (is_null($post)) {
return;
}
$post->status = 'publish';

View File

@@ -12,28 +12,25 @@
/**
* Class Entity
*
*
* @property int $id
* @property string $name
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property Collection|PostEntity[] $post_entities
*
* @package App\Models
*/
class Entity extends Model
{
protected $table = 'entities';
protected $table = 'entities';
protected $fillable = [
'name',
'slug',
'description'
];
protected $fillable = [
'name',
'slug',
'description',
];
public function post_entities()
{
return $this->hasMany(PostEntity::class);
}
public function post_entities()
{
return $this->hasMany(PostEntity::class);
}
}

View File

@@ -11,39 +11,36 @@
/**
* Class PostEntity
*
*
* @property int $id
* @property int $post_id
* @property int $entity_id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property Post $post
* @property Entity $entity
*
* @package App\Models
*/
class PostEntity extends Model
{
protected $table = 'post_entities';
protected $table = 'post_entities';
protected $casts = [
'post_id' => 'int',
'entity_id' => 'int'
];
protected $casts = [
'post_id' => 'int',
'entity_id' => 'int',
];
protected $fillable = [
'post_id',
'entity_id'
];
protected $fillable = [
'post_id',
'entity_id',
];
public function post()
{
return $this->belongsTo(Post::class);
}
public function post()
{
return $this->belongsTo(Post::class);
}
public function entity()
{
return $this->belongsTo(Entity::class);
}
public function entity()
{
return $this->belongsTo(Entity::class);
}
}