Skip to content

Commit

Permalink
fix:Add tag
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 23, 2022
1 parent e929629 commit 1204fb6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
36 changes: 36 additions & 0 deletions jvue-front/pages/post/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
<input type="hidden" :value="postObj.id" />
</div>

<div v-if="postObj.tagArray">
<NuxtLink
v-for="tagItem in postObj.tagArray"
:key="tagItem.tag"
:to="'/tag/' + tagItem.tag"
>
<el-tag :type="tagItem.color" class="post-tag">
{{ tagItem.tag }}
</el-tag>
</NuxtLink>
</div>

<!-- 文章详情 -->
<div
id="postContent"
Expand Down Expand Up @@ -124,6 +136,25 @@ export default {
errorMessage = postResult.msg;
}
const colors = ["success", "info", "warning", "danger"];
const tagArr = [];
if (postObj.tags && postObj.tags !== "") {
const tags = postObj.tags.split(",");
tags.forEach(item => {
const randomColor = colors[Math.floor(Math.random() * colors.length)];
tagArr.push({
tag: item,
color: randomColor
});
});
}
Object.assign(postObj, {
tagArray: tagArr
});
logger.info("fetch siteConfig and post finish");
return { siteConfigObj, postObj, errorMessage };
Expand Down Expand Up @@ -216,6 +247,11 @@ export default {
}
}
.post-default .post-tag {
margin-right: 10px;
cursor: pointer;
}
.post-default #postContent {
h1 {
font-size: 28px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ private static String parseHtml(String html) {
* "<.*?"表示<尖括号后的所有字符,此方法可以去掉残缺的标签,及后面的内容
* " ",若有多种此种字符,可用同一方法去除
*/
html = html.replaceAll("<iframe.*src=\"/widgets/publisher.*</iframe>", "");
html = html.replaceAll("<iframe.*src=\"/widgets/sy-post-publisher.*</iframe>", "");
html = html.replaceAll("<iframe.*/widgets/Note*\\sAttrs.*/iframe>", "");
html = html.replaceAll("<h1.*/h1>", "");

html = html.replaceAll("<.*?>", "");
html = html.replaceAll("<.*?", "");
html = html.replaceAll("\\n", "");
html = html.replaceAll("&quot;", "");
html = html.replaceAll(" ", "");

html = html.replaceAll("<iframe.*src=\"/widgets/publisher.*</iframe>", "");
html = html.replaceAll("<iframe.*src=\"/widgets/sy-post-publisher.*</iframe>", "");
html = html.replaceAll("<iframe.*/widgets/Note*\\sAttrs.*/iframe>", "");
html = html.replaceAll("<h1.*/h1>", "");

return (html);
}

Expand Down

0 comments on commit 1204fb6

Please sign in to comment.