Skip to content

Commit

Permalink
优化:网站内容页面seo优化
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Jun 11, 2023
1 parent 0780954 commit 8f34236
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends("App::app")

@section('title',$data->title)
@section('description','「关于'.$data->title."」帖子的相关信息")
@section('description',get_content_brief($data->post->content)?:'「关于'.$data->title."」帖子的相关信息")
@section('keywords',$data->title.','.$data->user->username)

@section('content')
Expand Down
18 changes: 18 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1017,3 +1017,21 @@ function get_file_content($file): bool | string
return $content;
}
}

// 截取内容摘要
if (! function_exists('get_content_brief')) {
function get_content_brief($content, $len = 200): string
{
if (@! $content) {
return $content;
}
$len = (int) $len;
// hook post_brief_start.php
$content = strip_tags($content);
$content = htmlspecialchars($content);
$content = remove_bbCode($content) ?: '';
$content = \Hyperf\Utils\Str::limit($content, $len);
$content = trim(preg_replace('/\s+/', ' ', $content));
return htmlspecialchars_decode($content, ENT_QUOTES);
}
}

0 comments on commit 8f34236

Please sign in to comment.