Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:Tag support and SEO #183

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions jvue-front/components/themes/default/PostList.vue
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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