mirror of https://github.com/halo-dev/halo
🎨 使用标签作为文章页面关键字
parent
c0d334f3ce
commit
eefd96d310
|
@ -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<Tag> tags = post.getTags();
|
||||
List<String> 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");
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
<@head title="${post.postTitle} · ${options.blog_title?default('Anatole')}" keywords="${post.postTitle},${options.seo_keywords?default('Anatole')},${tagWords}" description="${post.postSummary?if_exists}"></@head>
|
||||
<#include "module/sidebar.ftl">
|
||||
<div class="main">
|
||||
<link href="/anatole/source/plugins/prism/prism.css" type="text/css" rel="stylesheet" />
|
||||
|
|
|
@ -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}">
|
||||
<!-- Post Module -->
|
||||
<div class="material-post_container">
|
||||
<div class="material-post mdl-grid">
|
||||
|
|
Loading…
Reference in New Issue