From bd926664786a4003f399fdfc56d8b45e2334a310 Mon Sep 17 00:00:00 2001 From: terwer Date: Mon, 22 Aug 2022 16:29:46 +0800 Subject: [PATCH] fix:Tag support and SEO --- .../components/themes/default/PostList.vue | 1 + jvue-front/pages/post/_id.vue | 10 +- jvue-front/pages/tag/_tag.vue | 98 +++++++++++++++++++ jvue-server/pom.xml | 2 +- .../terwergreen/jvueserver/api/PostApi.java | 19 +++- .../main/resources/application-dev.properties | 12 +-- .../src/main/resources/application.properties | 2 +- .../resources/mappers/spl-mapping-post.xml | 10 +- 8 files changed, 139 insertions(+), 15 deletions(-) create mode 100644 jvue-front/pages/tag/_tag.vue diff --git a/jvue-front/components/themes/default/PostList.vue b/jvue-front/components/themes/default/PostList.vue index c11f429..d47d49d 100644 --- a/jvue-front/components/themes/default/PostList.vue +++ b/jvue-front/components/themes/default/PostList.vue @@ -24,6 +24,7 @@ >

{{ post.title === "" ? "暂无标题" : post.title }}

+ diff --git a/jvue-front/pages/post/_id.vue b/jvue-front/pages/post/_id.vue index e519b0d..b60ff7e 100644 --- a/jvue-front/pages/post/_id.vue +++ b/jvue-front/pages/post/_id.vue @@ -40,6 +40,7 @@ {{ postObj.title }} + @@ -55,7 +56,7 @@

作者:Terwer

-

首发:远方的灯塔

+

首发:{{ siteConfigObj.webname }}

原创内容,转载请注明出处!

@@ -150,12 +151,12 @@ export default { meta: [ { name: "keywords", - content: this.siteConfigObj.keywords + content: this.postObj.tags }, { hid: "description", name: "description", - content: this.siteConfigObj.description + content: this.postObj.desc } ], script: [ @@ -208,7 +209,7 @@ export default { } h1 { border-bottom: 1px solid #ddd; - font-size: 14px; + font-size: 28px; font-weight: bold; margin: 20px 0 10px; padding-bottom: 5px; @@ -221,6 +222,7 @@ export default { font-weight: bold; line-height: 1.5; margin: 10px 0; + display: none; } h2 { font-size: 21px; diff --git a/jvue-front/pages/tag/_tag.vue b/jvue-front/pages/tag/_tag.vue new file mode 100644 index 0000000..5a77944 --- /dev/null +++ b/jvue-front/pages/tag/_tag.vue @@ -0,0 +1,98 @@ + + + + + + + diff --git a/jvue-server/pom.xml b/jvue-server/pom.xml index 88c7702..8f722b3 100644 --- a/jvue-server/pom.xml +++ b/jvue-server/pom.xml @@ -10,7 +10,7 @@ com.terwergreen jvue-server - 4.0.1 + 4.1.0 war jvue-server Next light-weight,responsive project With Docker,Vue,Vue CLI 3,webpack and Spring Boot diff --git a/jvue-server/src/main/java/com/terwergreen/jvueserver/api/PostApi.java b/jvue-server/src/main/java/com/terwergreen/jvueserver/api/PostApi.java index c9ad659..e3fb4f3 100644 --- a/jvue-server/src/main/java/com/terwergreen/jvueserver/api/PostApi.java +++ b/jvue-server/src/main/java/com/terwergreen/jvueserver/api/PostApi.java @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,7 +59,8 @@ public class PostApi extends BaseApi { @ApiImplicitParam(name = "isHot", value = "是否热门,1热门,不传或者0全部"), @ApiImplicitParam(name = "postStatus", value = "状态"), @ApiImplicitParam(name = "postType", value = "文章类型"), - @ApiImplicitParam(name = "search", value = "搜索关键字") + @ApiImplicitParam(name = "search", value = "搜索关键字"), + @ApiImplicitParam(name = "tags", value = "标签") }) @PostMapping("/list") public RestResponse getPostList(@RequestParam(required = false) Integer pageNum, @@ -66,7 +68,8 @@ public RestResponse getPostList(@RequestParam(required = false) Integer pageNum, @RequestParam(required = false) Integer isHot, @RequestParam(required = false) String postStatus, @RequestParam(required = false) String postType, - @RequestParam(required = false) String search + @RequestParam(required = false) String search, + @RequestParam(required = false) String tags ) throws RestException { if (pageNum == null) { pageNum = Constants.DEFAULT_PAGE_NUM; @@ -90,6 +93,10 @@ public RestResponse getPostList(@RequestParam(required = false) Integer pageNum, if (StringUtils.isNotEmpty(search)) { paramMap.put("search", search); } + if (StringUtils.isNotEmpty(tags)) { + String[] tagArray = tags.split(","); + paramMap.put("tagArray", tagArray); + } PageInfo posts = postService.getPostsByPage(pageNum, pageSize, paramMap); if (null == posts.getList()) { @@ -204,10 +211,18 @@ public RestResponse updateHits(Integer postId, Integer hits) { * @param post 文章实体类 */ private void transformContent(Post post) { + // markdown转换为html String rawContent = post.getContent(); String html = MarkdownUtil.md2html(rawContent); post.setContent(html); post.setRawContent(rawContent); + + // 截取摘要 + String filteredHtml = HtmlUtil.parseHtml(html, Constants.MAX_PREVIEW_LENGTH); + post.setDesc(filteredHtml); + // 解析图片 + List thumbnails = ImageUtil.getImgSrc(html); + post.setThumbnails(thumbnails); } /** diff --git a/jvue-server/src/main/resources/application-dev.properties b/jvue-server/src/main/resources/application-dev.properties index dba5c15..555f2b2 100644 --- a/jvue-server/src/main/resources/application-dev.properties +++ b/jvue-server/src/main/resources/application-dev.properties @@ -4,12 +4,12 @@ # https://help.aliyun.com/document_detail/365559.html # HTTPS\u534f\u8bae\u9ed8\u8ba4\u7aef\u53e3\u53f7\u4e3a443\uff0c\u9700\u8981\u4f7f\u7528\u5176\u4ed6\u7aef\u53e3\u65f6\uff0c\u60a8\u53ef\u4ee5\u5728\u6b64\u5904\u81ea\u5b9a\u4e49\u3002 server.port=8002 -# https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#keystore-types -# \u60a8\u9700\u8981\u4f7f\u7528\u5b9e\u9645\u7684\u8bc1\u4e66\u540d\u79f0\u66ff\u6362domain_name.pfx\u3002 -server.ssl.key-store=classpath:v4.pfx -# \u586b\u5199pfx-password.txt\u6587\u4ef6\u5185\u7684\u5bc6\u7801\u3002 -server.ssl.key-store-password=123456 -server.ssl.keyStoreType=PKCS12 +## https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#keystore-types +## \u60a8\u9700\u8981\u4f7f\u7528\u5b9e\u9645\u7684\u8bc1\u4e66\u540d\u79f0\u66ff\u6362domain_name.pfx\u3002 +#server.ssl.key-store=classpath:v4.pfx +## \u586b\u5199pfx-password.txt\u6587\u4ef6\u5185\u7684\u5bc6\u7801\u3002 +#server.ssl.key-store-password=123456 +#server.ssl.keyStoreType=PKCS12 # ================================================ # DataSource\u914d\u7f6e diff --git a/jvue-server/src/main/resources/application.properties b/jvue-server/src/main/resources/application.properties index 5331ff3..2456ca5 100644 --- a/jvue-server/src/main/resources/application.properties +++ b/jvue-server/src/main/resources/application.properties @@ -1,5 +1,5 @@ application.title=JVue Framework -application.formatted-version=v4.0.1 +application.formatted-version=v4.1.0 logging.level.root=INFO logging.level.com.terwergreen.jvueserver=DEBUG diff --git a/jvue-server/src/main/resources/mappers/spl-mapping-post.xml b/jvue-server/src/main/resources/mappers/spl-mapping-post.xml index 6d884fb..d890c84 100644 --- a/jvue-server/src/main/resources/mappers/spl-mapping-post.xml +++ b/jvue-server/src/main/resources/mappers/spl-mapping-post.xml @@ -20,6 +20,13 @@ content LIKE concat(concat('%', #{search}), '%') ) + + AND ( + + find_in_set(#{tag},tags) + + ) + ORDER BY hits DESC,modified,created DESC @@ -68,7 +75,8 @@ WHERE id = #{postId} - + INSERT INTO posts( created ,modified