From 4d21f3463a8ffcb94df71fd3d896691b8ba98f1b Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 19 Dec 2024 23:17:47 +0800 Subject: [PATCH] :mag: Optimize post SEO --- src/pages/posts/[...slug].astro | 73 +++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 6ccdc02..02ee277 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -3,7 +3,7 @@ export const prerender = false import sanitizeHtml from 'sanitize-html' import { Icon } from 'astro-icon/components' -import {SEO} from 'astro-seo' +import { SEO } from 'astro-seo' import { marked } from 'marked' import Layout from '@/layouts/Layout.astro' @@ -30,33 +30,54 @@ const attachments = await fetchAttachmentMeta(data.body.attachments) --- - a.mimetype.startsWith('image'))?.rid), - url: `https://solsynth.dev/posts/${data.id}` - }, - article: { - publishedTime: new Date(data.created_at).toISOString(), - modifiedTime: new Date(data.updated_at).toISOString(), - authors: ["@"+data.publisher.name], - } - }} - twitter={{ - card: "summary_large_image", - title: data.body?.title ? data.body.title : `Post #${data.id}`, - description: data.body?.content, - creator: "@"+data.publisher.name, - image: data.body?.thumbnail ? getAttachmentUrl(data.body.thumbnail) : getAttachmentUrl(attachments.find(a => a.mimetype.startsWith('image'))?.rid), - }} - /> + a.mimetype.startsWith('video'))?.rid + ), + audio: getAttachmentUrl( + attachments.find((a) => a.mimetype.startsWith('audio'))?.rid + ), + }, + basic: { + title: data.body?.title ? data.body.title : `Post #${data.id}`, + type: 'article', + image: data.body?.thumbnail + ? getAttachmentUrl(data.body.thumbnail) + : getAttachmentUrl( + attachments.find((a) => a.mimetype.startsWith('image'))?.rid + ), + url: `https://solsynth.dev/posts/${data.id}`, + }, + article: { + publishedTime: new Date(data.created_at).toISOString(), + modifiedTime: new Date(data.updated_at).toISOString(), + authors: ['@' + data.publisher.name], + }, + }} + twitter={{ + card: 'summary_large_image', + title: data.body?.title ? data.body.title : `Post #${data.id}`, + description: data.body?.description, + creator: '@' + data.publisher.name, + image: data.body?.thumbnail + ? getAttachmentUrl(data.body.thumbnail) + : getAttachmentUrl( + attachments.find((a) => a.mimetype.startsWith('image'))?.rid + ), + }} + /> - +