-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a896efb
commit fff77c2
Showing
8 changed files
with
61 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 7 additions & 33 deletions
40
packages/applications/turbo-blog/src/build/application/getBlogPosts/getBlogposts.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,16 @@ | ||
import type { Result } from "option-t/esm/PlainResult"; | ||
import type { BlogContent } from "../../model/blog/blog.entity"; | ||
import type { BlogRepository } from "../../model/blog/blog.repository"; | ||
import { Language } from "../../model/language/language.entity"; | ||
import { M17NContents } from "../../model/m17n/m17n.entity"; | ||
import type { Language } from "../../model/language/language.entity"; | ||
|
||
export class GetBlogPostsUsecase { | ||
constructor(private blogPostRepository: BlogRepository) {} | ||
|
||
async getBlogPosts(): Promise<M17NContents<BlogContent>[]> { | ||
const blogPosts = await this.blogPostRepository.getBlogs(); | ||
const ja = blogPosts.filter( | ||
(blogPost) => blogPost.language === Language.ja, | ||
); | ||
const en = blogPosts.filter( | ||
(blogPost) => blogPost.language === Language.en, | ||
); | ||
async getBlogPosts( | ||
language: Language, | ||
): Promise<Result<BlogContent[], Error>> { | ||
const blogPosts = await this.blogPostRepository.getBlogs(language); | ||
|
||
const contents: M17NContents<BlogContent>[] = []; | ||
|
||
for (const blogPost of ja) { | ||
const existingContent = en.find( | ||
(content) => content.metadata.title === blogPost.metadata.title, | ||
); | ||
if (existingContent) { | ||
contents.push(new M17NContents(blogPost, existingContent)); | ||
} else { | ||
contents.push(new M17NContents(blogPost, undefined)); | ||
} | ||
} | ||
|
||
for (const blogPost of en) { | ||
const existingContent = ja.find( | ||
(content) => content.metadata.title === blogPost.metadata.title, | ||
); | ||
if (!existingContent) { | ||
contents.push(new M17NContents(undefined, blogPost)); | ||
} | ||
} | ||
|
||
return contents; | ||
return blogPosts; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import type { Language } from "../model/language/language.entity"; | ||
|
||
export type Context = { | ||
language: "ja" | "en"; | ||
language: Language; | ||
}; |
18 changes: 14 additions & 4 deletions
18
packages/applications/turbo-blog/src/build/handlers/index/generate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import type { Plugin } from "ssg-router"; | ||
import type { Context } from "../context/context"; | ||
import { Language } from "../model/language/language.entity"; | ||
|
||
export const registerLanguagePlugin: Plugin<Context> = { | ||
async onRouted(_, context) { | ||
context.language = "ja"; | ||
context.language = Language.ja; | ||
}, | ||
}; |
24 changes: 23 additions & 1 deletion
24
packages/applications/turbo-blog/src/ui/pages/Home/Home.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
import type { FunctionComponent } from "react"; | ||
import { Item } from "./components/Item/Item"; | ||
import { WelcomePage } from "./components/WelcomePage/WelcomePage"; | ||
|
||
export const Home: FunctionComponent = () => ( | ||
interface Props { | ||
items: { | ||
title: string; | ||
description: string; | ||
publishedAt: string; | ||
path: string; | ||
}[]; | ||
} | ||
|
||
export const Home: FunctionComponent<Props> = ({ items }) => ( | ||
<div> | ||
<WelcomePage /> | ||
<div> | ||
{items.map((item) => { | ||
return ( | ||
<Item | ||
title={item.title} | ||
description={item.description} | ||
publishedAt={item.publishedAt} | ||
path={item.path} | ||
/> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters