Skip to content

Commit

Permalink
Implement language filter for getBlogPosts method
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek committed Jun 1, 2024
1 parent 84fb39f commit a896efb
Showing 1 changed file with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,24 @@ export class BlogRepository {
return createOk(new BlogContent(metadata, body, language));
}

public async getBlogs(): Promise<Result<BlogContent[], Error>> {
public async getBlogs(
language: Language,
): Promise<Result<BlogContent[], Error>> {
const blogPaths = await this._fs.readdir(
this._path.resolve(
process.cwd(),
"packages/applications/turbo-blog/src/articles/public",
),
);
const blogEnPaths = await this._fs.readdir(
this._path.resolve(
process.cwd(),
"packages/applications/turbo-blog/src/articles/en",
language === Language.ja
? "packages/applications/turbo-blog/src/articles/public"
: "packages/applications/turbo-blog/src/articles/en",
),
);

const blogsJa = await Promise.all(
const blogResults = await Promise.all(
blogPaths.map(async (blogPath) => {
return this.getBlog(blogPath, Language.ja);
return this.getBlog(blogPath, language);
}),
);

const blogsEn = await Promise.all(
blogEnPaths.map(async (blogPath) => {
return this.getBlog(blogPath, Language.en);
}),
);

const blogResults = [...blogsJa, ...blogsEn];

const blogErrs = blogResults.filter(isErr);

if (blogErrs.length > 0) {
Expand Down

0 comments on commit a896efb

Please sign in to comment.