diff options
| -rw-r--r-- | src/components/BaseHead.astro | 28 | ||||
| -rw-r--r-- | src/content.config.ts | 1 | ||||
| -rw-r--r-- | src/layouts/Base.astro | 12 | ||||
| -rw-r--r-- | src/loaders/pleroma.ts | 2 | ||||
| -rw-r--r-- | src/pages/micro/[...slug].astro | 2 | ||||
| -rw-r--r-- | src/types.ts | 1 |
6 files changed, 41 insertions, 5 deletions
diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index cb39d4a..40f1d20 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -6,12 +6,36 @@ import "@/styles/global.css"; type Props = SiteMeta; -const { articleDate, description, ogImage, title } = Astro.props; +const { articleDate, description, ogImage, title, lang } = Astro.props; const titleSeparator = "•"; const siteTitle = `${title} ${titleSeparator} ${siteConfig.title}`; const canonicalURL = new URL(Astro.url.pathname, Astro.site); const socialImageURL = new URL(ogImage ? ogImage : "/social-card.png", Astro.url).href; + +// Map ISO 639-1 language codes to og:locale format +function getOgLocale(langCode?: string): string { + if (!langCode) return siteConfig.ogLocale; + + const localeMap: Record<string, string> = { + en: "en_US", + pl: "pl_PL", + es: "es_ES", + fr: "fr_FR", + de: "de_DE", + it: "it_IT", + pt: "pt_PT", + nl: "nl_NL", + ru: "ru_RU", + ja: "ja_JP", + zh: "zh_CN", + ko: "ko_KR", + }; + + return localeMap[langCode] || siteConfig.ogLocale; +} + +const ogLocale = getOgLocale(lang); --- <meta charset="utf-8" /> @@ -46,7 +70,7 @@ const socialImageURL = new URL(ogImage ? ogImage : "/social-card.png", Astro.url <meta content={description} property="og:description" /> <meta content={canonicalURL} property="og:url" /> <meta content={siteConfig.title} property="og:site_name" /> -<meta content={siteConfig.ogLocale} property="og:locale" /> +<meta content={ogLocale} property="og:locale" /> <meta content={socialImageURL} property="og:image" /> <meta content="1200" property="og:image:width" /> <meta content="630" property="og:image:height" /> diff --git a/src/content.config.ts b/src/content.config.ts index 5e15713..bee2f8c 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -48,6 +48,7 @@ const micro = defineCollection({ description: z.string().optional(), publishDate: z.date().or(z.string().transform((val) => new Date(val))), sourceUrl: z.string().optional(), + language: z.string().optional(), author: z .object({ username: z.string(), diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index 41a56dd..fe5c064 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -12,13 +12,19 @@ interface Props { } const { - meta: { articleDate, description = siteConfig.description, ogImage, title }, + meta: { articleDate, description = siteConfig.description, ogImage, title, lang }, } = Astro.props; --- -<html class="scroll-smooth" lang={siteConfig.lang}> +<html class="scroll-smooth" lang={lang ?? siteConfig.lang}> <head> - <BaseHead articleDate={articleDate} description={description} ogImage={ogImage} title={title} /> + <BaseHead + articleDate={articleDate} + description={description} + ogImage={ogImage} + title={title} + {...lang ? { lang } : {}} + /> </head> <body class="bg-global-bg text-global-text mx-auto flex min-h-screen max-w-3xl flex-col px-4 pt-16 font-mono text-sm font-normal antialiased sm:px-8" diff --git a/src/loaders/pleroma.ts b/src/loaders/pleroma.ts index 6b5b2f5..0fd839f 100644 --- a/src/loaders/pleroma.ts +++ b/src/loaders/pleroma.ts @@ -43,6 +43,7 @@ interface PleromaStatus { media_attachments: PleromaMediaAttachment[]; visibility: string; account: PleromaAccount; + language?: string | null; } /** @@ -709,6 +710,7 @@ export function pleromaLoader(config: PleromaFeedConfig): Loader { sourceUrl, author, attachments, + language: status.language || undefined, }, body: cleanedContent, rendered: { diff --git a/src/pages/micro/[...slug].astro b/src/pages/micro/[...slug].astro index 4cfae32..681c106 100644 --- a/src/pages/micro/[...slug].astro +++ b/src/pages/micro/[...slug].astro @@ -3,6 +3,7 @@ import { getCollection } from "astro:content"; import type { GetStaticPaths, InferGetStaticPropsType } from "astro"; import Note from "@/components/note/Note.astro"; import PageLayout from "@/layouts/Base.astro"; +import { siteConfig } from "@/site.config"; // if you're using an adaptor in SSR mode, getStaticPaths wont work -> https://docs.astro.build/en/guides/routing/#modifying-the-slug-example-for-ssr export const getStaticPaths = (async () => { @@ -24,6 +25,7 @@ const meta = { note.data.description || `Read about my note posted on: ${note.data.publishDate.toLocaleDateString()}`, title: note.data.title, + lang: note.data.language || siteConfig.lang, }; --- diff --git a/src/types.ts b/src/types.ts index f2abc0f..303ad03 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,6 +22,7 @@ export interface SiteMeta { description?: string; ogImage?: string | undefined; title: string; + lang?: string; } /** Webmentions */ |
