diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java b/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java index 200b742eb..603b3bd09 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java @@ -2,12 +2,14 @@ package cc.ryanc.halo.web.controller.front; import cc.ryanc.halo.model.domain.Comment; import cc.ryanc.halo.model.domain.Post; +import cc.ryanc.halo.model.domain.Tag; import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.enums.*; import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.utils.CommentUtil; import cc.ryanc.halo.web.controller.core.BaseController; +import cn.hutool.core.collection.CollUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -130,10 +133,19 @@ public class FrontArchiveController extends BaseController { } else { comments = commentService.findCommentsByPostAndCommentStatusNot(post, CommentStatusEnum.RECYCLE.getCode()); } + //获取文章的标签用作keywords + List tags = post.getTags(); + List tagWords = new ArrayList<>(); + if (tags != null) { + for (Tag tag : tags) { + tagWords.add(tag.getTagName()); + } + } model.addAttribute("is_post",true); model.addAttribute("post", post); model.addAttribute("comments", CommentUtil.getComments(comments)); model.addAttribute("commentsCount", comments.size()); + model.addAttribute("tagWords", CollUtil.join(tagWords, ",")); postService.updatePostView(post); return this.render("post"); } diff --git a/src/main/resources/templates/themes/anatole/post.ftl b/src/main/resources/templates/themes/anatole/post.ftl index 3a20a77ab..6afdc43a2 100644 --- a/src/main/resources/templates/themes/anatole/post.ftl +++ b/src/main/resources/templates/themes/anatole/post.ftl @@ -1,5 +1,5 @@ <#include "module/macro.ftl"> -<@head title="${post.postTitle} · ${options.blog_title?default('Anatole')}" keywords="${post.postTitle},${options.seo_keywords?default('Anatole')}" description="${post.postSummary?if_exists}"> +<@head title="${post.postTitle} · ${options.blog_title?default('Anatole')}" keywords="${post.postTitle},${options.seo_keywords?default('Anatole')},${tagWords}" description="${post.postSummary?if_exists}"> <#include "module/sidebar.ftl">
diff --git a/src/main/resources/templates/themes/material/post.ftl b/src/main/resources/templates/themes/material/post.ftl index 0dac16db9..5768cd4c9 100644 --- a/src/main/resources/templates/themes/material/post.ftl +++ b/src/main/resources/templates/themes/material/post.ftl @@ -1,5 +1,5 @@ <#include "module/macro.ftl"> -<@layout title="${post.postTitle?if_exists} | ${options.blog_title?default('Material')}" keywords="${options.seo_keywords?default('Material')}" description="${post.postSummary?if_exists}"> +<@layout title="${post.postTitle?if_exists} | ${options.blog_title?default('Material')}" keywords="${options.seo_keywords?default('Material')},${tagWords}" description="${post.postSummary?if_exists}">
@@ -26,4 +26,4 @@ <#include "_partial/post-nav.ftl">
- \ No newline at end of file +