refactor: path | detail blog
This commit is contained in:
parent
7568b6d26f
commit
c2ba6cf36f
@ -23,7 +23,7 @@
|
|||||||
{{ firstBlog.description }}
|
{{ firstBlog.description }}
|
||||||
</p>
|
</p>
|
||||||
<br>
|
<br>
|
||||||
<NuxtLink :to="firstBlog.path" class="button is-primary">
|
<NuxtLink :to="{name: 'blog-slug', params: { slug: firstBlog.slug }}" class="button is-primary">
|
||||||
Read More
|
Read More
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<article class="container content">
|
<article class="container content">
|
||||||
<nuxt-content :document="article" />
|
<nuxt-content :document="blogDetail" />
|
||||||
</article>
|
</article>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -12,7 +12,10 @@ import getSiteMeta from '@/utils/getSiteMeta'
|
|||||||
@Component({
|
@Component({
|
||||||
name: 'ArticlePage',
|
name: 'ArticlePage',
|
||||||
async asyncData ({ $content, params }) {
|
async asyncData ({ $content, params }) {
|
||||||
const article = await $content('blog', params.slug).fetch()
|
const findedBlog = await $content('blog', { deep: true })
|
||||||
|
.where({ slug: params.slug })
|
||||||
|
.fetch()
|
||||||
|
const [blogDetail] = findedBlog
|
||||||
|
|
||||||
const [prev, next] = await $content('blog')
|
const [prev, next] = await $content('blog')
|
||||||
.only(['title', 'slug', 'published'])
|
.only(['title', 'slug', 'published'])
|
||||||
@ -25,41 +28,41 @@ import getSiteMeta from '@/utils/getSiteMeta'
|
|||||||
.sortBy('published', 'desc')
|
.sortBy('published', 'desc')
|
||||||
.fetch()
|
.fetch()
|
||||||
|
|
||||||
const articlesByTag = allBlogs.filter((article) => {
|
const blogsByTag = allBlogs.filter((blog) => {
|
||||||
const articleTags = article.tags.map(x => x.toLowerCase())
|
const blogTags = blog.tags.map(x => x.toLowerCase())
|
||||||
return articleTags.includes(article.tags[0].toLowerCase())
|
return blogTags.includes(blog.tags[0].toLowerCase())
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
article,
|
blogDetail,
|
||||||
articlesByTag,
|
blogsByTag,
|
||||||
prev,
|
prev,
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
head () {
|
head () {
|
||||||
return {
|
return {
|
||||||
title: this.article.title,
|
title: this.blogDetail.title,
|
||||||
meta: [
|
meta: [
|
||||||
...this.meta,
|
...this.meta,
|
||||||
{
|
{
|
||||||
property: 'article:published_time',
|
property: 'blog:published_time',
|
||||||
content: this.article.createdAt
|
content: this.blogDetail.createdAt
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
property: 'article:modified_time',
|
property: 'blog:modified_time',
|
||||||
content: this.article.updatedAt
|
content: this.blogDetail.updatedAt
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
property: 'article:tag',
|
property: 'blog:tag',
|
||||||
content: this.article.tags ? this.article.tags.toString() : ''
|
content: this.blogDetail.tags ? this.blogDetail.tags.toString() : ''
|
||||||
},
|
},
|
||||||
{ name: 'twitter:label1', content: 'Written by' },
|
{ name: 'twitter:label1', content: 'Written by' },
|
||||||
{ name: 'twitter:data1', content: global.author || '' },
|
{ name: 'twitter:data1', content: global.author || '' },
|
||||||
{ name: 'twitter:label2', content: 'Filed under' },
|
{ name: 'twitter:label2', content: 'Filed under' },
|
||||||
{
|
{
|
||||||
name: 'twitter:data2',
|
name: 'twitter:data2',
|
||||||
content: this.article.tags ? this.article.tags.toString() : ''
|
content: this.blogDetail.tags ? this.blogDetail.tags.toString() : ''
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
link: [
|
link: [
|
||||||
@ -74,11 +77,11 @@ import getSiteMeta from '@/utils/getSiteMeta'
|
|||||||
computed: {
|
computed: {
|
||||||
meta () {
|
meta () {
|
||||||
const metaData = {
|
const metaData = {
|
||||||
type: 'article',
|
type: 'blog',
|
||||||
title: this.article.title,
|
title: this.blogDetail.title,
|
||||||
description: this.article.description,
|
description: this.blogDetail.description,
|
||||||
url: `${this.$config.baseUrl}/blog/${this.$route.params.slug}`,
|
url: `${this.$config.baseUrl}/blog/${this.$route.params.slug}`,
|
||||||
mainImage: this.article.image
|
mainImage: this.blogDetail.image
|
||||||
}
|
}
|
||||||
return getSiteMeta(metaData)
|
return getSiteMeta(metaData)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user