✨ Better open graph
This commit is contained in:
parent
dfe6198b94
commit
d4670bb543
@ -39,12 +39,17 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const props = defineProps<{ attachments: number[] }>()
|
const props = defineProps<{ attachments: number[] }>()
|
||||||
|
const emits = defineEmits(["update:metadata"])
|
||||||
|
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
|
|
||||||
const { data } = await useFetch<any>(`${config.public.solarNetworkApi}/cgi/files/attachments?take=${props.attachments.length}&id=${props.attachments.join(",")}`)
|
const { data } = await useFetch<any>(`${config.public.solarNetworkApi}/cgi/files/attachments?take=${props.attachments.length}&id=${props.attachments.join(",")}`)
|
||||||
const metadata = computed(() => data.value.data)
|
const metadata = computed(() => data.value.data)
|
||||||
|
|
||||||
|
watch(metadata, (value) => {
|
||||||
|
emits("update:metadata", value)
|
||||||
|
}, { deep: true, immediate: true })
|
||||||
|
|
||||||
function getAttachmentUrl(id: number) {
|
function getAttachmentUrl(id: number) {
|
||||||
return `${config.public.solarNetworkApi}/cgi/files/attachments/${id}`
|
return `${config.public.solarNetworkApi}/cgi/files/attachments/${id}`
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
</article>
|
</article>
|
||||||
|
|
||||||
<v-card v-if="post.body?.attachments?.length > 0" class="mb-5">
|
<v-card v-if="post.body?.attachments?.length > 0" class="mb-5">
|
||||||
<attachment-carousel :attachments="post.body?.attachments" />
|
<attachment-carousel :attachments="post.body?.attachments" @update:metadata="args => attachments = args" />
|
||||||
</v-card>
|
</v-card>
|
||||||
|
|
||||||
<div class="mb-3 text-sm flex flex-col">
|
<div class="mb-3 text-sm flex flex-col">
|
||||||
@ -56,16 +56,34 @@
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
|
|
||||||
|
const attachments = ref<any[]>([])
|
||||||
|
const firstImage = ref<string|null>()
|
||||||
|
const firstVideo = ref<string|null>()
|
||||||
|
|
||||||
const { data: post } = await useFetch<any>(`${config.public.solarNetworkApi}/cgi/interactive/posts/${route.params.id}`)
|
const { data: post } = await useFetch<any>(`${config.public.solarNetworkApi}/cgi/interactive/posts/${route.params.id}`)
|
||||||
|
|
||||||
if (!post.value) {
|
if (!post.value) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: 404,
|
statusCode: 404,
|
||||||
statusMessage: 'Post Not Found'
|
statusMessage: "Post Not Found",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = computed(() => post.value.body?.title ? `${post.value.body?.title} from ${post.value.author.nick}` : `Post from ${post.value.author.nick}`)
|
const title = computed(() => post.value.body?.title ? `${post.value.body?.title} from ${post.value.author.nick}` : `Post from ${post.value.author.nick}`)
|
||||||
|
const description = computed(() => post.value.body?.description ?? post.value.body?.content.substring(0, 160).trim())
|
||||||
|
|
||||||
|
watch(attachments, (value) => {
|
||||||
|
if (post.value.body?.thumbnail) {
|
||||||
|
firstImage.value = `${config.public.solarNetworkApi}/cgi/files/attachments/${post.value.body?.thumbnail}`
|
||||||
|
}
|
||||||
|
if (value.length > 0 && value[0].mimetype.split("/")[0] == "image") {
|
||||||
|
firstImage.value = `${config.public.solarNetworkApi}/cgi/files/attachments/${attachments.value[0].id}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.length > 0 && value[0].mimetype.split("/")[0] == "video") {
|
||||||
|
firstVideo.value = `${config.public.solarNetworkApi}/cgi/files/attachments/${attachments.value[0].id}`
|
||||||
|
}
|
||||||
|
}, { immediate: true, deep: true })
|
||||||
|
|
||||||
useHead({
|
useHead({
|
||||||
title: title.value,
|
title: title.value,
|
||||||
@ -78,14 +96,15 @@ useHead({
|
|||||||
|
|
||||||
useSeoMeta({
|
useSeoMeta({
|
||||||
author: post.value.author.nick,
|
author: post.value.author.nick,
|
||||||
title: title.value,
|
title: title,
|
||||||
publisher: "Solar Network",
|
publisher: "Solar Network",
|
||||||
articlePublishedTime: post.value.publishedAt,
|
articlePublishedTime: post.value.publishedAt,
|
||||||
description: post.value.body?.description ?? post.value.body?.content.substring(0, 160).trim(),
|
description: description,
|
||||||
ogTitle: title.value,
|
ogTitle: title,
|
||||||
ogDescription: post.value.body?.description ?? post.value.body?.content.substring(0, 160).trim(),
|
ogDescription: description,
|
||||||
ogUrl: `${useRuntimeConfig().public.siteUrl}/${route.fullPath}`,
|
ogUrl: `${useRuntimeConfig().public.siteUrl}${route.fullPath}`,
|
||||||
ogImage: post.value.body?.thumbnail ? `${config.public.solarNetworkApi}/cgi/files/attachments/${post.value.body?.thumbnail}` : null,
|
ogImage: firstImage,
|
||||||
|
ogVideo: firstVideo,
|
||||||
})
|
})
|
||||||
|
|
||||||
const externalOpenLink = computed(() => `${config.public.solianUrl}/posts/view/${route.params.id}`)
|
const externalOpenLink = computed(() => `${config.public.solianUrl}/posts/view/${route.params.id}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user