🎨 使用标签作为文章页面关键字

pull/33/merge
ruibaby 2018-08-06 11:00:57 +08:00
parent c0d334f3ce
commit eefd96d310
3 changed files with 15 additions and 3 deletions

View File

@ -2,12 +2,14 @@ package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.Comment; import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Post; 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.dto.HaloConst;
import cc.ryanc.halo.model.enums.*; import cc.ryanc.halo.model.enums.*;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.utils.CommentUtil; import cc.ryanc.halo.utils.CommentUtil;
import cc.ryanc.halo.web.controller.core.BaseController; import cc.ryanc.halo.web.controller.core.BaseController;
import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; 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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -130,10 +133,19 @@ public class FrontArchiveController extends BaseController {
} else { } else {
comments = commentService.findCommentsByPostAndCommentStatusNot(post, CommentStatusEnum.RECYCLE.getCode()); 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("is_post",true);
model.addAttribute("post", post); model.addAttribute("post", post);
model.addAttribute("comments", CommentUtil.getComments(comments)); model.addAttribute("comments", CommentUtil.getComments(comments));
model.addAttribute("commentsCount", comments.size()); model.addAttribute("commentsCount", comments.size());
model.addAttribute("tagWords", CollUtil.join(tagWords, ","));
postService.updatePostView(post); postService.updatePostView(post);
return this.render("post"); return this.render("post");
} }

View File

@ -1,5 +1,5 @@
<#include "module/macro.ftl"> <#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"> <#include "module/sidebar.ftl">
<div class="main"> <div class="main">
<link href="/anatole/source/plugins/prism/prism.css" type="text/css" rel="stylesheet" /> <link href="/anatole/source/plugins/prism/prism.css" type="text/css" rel="stylesheet" />

View File

@ -1,5 +1,5 @@
<#include "module/macro.ftl"> <#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 --> <!-- Post Module -->
<div class="material-post_container"> <div class="material-post_container">
<div class="material-post mdl-grid"> <div class="material-post mdl-grid">
@ -26,4 +26,4 @@
<#include "_partial/post-nav.ftl"> <#include "_partial/post-nav.ftl">
</div> </div>
</div> </div>
</@layout> </@layout>