Update (view): redesign
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
if (! function_exists('epoch_now_timestamp')) {
|
||||
@@ -9,6 +10,27 @@ function epoch_now_timestamp()
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('read_duration')) {
|
||||
function read_duration($text)
|
||||
{
|
||||
return Str::readDuration($text);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('plain_text')) {
|
||||
function plain_text($content)
|
||||
{
|
||||
return trim(preg_replace('/\s\s+/', ' ', strip_tags($content)));
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('markdown_min_read')) {
|
||||
function markdown_min_read($markdown)
|
||||
{
|
||||
return read_duration(plain_text(Markdown::convert($markdown)->getContent()));
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('unslug')) {
|
||||
function unslug($slug, $delimiter = '-')
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ public function redirect(Request $request, $slug)
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
return redirect()->route('front.post',['category_slug' => $post->category->slug, 'slug' => $post->slug]);
|
||||
return redirect()->route('front.post', ['category_slug' => $post->category->slug, 'slug' => $post->slug]);
|
||||
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public function index(Request $request, $category_slug, $slug)
|
||||
->addValue('dateCreated', $post->created_at->format('Y-m-d'))
|
||||
->addValue('dateModified', $post->updated_at->format('Y-m-d'))
|
||||
->addValue('description', $post_description)
|
||||
->addValue('articleBody', trim(preg_replace('/\s\s+/', ' ', strip_tags($content))));
|
||||
->addValue('articleBody', plain_text($content));
|
||||
|
||||
// breadcrumb json ld
|
||||
$listItems = [];
|
||||
@@ -161,7 +161,7 @@ private function injectBootstrapClasses($content)
|
||||
|
||||
if (strpos($pNode->text(), 'Q:') === 0) {
|
||||
$currentClasses = $pNode->attr('class');
|
||||
$newClasses = trim($currentClasses.' fw-bold');
|
||||
$newClasses = trim($currentClasses.' ');
|
||||
$pNode->getNode(0)->setAttribute('class', $newClasses);
|
||||
}
|
||||
});
|
||||
@@ -234,7 +234,7 @@ private function injectPublishDateAndAuthor($post, $content)
|
||||
$authorName = $post->author->name;
|
||||
|
||||
// Create the HTML structure for publish date and author
|
||||
$publishInfo = "<div class=\"mb-4\"><span class=\"text-secondary small\">Published on {$publishedAtFormatted} by {$authorName}</span></div>";
|
||||
$publishInfo = "<div class=\"mb-4\"><span class=\"text-secondary small\">Published on {$publishedAtFormatted} by {$authorName}<i class=\"bi bi-dot\"></i>" . markdown_min_read($post->body) . "</span></div>";
|
||||
|
||||
// Inject the publish date and author information after the `h1` tag
|
||||
$content = preg_replace('/(<\/h1>)/', '$1'.$publishInfo, $content, 1);
|
||||
|
||||
@@ -42,18 +42,14 @@ public static function handle(SerpUrl $serp_url)
|
||||
|
||||
$count = 0;
|
||||
|
||||
while ((!isset($ai_suggestion?->article_type)) || (!isset($ai_suggestion?->short_title)) || (!isset($ai_suggestion?->main_keyword)) || (!isset($ai_suggestion?->photo_keywords)) || (!isset($ai_suggestion?->description)) || (!isset($ai_suggestion?->title)))
|
||||
{
|
||||
if ($count >= 3)
|
||||
{
|
||||
Log::error(serialize($ai_suggestion));
|
||||
throw new Exception('Failed to generate ai_suggestion');
|
||||
}
|
||||
else
|
||||
{
|
||||
$count++;
|
||||
$ai_suggestion = OpenAI::createNewArticleTitle($serp_url->title, $serp_url->description);
|
||||
}
|
||||
while ((! isset($ai_suggestion?->article_type)) || (! isset($ai_suggestion?->short_title)) || (! isset($ai_suggestion?->main_keyword)) || (! isset($ai_suggestion?->photo_keywords)) || (! isset($ai_suggestion?->description)) || (! isset($ai_suggestion?->title))) {
|
||||
if ($count >= 3) {
|
||||
Log::error(serialize($ai_suggestion));
|
||||
throw new Exception('Failed to generate ai_suggestion');
|
||||
} else {
|
||||
$count++;
|
||||
$ai_suggestion = OpenAI::createNewArticleTitle($serp_url->title, $serp_url->description);
|
||||
}
|
||||
}
|
||||
|
||||
$readability_content = ScrapeUrlBodyTask::handle($serp_url->url);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -19,6 +20,11 @@ public function register(): void
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
Str::macro('readDuration', function (...$text) {
|
||||
$totalWords = str_word_count(implode(' ', $text));
|
||||
$minutesToRead = round($totalWords / 200);
|
||||
|
||||
return (int) max(1, $minutesToRead).' min read';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user