From fd6b1b10fd3b80e46b22845df8b364db920e7369 Mon Sep 17 00:00:00 2001 From: Skystryder Date: Sat, 28 Jan 2023 16:47:26 -0800 Subject: [PATCH] Proper support for image types in notes, opengraph images and videos. Progress toward https://codeberg.org/calckey/calckey/issues/9373 --- packages/backend/src/server/web/views/note.pug | 13 ++++++++++++- .../client/src/components/MkImgWithBlurhash.vue | 4 +++- packages/client/src/components/MkMediaImage.vue | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/web/views/note.pug b/packages/backend/src/server/web/views/note.pug index 6b55f6ba03..b2dc5f63fd 100644 --- a/packages/backend/src/server/web/views/note.pug +++ b/packages/backend/src/server/web/views/note.pug @@ -5,6 +5,9 @@ block vars - const title = privateMode ? instanceName : (user.name ? `${user.name} (@${user.username})` : `@${user.username}`); - const url = `${config.url}/notes/${note.id}`; - const isRenote = note.renote && note.text == null && note.fileIds.length == 0 && note.poll == null; + - const isImage = note.files.length !== 0 && note.files[0].type.startsWith('image'); + - const isVideo = note.files.length !== 0 && note.files[0].type.startsWith('video'); + - const imageUrl = isImage ? note.files[0].url : isVideo ? note.files[0].thumbnailUrl : avatarUrl; block title = `${title} | ${instanceName}` @@ -19,7 +22,15 @@ block og meta(property='og:title' content= title) meta(property='og:description' content= summary) meta(property='og:url' content= url) - meta(property='og:image' content= avatarUrl) + meta(property='og:image' content= imageUrl) + if isImage + meta(property='og:image:width' content=note.files[0].properties.width) + meta(property='og:image:height' content=note.files[0].properties.height) + meta(property='og:image:type' content=note.files[0].type) + meta(property='twitter:card' content="summary_large_image") + if isVideo + meta(property='og:video:type' content=note.files[0].type) + meta(property='og:video' content=note.files[0].url) block meta unless privateMode diff --git a/packages/client/src/components/MkImgWithBlurhash.vue b/packages/client/src/components/MkImgWithBlurhash.vue index 80d7c201a4..b6eae622d9 100644 --- a/packages/client/src/components/MkImgWithBlurhash.vue +++ b/packages/client/src/components/MkImgWithBlurhash.vue @@ -1,7 +1,7 @@ @@ -13,11 +13,13 @@ const props = withDefaults(defineProps<{ src?: string | null; hash?: string; alt?: string; + type?: string | null; title?: string | null; size?: number; cover?: boolean; }>(), { src: null, + type: null, alt: '', title: null, size: 64, diff --git a/packages/client/src/components/MkMediaImage.vue b/packages/client/src/components/MkMediaImage.vue index f913c1a2ec..5cf851d6b5 100644 --- a/packages/client/src/components/MkMediaImage.vue +++ b/packages/client/src/components/MkMediaImage.vue @@ -13,7 +13,7 @@ :href="image.url" :title="image.name" > - +
GIF