plan for ssg
This commit is contained in:
1 parent
a8867be72c
commit
fb69b2710f
73 files changed
+921
-718
No files matched your search
@@ -51,13 +51,18 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop } from 'nuxt-property-decorator'
|
||||
import { Vue, Component, Prop, Watch } from 'nuxt-property-decorator'
|
||||
|
||||
@Component
|
||||
export default class PostQuery extends Vue {
|
||||
@Prop({ required: true }) posts!: IPostTeaser[]
|
||||
@Prop({ required: true }) count!: number
|
||||
|
||||
readonly defaults = {
|
||||
posts: this.posts,
|
||||
count: this.count,
|
||||
}
|
||||
|
||||
get page() {
|
||||
return parseInt((this.$route.query.page as string) || '1')
|
||||
}
|
||||
@@ -66,14 +71,45 @@ export default class PostQuery extends Vue {
|
||||
return Math.ceil(this.count / 5)
|
||||
}
|
||||
|
||||
makePageUrl(page: number) {
|
||||
makePageUrl(p: number) {
|
||||
let path = this.$route.path
|
||||
if (!(path.startsWith('/tag') || path.startsWith('/blog'))) {
|
||||
path = '/blog'
|
||||
}
|
||||
|
||||
path = path.replace(/\d+$/, '').replace(/\/$/, '')
|
||||
if (p > 1) {
|
||||
path = path + '/' + p
|
||||
}
|
||||
|
||||
return this.$router.resolve({
|
||||
path: this.$route.path,
|
||||
query: {
|
||||
...this.$route.query,
|
||||
page: page.toString(),
|
||||
},
|
||||
path,
|
||||
query: this.$route.query,
|
||||
}).href
|
||||
}
|
||||
|
||||
@Watch('$route.params.page')
|
||||
@Watch('$route.params.tag')
|
||||
async updatePosts() {
|
||||
if (this.$route.query.q) {
|
||||
const ps = await this.$axios.$post(
|
||||
'/.netlify/functions/search',
|
||||
undefined,
|
||||
{
|
||||
params: {
|
||||
q: this.$route.query.q,
|
||||
page: this.$route.params.page,
|
||||
tag: this.$route.params.tag,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
this.count = ps.count
|
||||
this.$set(this, 'posts', ps.result)
|
||||
} else {
|
||||
this.count = this.defaults.count
|
||||
this.$set(this, 'posts', this.defaults.posts)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<section>
|
||||
<h2>
|
||||
<nuxt-link :to="'post/' + post.path">
|
||||
<nuxt-link :to="'/post/' + post.path">
|
||||
{{ post.title }}
|
||||
</nuxt-link>
|
||||
</h2>
|
||||
@@ -25,7 +25,7 @@
|
||||
</span>
|
||||
</small>
|
||||
|
||||
<article v-html="post.excerpt"></article>
|
||||
<article v-html="post.excerptHtml"></article>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in new issue
Block a user