diff --git a/app/Filament/Pages/BlogSettings.php b/app/Filament/Pages/BlogSettings.php index 01f3a27..ab94021 100644 --- a/app/Filament/Pages/BlogSettings.php +++ b/app/Filament/Pages/BlogSettings.php @@ -64,6 +64,13 @@ class BlogSettings extends Page // 维护 'site_closed' => Setting::get('site_closed', '0'), 'site_closed_note' => Setting::get('site_closed_note', ''), + // 社交账号 + 'social_weibo' => Setting::get('social_weibo', ''), + 'social_github' => Setting::get('social_github', ''), + 'social_twitter' => Setting::get('social_twitter', ''), + 'social_facebook' => Setting::get('social_facebook', ''), + 'social_zhihu' => Setting::get('social_zhihu', ''), + 'social_email' => Setting::get('social_email', ''), ]); } @@ -119,6 +126,16 @@ class BlogSettings extends Page TextInput::make('watermark_size')->label('水印触发尺寸')->placeholder('300x300'), TextInput::make('watermarktrans')->label('水印透明度(%)')->numeric(), ]), + Tab::make('社交账号') + ->columns(2) + ->schema([ + TextInput::make('social_weibo')->label('微博')->url()->placeholder('https://weibo.com/xxx'), + TextInput::make('social_github')->label('GitHub')->url()->placeholder('https://github.com/xxx'), + TextInput::make('social_twitter')->label('Twitter / X')->url()->placeholder('https://x.com/xxx'), + TextInput::make('social_facebook')->label('Facebook')->url()->placeholder('https://facebook.com/xxx'), + TextInput::make('social_zhihu')->label('知乎')->url()->placeholder('https://zhihu.com/people/xxx'), + TextInput::make('social_email')->label('邮箱')->email()->placeholder('contact@example.com'), + ]), Tab::make('维护') ->schema([ Toggle::make('site_closed')->label('关闭站点')->default(false), diff --git a/plugins/neatstudio.blog-seo/src/Http/Middleware/SeoMiddleware.php b/plugins/neatstudio.blog-seo/src/Http/Middleware/SeoMiddleware.php index d97e5c3..ab36125 100644 --- a/plugins/neatstudio.blog-seo/src/Http/Middleware/SeoMiddleware.php +++ b/plugins/neatstudio.blog-seo/src/Http/Middleware/SeoMiddleware.php @@ -60,6 +60,7 @@ class SeoMiddleware private function structuredData(Request $request): array { $siteName = blog_setting('site_name', config('blog.name')); + $sameAs = $this->socialLinks(); $route = $request->route(); @@ -70,18 +71,24 @@ class SeoMiddleware }); if ($post && $post->status === 'published') { - return [ + $data = [ '@context' => 'https://schema.org', '@type' => 'BlogPosting', 'headline' => $post->title, 'url' => route('posts.show', $post->slug ?: $post->id), 'datePublished' => $post->published_at?->toIso8601String(), 'dateModified' => $post->updated_at?->toIso8601String(), - 'author' => ['@type' => 'Person', 'name' => $post->author?->name ?? $siteName], - 'publisher' => ['@type' => 'Organization', 'name' => $siteName], + 'author' => ['@type' => 'Person', 'name' => $post->author?->name ?? $siteName] + ($sameAs ? ['sameAs' => $sameAs] : []), + 'publisher' => ['@type' => 'Organization', 'name' => $siteName, 'url' => url('/')] + ($sameAs ? ['sameAs' => $sameAs] : []), 'description' => Str::limit(strip_tags($post->excerpt_or_fallback), 200), 'mainEntityOfPage' => route('posts.show', $post->slug ?: $post->id), ]; + + if ($cover = $post->getFirstMedia('cover')) { + $data['image'] = [$cover->getUrl('card') ?: $cover->getUrl()]; + } + + return $data; } } @@ -90,26 +97,52 @@ class SeoMiddleware '@type' => 'WebSite', 'name' => $siteName, 'url' => url('/'), - ]; + ] + ($sameAs ? ['sameAs' => $sameAs] : []); + } + + /** + * 后台配置的社交账号 -> schema sameAs(Facebook / GitHub / Twitter 等平台识别)。 + */ + private function socialLinks(): array + { + $links = []; + + foreach (['social_weibo', 'social_github', 'social_twitter', 'social_facebook', 'social_zhihu'] as $key) { + if ($url = blog_setting($key, '')) { + $links[] = $url; + } + } + + return array_values(array_unique($links)); } private function ogTags(Request $request, array $data): string { $siteName = blog_setting('site_name', config('blog.name')); $isArticle = ($data['@type'] ?? '') === 'BlogPosting'; + $image = $data['image'][0] ?? null; $tags = [ '', + '', '', '', '', '', - '', + '', '', + '', ]; + if ($image) { + $tags[] = ''; + $tags[] = ''; + $tags[] = ''; + } + if ($isArticle) { $tags[] = ''; + $tags[] = ''; } return implode("\n", $tags); diff --git a/storage/media-library/temp/UbDeFqsC2Rjow2qEXFWMljuEOUgmXfDj/1FPjotBUcPiaG4jIesWlXyqa3RNRAwZa.jpg b/storage/media-library/temp/UbDeFqsC2Rjow2qEXFWMljuEOUgmXfDj/1FPjotBUcPiaG4jIesWlXyqa3RNRAwZa.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/UbDeFqsC2Rjow2qEXFWMljuEOUgmXfDj/1FPjotBUcPiaG4jIesWlXyqa3RNRAwZa.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file diff --git a/storage/media-library/temp/UbDeFqsC2Rjow2qEXFWMljuEOUgmXfDj/ZVRR8Ytli07QqiZ6EfpED8IERlA7u349thumb.jpg b/storage/media-library/temp/UbDeFqsC2Rjow2qEXFWMljuEOUgmXfDj/ZVRR8Ytli07QqiZ6EfpED8IERlA7u349thumb.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/UbDeFqsC2Rjow2qEXFWMljuEOUgmXfDj/ZVRR8Ytli07QqiZ6EfpED8IERlA7u349thumb.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file diff --git a/storage/media-library/temp/cqJCkHhsbsobTEn7ItrRMClKuGJ1JgtJ/oNksN3TuGkpedcsH7ycgCBgRcwbdZB3gthumb.jpg b/storage/media-library/temp/cqJCkHhsbsobTEn7ItrRMClKuGJ1JgtJ/oNksN3TuGkpedcsH7ycgCBgRcwbdZB3gthumb.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/cqJCkHhsbsobTEn7ItrRMClKuGJ1JgtJ/oNksN3TuGkpedcsH7ycgCBgRcwbdZB3gthumb.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file diff --git a/storage/media-library/temp/cqJCkHhsbsobTEn7ItrRMClKuGJ1JgtJ/viI8YaTCx2EtUo8tA3ZJNfLyXN4T5Pl4.jpg b/storage/media-library/temp/cqJCkHhsbsobTEn7ItrRMClKuGJ1JgtJ/viI8YaTCx2EtUo8tA3ZJNfLyXN4T5Pl4.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/cqJCkHhsbsobTEn7ItrRMClKuGJ1JgtJ/viI8YaTCx2EtUo8tA3ZJNfLyXN4T5Pl4.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file diff --git a/storage/media-library/temp/f2YIkQUCJ5XH97YPYIu2RhQpL3GkjBUv/1L4C3qm4BKgSKiDD8YyTpRShGRPCzgrM.jpg b/storage/media-library/temp/f2YIkQUCJ5XH97YPYIu2RhQpL3GkjBUv/1L4C3qm4BKgSKiDD8YyTpRShGRPCzgrM.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/f2YIkQUCJ5XH97YPYIu2RhQpL3GkjBUv/1L4C3qm4BKgSKiDD8YyTpRShGRPCzgrM.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file diff --git a/storage/media-library/temp/f2YIkQUCJ5XH97YPYIu2RhQpL3GkjBUv/puc9BLe5VYABb0GIBV2p57vrHr2DsiQVthumb.jpg b/storage/media-library/temp/f2YIkQUCJ5XH97YPYIu2RhQpL3GkjBUv/puc9BLe5VYABb0GIBV2p57vrHr2DsiQVthumb.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/f2YIkQUCJ5XH97YPYIu2RhQpL3GkjBUv/puc9BLe5VYABb0GIBV2p57vrHr2DsiQVthumb.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file diff --git a/storage/media-library/temp/k1vkWEqjtiuYJxazhxe1iEF7rl6tppzN/48IvYjo3X6xmFw6aWxoawj8vrAHdOL9qthumb.jpg b/storage/media-library/temp/k1vkWEqjtiuYJxazhxe1iEF7rl6tppzN/48IvYjo3X6xmFw6aWxoawj8vrAHdOL9qthumb.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/k1vkWEqjtiuYJxazhxe1iEF7rl6tppzN/48IvYjo3X6xmFw6aWxoawj8vrAHdOL9qthumb.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file diff --git a/storage/media-library/temp/k1vkWEqjtiuYJxazhxe1iEF7rl6tppzN/Rn3OQa8JrYo0vuQGgt732id4Sw25Nk7f.jpg b/storage/media-library/temp/k1vkWEqjtiuYJxazhxe1iEF7rl6tppzN/Rn3OQa8JrYo0vuQGgt732id4Sw25Nk7f.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/k1vkWEqjtiuYJxazhxe1iEF7rl6tppzN/Rn3OQa8JrYo0vuQGgt732id4Sw25Nk7f.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file diff --git a/storage/media-library/temp/p0ECg8NW2LpZdbYlDLy34VGu57GxXbOE/YWw4ZG1b9U5FtuxhRvbrrxCf80Wsxfl2.jpg b/storage/media-library/temp/p0ECg8NW2LpZdbYlDLy34VGu57GxXbOE/YWw4ZG1b9U5FtuxhRvbrrxCf80Wsxfl2.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/p0ECg8NW2LpZdbYlDLy34VGu57GxXbOE/YWw4ZG1b9U5FtuxhRvbrrxCf80Wsxfl2.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file diff --git a/storage/media-library/temp/p0ECg8NW2LpZdbYlDLy34VGu57GxXbOE/qUZFsfr06gNkuu9OFh9NWywk8T3UiOQVthumb.jpg b/storage/media-library/temp/p0ECg8NW2LpZdbYlDLy34VGu57GxXbOE/qUZFsfr06gNkuu9OFh9NWywk8T3UiOQVthumb.jpg new file mode 100644 index 0000000..7e754f4 --- /dev/null +++ b/storage/media-library/temp/p0ECg8NW2LpZdbYlDLy34VGu57GxXbOE/qUZFsfr06gNkuu9OFh9NWywk8T3UiOQVthumb.jpg @@ -0,0 +1 @@ +fake-jpg \ No newline at end of file