adding alternative language versions to article metadata

This commit is contained in:
2026-05-05 09:35:27 +02:00
parent 62dd29e3cb
commit 0af590fd26
7 changed files with 72 additions and 34 deletions
+21
View File
@@ -1,6 +1,8 @@
import fs from "node:fs";
import path from "node:path";
import matter from "gray-matter";
import { locales } from "@/middleware";
import { Article, ArticleFrontmatter } from "./types";
const CONTENT_DIR = path.join(process.cwd(), "content/blog");
@@ -42,3 +44,22 @@ export function getAllArticles(locale: string): Article[] {
.filter((article): article is Article => article !== null && article.ready)
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
}
export function getAlternatesArticle(article: Article) {
if (!article.translationKey) {
return {};
}
return locales.reduce<Record<string, string>>((acc, locale) => {
const translatedArticle = getAllArticles(locale).find(
(candidate) =>
candidate.translationKey === article.translationKey
);
if (translatedArticle) {
acc[locale] = `/${locale}/blog/${translatedArticle.slug}`;
}
return acc;
}, {});
}