Skip to content

Commit

Permalink
[release-1.5] fix: issue of post details page without meta_descriptio…
Browse files Browse the repository at this point in the history
…n variables (#2285)

This is an automated cherry-pick of #2282

/assign ruibaby

```release-note
修复文章内容查询问题导致的文章详情页 meta_description 为空
```
  • Loading branch information
halo-dev-bot authored Jul 29, 2022
1 parent 09202da commit b3a53ab
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main/java/run/halo/app/controller/content/model/PostModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import run.halo.app.model.enums.EncryptTypeEnum;
import run.halo.app.model.enums.PostStatus;
import run.halo.app.model.vo.ArchiveYearVO;
import run.halo.app.model.vo.PostDetailVO;
import run.halo.app.model.vo.PostListVO;
import run.halo.app.service.CategoryService;
import run.halo.app.service.OptionService;
Expand Down Expand Up @@ -143,21 +144,25 @@ public String content(Post post, String token, Model model) {
tags.stream().map(Tag::getName).collect(Collectors.joining(",")));
}

model.addAttribute("is_post", true);

PostDetailVO postDetail;
if (StringUtils.isNotBlank(token)) {
postDetail = postRenderAssembler.convertToPreviewDetailVo(post);
model.addAttribute("post", postDetail);
} else {
postDetail = postRenderAssembler.convertToDetailVo(post);
model.addAttribute("post", postDetail);
}

// Generate meta description.
if (StringUtils.isNotEmpty(post.getMetaDescription())) {
model.addAttribute("meta_description", post.getMetaDescription());
} else {
model.addAttribute("meta_description",
postService.generateDescription(post.getContent().getContent()));
postService.generateDescription(postDetail.getContent()));
}

model.addAttribute("is_post", true);

if (StringUtils.isNotBlank(token)) {
model.addAttribute("post", postRenderAssembler.convertToPreviewDetailVo(post));
} else {
model.addAttribute("post", postRenderAssembler.convertToDetailVo(post));
}

model.addAttribute("categories", categoryService.convertTo(categories));
model.addAttribute("tags", tagService.convertTo(tags));
Expand Down

0 comments on commit b3a53ab

Please sign in to comment.