From 7374d66a213f256b4af5cb574ce765302f53ca41 Mon Sep 17 00:00:00 2001 From: Charles Teh Date: Thu, 5 Oct 2023 00:29:23 +0800 Subject: [PATCH] Update (view): redesign --- app/Helpers/Global/string_helper.php | 22 ++++++++++++++ .../Controllers/Front/FrontPostController.php | 8 ++--- app/Jobs/Tasks/GenerateArticleTask.php | 20 +++++-------- app/Providers/AppServiceProvider.php | 8 ++++- resources/css/app-front.css | 11 +++++-- resources/sass/_variables.scss | 1 + .../front/layouts/partials/nav.blade.php | 7 +++-- .../views/front/partials/about.blade.php | 5 ++-- .../front/partials/post_detail.blade.php | 29 +++++++++++++------ resources/views/front/post_list.blade.php | 2 +- resources/views/front/single_post.blade.php | 5 ++-- resources/views/front/welcome.blade.php | 26 +++++++++++++---- .../simple-bootstrap-5-rounded.blade.php | 8 ++--- routes/web.php | 1 - 14 files changed, 104 insertions(+), 49 deletions(-) diff --git a/app/Helpers/Global/string_helper.php b/app/Helpers/Global/string_helper.php index 4fe9ab7..a59824f 100644 --- a/app/Helpers/Global/string_helper.php +++ b/app/Helpers/Global/string_helper.php @@ -1,5 +1,6 @@ getContent())); + } +} + if (! function_exists('unslug')) { function unslug($slug, $delimiter = '-') { diff --git a/app/Http/Controllers/Front/FrontPostController.php b/app/Http/Controllers/Front/FrontPostController.php index 6296881..2141067 100644 --- a/app/Http/Controllers/Front/FrontPostController.php +++ b/app/Http/Controllers/Front/FrontPostController.php @@ -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 = "
Published on {$publishedAtFormatted} by {$authorName}
"; + $publishInfo = "
Published on {$publishedAtFormatted} by {$authorName}" . markdown_min_read($post->body) . "
"; // Inject the publish date and author information after the `h1` tag $content = preg_replace('/(<\/h1>)/', '$1'.$publishInfo, $content, 1); diff --git a/app/Jobs/Tasks/GenerateArticleTask.php b/app/Jobs/Tasks/GenerateArticleTask.php index 70d0a13..1936bc7 100644 --- a/app/Jobs/Tasks/GenerateArticleTask.php +++ b/app/Jobs/Tasks/GenerateArticleTask.php @@ -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); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 452e6b6..f9d5465 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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'; + }); } } diff --git a/resources/css/app-front.css b/resources/css/app-front.css index ba67609..a928a04 100644 --- a/resources/css/app-front.css +++ b/resources/css/app-front.css @@ -1,15 +1,12 @@ .nav-scroller { position: relative; z-index: 2; - height: 2.75rem; overflow-y: hidden; } .nav-scroller .nav { display: flex; flex-wrap: nowrap; - padding-bottom: 1rem; - margin-top: -1px; overflow-x: auto; text-align: center; white-space: nowrap; @@ -35,3 +32,11 @@ img.lqip-blur { } /* lqip end */ + +a.link-body-emphasis { + text-decoration: none; + + &:hover { + text-decoration: none; + } +} diff --git a/resources/sass/_variables.scss b/resources/sass/_variables.scss index 48a2c60..49b3a43 100644 --- a/resources/sass/_variables.scss +++ b/resources/sass/_variables.scss @@ -4,6 +4,7 @@ // consistent naming. Ex: $nav-link-disabled-color and $modal-content-box-shadow-xs. // Color system +$body-bg: #f0f2f5; // scss-docs-start gray-color-variables $white: #fff; diff --git a/resources/views/front/layouts/partials/nav.blade.php b/resources/views/front/layouts/partials/nav.blade.php index 83f25ac..3edecea 100644 --- a/resources/views/front/layouts/partials/nav.blade.php +++ b/resources/views/front/layouts/partials/nav.blade.php @@ -1,4 +1,4 @@ -
+
@@ -10,8 +10,9 @@
-