feat(blog): isolate articles by locale and add initial english posts
This commit is contained in:
+7
-2
@@ -12,6 +12,7 @@ export type BlogDetail = {
|
||||
excerpt: string;
|
||||
coverImage: string;
|
||||
markdown: string;
|
||||
lang: "tr" | "en";
|
||||
};
|
||||
|
||||
const BLOG_CONTENT_DIR = path.join(process.cwd(), "content", "blog");
|
||||
@@ -40,10 +41,11 @@ function mapMarkdownToBlogDetail(fileName: string, raw: string): BlogDetail {
|
||||
excerpt: toSafeString(parsed.data.excerpt, ""),
|
||||
coverImage: toSafeString(parsed.data.coverImage, "/news/design.svg"),
|
||||
markdown: parsed.content.trim(),
|
||||
lang: toSafeString(parsed.data.lang, "tr") as "tr" | "en",
|
||||
};
|
||||
}
|
||||
|
||||
export async function listBlogDetails(): Promise<BlogDetail[]> {
|
||||
export async function listBlogDetails(locale?: string): Promise<BlogDetail[]> {
|
||||
let files: string[] = [];
|
||||
try {
|
||||
files = await fs.readdir(BLOG_CONTENT_DIR);
|
||||
@@ -60,7 +62,10 @@ export async function listBlogDetails(): Promise<BlogDetail[]> {
|
||||
}),
|
||||
);
|
||||
|
||||
return posts.sort((a, b) => a.slug.localeCompare(b.slug));
|
||||
const targetLang = locale || "tr";
|
||||
return posts
|
||||
.filter((post) => post.lang === targetLang)
|
||||
.sort((a, b) => a.slug.localeCompare(b.slug));
|
||||
}
|
||||
|
||||
export async function getBlogDetailBySlug(slug: string): Promise<BlogDetail | null> {
|
||||
|
||||
+6
-5
@@ -54,8 +54,8 @@ function normalizeCategory(value: string) {
|
||||
return value.trim().toLocaleLowerCase();
|
||||
}
|
||||
|
||||
export async function getAllBlogArticles(): Promise<BlogArticleItem[]> {
|
||||
const posts = await listBlogDetails();
|
||||
export async function getAllBlogArticles(locale?: string): Promise<BlogArticleItem[]> {
|
||||
const posts = await listBlogDetails(locale);
|
||||
|
||||
const articles = posts.map((post) => ({
|
||||
id: post.slug,
|
||||
@@ -73,8 +73,8 @@ export async function getAllBlogArticles(): Promise<BlogArticleItem[]> {
|
||||
return sortByDateDesc(articles);
|
||||
}
|
||||
|
||||
export async function getHomeBlogNews(limit = 3) {
|
||||
const articles = await getAllBlogArticles();
|
||||
export async function getHomeBlogNews(locale?: string, limit = 3) {
|
||||
const articles = await getAllBlogArticles(locale);
|
||||
|
||||
return articles.slice(0, limit).map((item) => ({
|
||||
id: `home-news-${item.slug}`,
|
||||
@@ -87,12 +87,13 @@ export async function getHomeBlogNews(limit = 3) {
|
||||
}
|
||||
|
||||
export async function getBlogPageData(
|
||||
locale?: string,
|
||||
page = 1,
|
||||
pageSize = 12,
|
||||
selectedCategoryParam?: string,
|
||||
searchQueryParam?: string,
|
||||
): Promise<BlogPageData> {
|
||||
const articles = await getAllBlogArticles();
|
||||
const articles = await getAllBlogArticles(locale);
|
||||
const categories = BLOG_CATEGORIES;
|
||||
const categoryByNormalized = new Map(
|
||||
categories.map((category) => [normalizeCategory(category), category]),
|
||||
|
||||
Reference in New Issue
Block a user