From 02cfe6e3728fef199438d9b045f3a523a58ebd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Rebours?= Date: Thu, 29 Feb 2024 16:27:58 +0100 Subject: [PATCH] Fix link of encrypted-card Add date and author to blog articles --- .../EncryptedItems/EncryptedBusinessCard.client.vue | 2 +- src/components/MetaOGImage.astro | 9 ++++++--- src/components/og-image.tsx | 8 ++++++-- src/pages/[lang]/blog/[slug]/index.astro | 7 +++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/components/EncryptedItems/EncryptedBusinessCard.client.vue b/src/components/EncryptedItems/EncryptedBusinessCard.client.vue index 860632f..74707e2 100644 --- a/src/components/EncryptedItems/EncryptedBusinessCard.client.vue +++ b/src/components/EncryptedItems/EncryptedBusinessCard.client.vue @@ -78,7 +78,7 @@ -
The content of this web page is end-2-end encrypted, for more details please read the related blog article.
+
The content of this web page is end-2-end encrypted, for more details please read the related blog article.
diff --git a/src/components/MetaOGImage.astro b/src/components/MetaOGImage.astro index 2350c7e..6fcc4a1 100644 --- a/src/components/MetaOGImage.astro +++ b/src/components/MetaOGImage.astro @@ -6,6 +6,7 @@ import { existsSync } from 'node:fs' import AstroConfig, { PWD } from '../../astro.config' import { PNG } from '~/utils/createImage' import ogImage from './og-image' +import { languages } from '~/i18n' export interface Props { title: string @@ -14,7 +15,8 @@ export interface Props { width?: number height?: number author?: string - date?: Date + date?: Date, + dateFormat?: keyof languages } const { @@ -24,7 +26,8 @@ const { author, date, width = 1200, - height = 630 + height = 630, + dateFormat } = Astro.props const generateHash = (input: string): string => { @@ -38,7 +41,7 @@ const ogDir = path.resolve(publicDir, 'og') if (!(existsSync(ogDir))) await mkdir(ogDir) -const options = { image: Buffer.from(image), title, description, author, date, width, height } +const options = { image: Buffer.from(image), title, description, author, date, width, height, dateFormat } const hash = generateHash(JSON.stringify({ ...options, image: options.image.toString('base64') })) diff --git a/src/components/og-image.tsx b/src/components/og-image.tsx index 973ee3a..25965c5 100644 --- a/src/components/og-image.tsx +++ b/src/components/og-image.tsx @@ -12,14 +12,18 @@ import { waterfall } from 'astro-pintora' // will fail. Using the waterfall makes sure they wait for each other to finish. // see: https://github.com/hikerpig/pintora/issues/237 and -export default waterfall(async ({ image, title, description, author, date, width = 1200, height = 630 }: { image: ArrayBuffer, title: string, description: string, width?: number, height?: number, author?: string, date?: Date }) => { +export default waterfall(async ({ image, title, description, author, date, width = 1200, height = 630, dateFormat }: { image: ArrayBuffer, title: string, description: string, width?: number, height?: number, author?: string, date?: Date, dateFormat: string }) => { const resizedImage = await sharp(Buffer.from(image)) .resize({ width: Math.floor(width / 3), height: 1.25 * Math.floor(width / 3), fit: 'cover' }) .png() .toBuffer() const b64ImageSrc = `data:image/png;base64,${resizedImage.toString('base64')}` - const dateString = date ? `${date.getDate().toString().padStart(2, '0')}/${(date.getMonth() + 1).toString().padStart(2, '0')}/${date.getFullYear().toString().padStart(4, '0')}` : undefined + const dateString = date ? + dateFormat === 'en' ? + `${(date.getMonth() + 1).toString().padStart(2, '0')}/${date.getDate().toString().padStart(2, '0')}/${date.getFullYear().toString().padStart(4, '0')}` : + `${date.getDate().toString().padStart(2, '0')}/${(date.getMonth() + 1).toString().padStart(2, '0')}/${date.getFullYear().toString().padStart(4, '0')}` : + undefined const frameWidth = 48 const imageMargin = 20 diff --git a/src/pages/[lang]/blog/[slug]/index.astro b/src/pages/[lang]/blog/[slug]/index.astro index 8daa09b..1b2a32e 100644 --- a/src/pages/[lang]/blog/[slug]/index.astro +++ b/src/pages/[lang]/blog/[slug]/index.astro @@ -50,8 +50,11 @@ const image = imageFilePath != null ? await readFile(imageFilePath) : undefined { (image != null) ? : <> }