92 lines
2.1 KiB
Vue
92 lines
2.1 KiB
Vue
<template lang="pug">
|
|
post-full(:header="header")
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { Vue, Component } from 'nuxt-property-decorator'
|
|
import PostFull from '@/components/PostFull.vue'
|
|
import htmlToText from 'html-to-text'
|
|
import { apiHash, HASH } from '@/assets/util'
|
|
import MakeHtml from '@/assets/make-html'
|
|
|
|
@Component({
|
|
components: {
|
|
PostFull,
|
|
},
|
|
})
|
|
export default class PostPage extends Vue {
|
|
header: any = {}
|
|
|
|
async asyncData ({ params, error, redirect }: any) {
|
|
const ps: any[] = JSON.parse(await apiHash('/build/header/posts.json', HASH.posts._header))
|
|
const header = ps.filter((p) => p.name === params.name)[0]
|
|
|
|
if (!header) {
|
|
return error({ statusCode: 404, message: 'Post not found' })
|
|
}
|
|
|
|
if (header.y && header.mo) {
|
|
return redirect(encodeURI(`/post/${header.y}/${header.mo}/${params.name}`))
|
|
}
|
|
|
|
header.teaser = await apiHash(`/build/teaser/${header.path}`, HASH.posts[header.path])
|
|
|
|
return {
|
|
header,
|
|
}
|
|
}
|
|
|
|
head () {
|
|
let { title } = this.header
|
|
title = `${title} - ${process.env.title}`
|
|
const description = htmlToText.fromString(this.header.teaser)
|
|
|
|
return {
|
|
title,
|
|
meta: [
|
|
{
|
|
hid: 'description',
|
|
name: 'description',
|
|
content: description,
|
|
},
|
|
{
|
|
hid: 'keywords',
|
|
name: 'keywords',
|
|
content: (this.header.tag || []).join(', '),
|
|
},
|
|
{
|
|
hid: 'og:title',
|
|
property: 'og:title',
|
|
content: title,
|
|
},
|
|
{
|
|
hid: 'og:description',
|
|
property: 'og:description',
|
|
content: description,
|
|
},
|
|
{
|
|
hid: 'og:image',
|
|
property: 'og:image',
|
|
content: this.header.image,
|
|
},
|
|
{
|
|
hid: 'twitter:title',
|
|
property: 'twitter:title',
|
|
content: title,
|
|
},
|
|
{
|
|
hid: 'twitter:description',
|
|
property: 'twitter:description',
|
|
content: description,
|
|
},
|
|
{
|
|
hid: 'twitter:image',
|
|
property: 'twitter:image',
|
|
content: this.header.image,
|
|
},
|
|
],
|
|
}
|
|
}
|
|
}
|
|
</script>
|