Skip to content

Commit

Permalink
Merge pull request #183 from terwer/v4.x
Browse files Browse the repository at this point in the history
fix:Tag support and SEO
  • Loading branch information
terwer committed Aug 22, 2022
2 parents b9be051 + bd92666 commit 44e6540
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 15 deletions.
1 change: 1 addition & 0 deletions jvue-front/components/themes/default/PostList.vue
Expand Up @@ -24,6 +24,7 @@
>
<h2>{{ post.title === "" ? "暂无标题" : post.title }}</h2>
</nuxt-link>
<input type="hidden" :value="post.id" />
</div>
</el-col>
<el-col :span="24">
Expand Down
10 changes: 6 additions & 4 deletions jvue-front/pages/post/_id.vue
Expand Up @@ -40,6 +40,7 @@
{{ postObj.title }}
</h1>
</nuxt-link>
<input type="hidden" :value="postObj.id" />
</div>

<!-- 文章详情 -->
Expand All @@ -55,7 +56,7 @@

<div class="copy">
<p>作者:Terwer</p>
<p>首发:远方的灯塔</p>
<p>首发:{{ siteConfigObj.webname }}</p>
<p>
原创内容,转载请注明出处!
</p>
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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;
Expand All @@ -221,6 +222,7 @@ export default {
font-weight: bold;
line-height: 1.5;
margin: 10px 0;
display: none;
}
h2 {
font-size: 21px;
Expand Down
98 changes: 98 additions & 0 deletions jvue-front/pages/tag/_tag.vue
@@ -0,0 +1,98 @@
<template>
<el-container>
<el-main>
<el-row>
<el-col :xs="0" :md="2">&nbsp;</el-col>
<el-col :xs="24" :md="20">
<el-main>
<el-container>
<el-main>
<el-container>
<el-header>
<HeaderTime />
</el-header>
<el-header>
<Header />
</el-header>
<el-main>
<Body :keyword="tag" :post-list="postListArray" />
</el-main>
</el-container>
</el-main>
</el-container>
</el-main>
</el-col>
<el-col :xs="0" :md="2">&nbsp;</el-col>
</el-row>
<el-row>
<el-col>
<el-footer>
<Footer :site-config="siteConfigObj" />
<FriendLink />
</el-footer>
</el-col>
</el-row>
</el-main>
</el-container>
</template>

<script>
import { getLogger } from "../../util/logger";
import HeaderTime from "../../components/themes/default/HeaderTime";
import Header from "../../components/themes/default/Header";
import Body from "../../components/themes/default/Body";
import Footer from "../../components/themes/default/Footer";
import FriendLink from "../../components/themes/default/FriendLink";
const logger = getLogger("pages/post");
export default {
components: { HeaderTime, Header, Body, Footer, FriendLink },
async asyncData({ $axios }) {
const siteConfigResult = await $axios.$post("/site/config/list");
const siteConfigObj =
siteConfigResult.status === 1 ? siteConfigResult.data : {};
logger.info("fetch siteConfig and postList finish");
return { siteConfigObj };
},
data() {
return {
tag: this.$route.params.tag
? this.$route.params.tag.replace(/\.[^/.]+$/, "")
: "",
postListArray: []
};
},
head() {
return {
title: this.siteConfigObj.webname + " - " + this.siteConfigObj.webslogen,
meta: [
{
name: "keywords",
content: this.siteConfigObj.keywords
},
{
hid: "description",
name: "description",
content: this.siteConfigObj.description
}
]
};
},
async mounted() {
const postsResult = await this.$axios.$post("/blog/post/list", {
postStatus: "publish",
tags: this.tag
});
this.postListArray = postsResult.status === 1 ? postsResult.data.list : [];
}
};
</script>

<style lang="scss">
@import "../common.css";
@import "../default.css";
</style>

<style scoped></style>
2 changes: 1 addition & 1 deletion jvue-server/pom.xml
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.terwergreen</groupId>
<artifactId>jvue-server</artifactId>
<version>4.0.1</version>
<version>4.1.0</version>
<packaging>war</packaging>
<name>jvue-server</name>
<description>Next light-weight,responsive project With Docker,Vue,Vue CLI 3,webpack and Spring Boot</description>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -58,15 +59,17 @@ 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,
@RequestParam(required = false) Integer pageSize,
@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;
Expand All @@ -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<Post> posts = postService.getPostsByPage(pageNum, pageSize, paramMap);

if (null == posts.getList()) {
Expand Down Expand Up @@ -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<String> thumbnails = ImageUtil.getImgSrc(html);
post.setThumbnails(thumbnails);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions jvue-server/src/main/resources/application-dev.properties
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 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

Expand Down
10 changes: 9 additions & 1 deletion jvue-server/src/main/resources/mappers/spl-mapping-post.xml
Expand Up @@ -20,6 +20,13 @@
content LIKE concat(concat('%', #{search}), '%')
)
</if>
<if test="tagArray != null and tagArray != ''">
AND (
<foreach collection="tagArray" open="" close="" item="tag" separator="or" index="index">
find_in_set(#{tag},tags)
</foreach>
)
</if>
<choose>
<when test="isHot!=null and isHot==1">
ORDER BY hits DESC,modified,created DESC
Expand Down Expand Up @@ -68,7 +75,8 @@
WHERE id = #{postId}
</select>
<!-- 新增文章 -->
<insert id="insertPost" useGeneratedKeys="true" keyProperty="id" keyColumn="id" parameterType="com.terwergreen.jvueserver.model.Post">
<insert id="insertPost" useGeneratedKeys="true" keyProperty="id" keyColumn="id"
parameterType="com.terwergreen.jvueserver.model.Post">
INSERT INTO posts(
created
,modified
Expand Down

1 comment on commit 44e6540

@vercel
Copy link

@vercel vercel bot commented on 44e6540 Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.