add post and fix bugs, also use external

This commit is contained in:
patarapolw committed 2019-08-23 20:08:23 +07:00
1 parent 39d6b337e6
commit 6fa1f68a6f
17 files changed
+214 -459

No files matched your search

+20 -9
View File
@@ -1,19 +1,19 @@
<template lang="pug">
div
div(v-if="filename")
post(:is-teaser="false" :filename="filename")
post(:is-teaser="false" :filename="filename" :key="filename")
vue-disqus(:shortname="disqus" :identifier="$route.path")
div(v-else="")
empty
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { Vue, Component, Prop, Watch } from "vue-property-decorator";
import Post from "@/layouts/Post.vue";
import Empty from "@/layouts/Empty.vue";
import moment from "moment";
import { g } from '../shared';
import { dotGetter } from '../plugins/search';
import { dotGetter } from "q2filter";
@Component({
components: {
@@ -26,14 +26,25 @@ export default class Search extends Vue {
private disqus: string = dotGetter(g.config, "external.disqus");
public mounted() {
this.updateFilename();
}
@Watch("$route.path")
public updateFilename() {
const ps = g.posts.filter((p) => {
const m = moment(p.date);
if (m.format("YYYY") === this.$route.params.y && m.format("MM") === this.$route.params.mo) {
if (p.filename
.replace(/^.*\//, "")
.replace(/\.[^.]+$/, "") === this.$route.params.name) {
const { filename } = this.$route.query;
if (filename) {
if (encodeURI(p.filename) === encodeURI(filename as string)) {
return true;
}
} else {
const m = moment(p.date);
if (m.format("YYYY") === this.$route.params.y && m.format("MM") === this.$route.params.mo) {
if (p.filename
.replace(/^.*\//, "")
.replace(/\.[^.]+$/, "") === this.$route.params.name) {
return true;
}
}
}
return false;
@@ -43,7 +54,7 @@ export default class Search extends Vue {
this.filename = "";
}
this.filename = ps[0].filename;
this.filename = (ps[0] || {}).filename;
}
}
</script>