Skip to content

Commit

Permalink
feat: Update BlogPostHistory to accept language parameter for localiz…
Browse files Browse the repository at this point in the history
…ation support
  • Loading branch information
Laisky committed Nov 13, 2024
1 parent 1a1990b commit 1d0438b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/web/blog/controller/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func (r *QueryResolver) BlogPostInfo(ctx context.Context) (*dto.PostInfo, error)
return r.svc.LoadPostInfo(ctx)
}

func (r *QueryResolver) BlogPostHistory(ctx context.Context, fileID string) (*model.Post, error) {
return r.svc.LoadPostHistory(ctx, fileID)
func (r *QueryResolver) BlogPostHistory(ctx context.Context, fileID string, language models.Language) (*model.Post, error) {
return r.svc.LoadPostHistory(ctx, fileID, language)
}

func (r *QueryResolver) WhoAmI(ctx context.Context) (*model.User, error) {
Expand Down
9 changes: 8 additions & 1 deletion internal/web/blog/service/posts.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (s *Blog) LoadPostInfo(ctx context.Context) (*dto.PostInfo, error) {
}

// LoadPostHistory load post history by arweave file id
func (s *Blog) LoadPostHistory(ctx context.Context, fileID string) (*model.Post, error) {
func (s *Blog) LoadPostHistory(ctx context.Context, fileID string, language models.Language) (*model.Post, error) {
logger := gmw.GetLogger(ctx)

req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://ario.laisky.com/"+fileID, nil)
Expand Down Expand Up @@ -189,6 +189,13 @@ func (s *Blog) LoadPostHistory(ctx context.Context, fileID string) (*model.Post,
return nil, errors.Wrap(err, "decode post")
}

if language != models.LanguageZhCn && post.I18N.EnUs.PostContent != "" {
post.Content = post.I18N.EnUs.PostContent
post.Title = post.I18N.EnUs.PostTitle
post.Menu = post.I18N.EnUs.PostMenu
post.Markdown = post.I18N.EnUs.PostMarkdown
}

return post, nil
}

Expand Down
35 changes: 31 additions & 4 deletions internal/web/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/web/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Query {
): [BlogPost]!
BlogPostHistory(
file_id: String!
language: Language! = zh_CN
): BlogPost!
BlogPostInfo: PostInfo!
BlogPostCategories: [BlogCategory]!
Expand Down

0 comments on commit 1d0438b

Please sign in to comment.