博客-文章页meta完善
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
| {{ articels.post_date }}
|
||||
li
|
||||
Icon(:icon="['far', 'bookmark']")
|
||||
nuxt-link(v-for='(relationships, index) in articels.term_relationships', :key='index', v-if='relationships.term_taxonomy && relationships.term_taxonomy.term && relationships.term_taxonomy.taxonomy.category === "category"', :to="'/' + relationships.term_taxonomy.term.slug")
|
||||
nuxt-link(v-for='(relationships, index) in articels.term_relationships', :key='index', v-if='relationships.term_taxonomy && relationships.term_taxonomy.term && relationships.term_taxonomy.taxonomy === "category"', :to="'/' + relationships.term_taxonomy.term.slug")
|
||||
span
|
||||
| {{ relationships.term_taxonomy.term.name }}
|
||||
li(v-if='articels.postmetum.meta_value !== 0')
|
||||
@ -89,6 +89,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import remark from 'remark'
|
||||
import strip from 'strip-markdown'
|
||||
|
||||
export default {
|
||||
async asyncData ({ route, app, $axios }) {
|
||||
const data = await $axios.$get(`/public/article/details?id=${route.params.id}`)
|
||||
@ -103,14 +106,35 @@ export default {
|
||||
result.postmetum.meta_value = 0
|
||||
}
|
||||
|
||||
const truncated = (str, num) => {
|
||||
return Array.from(str).slice(0, num).join('')
|
||||
}
|
||||
|
||||
const removeMarkdownFormat = (str) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
remark()
|
||||
.use(strip)
|
||||
.process(str, function (err, file) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
resolve(String(file))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 获取评论
|
||||
const tmp = await $axios.$get(`/public/comments/post?ID=${route.params.id}`)
|
||||
const comments = tmp.result.list || []
|
||||
const commentAmount = tmp.result.amount || 0
|
||||
const markdownToText = await removeMarkdownFormat(result.post_excerpt)
|
||||
const description = truncated(markdownToText.replace(/[\r\n]/g, '').replace(/\s+/g, '').trim(), 200)
|
||||
|
||||
return {
|
||||
postID: route.params.id,
|
||||
articels: result,
|
||||
description,
|
||||
comments,
|
||||
commentsMap: new Map(),
|
||||
commentAmount,
|
||||
@ -587,22 +611,23 @@ export default {
|
||||
head () {
|
||||
const keywords = []
|
||||
for (let i = 0; i < this.articels.term_relationships.length; i++) {
|
||||
if (this.articels.term_relationships[i].term_taxonomy && this.articels.term_relationships[i].term_taxonomy.term && this.articels.term_relationships[i].term_taxonomy.taxonomy.category === 'category') {
|
||||
if (this.articels.term_relationships[i].term_taxonomy && this.articels.term_relationships[i].term_taxonomy.term && this.articels.term_relationships[i].term_taxonomy.taxonomy === 'post_tag') {
|
||||
keywords.push(this.articels.term_relationships[i].term_taxonomy.term.name)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
title: `${this.articels.post_title} - 轶哥`,
|
||||
meta: [
|
||||
{
|
||||
hid: 'description',
|
||||
name: 'description',
|
||||
content: this.articels.post_excerpt
|
||||
content: this.description
|
||||
},
|
||||
{
|
||||
hid: 'keywords',
|
||||
name: 'keywords',
|
||||
content: '轶哥,王轶,全栈,程序员,技术博客'
|
||||
content: keywords.join(',')
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user