-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlog.vue
106 lines (98 loc) · 2.76 KB
/
Blog.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<template>
<div class="post">
<template v-for="element in postContent">
<BlogTitle
v-if="element.type === 'title'"
:msg="element.msg"
:key="element.index"
/>
<BlogP
v-else-if="element.type === 'p'"
:raw-msg="element.rawMsg"
:links="element.links"
:key="element.index"
/>
<BlogImg
v-else-if="element.type === 'img'"
:file-links="element.signed || {'public': element.link}"
:post-id="id"
:alt-text="element.alt"
:key="element.index"
/>
<BlogVideo
v-else-if="element.type === 'video'"
:file-links="element.signed || {'public': element.link}"
:post-id="id"
:key="element.index"
/>
<BlogHeader
v-else-if="element.type === 'header'"
:msg="element.msg"
:key="element.index"
/>
<BlogList
v-else-if="element.type === 'list'"
:items="element.items"
:key="element.index"
/>
</template>
</div>
</template>
<script>
import axios from 'axios';
import { getCachedData, setCachedData } from '@/util/expiring-session-cache';
import BlogHeader from '@/components/BlogHeader.vue';
import BlogImg from '@/components/BlogImg.vue';
import BlogVideo from '@/components/BlogVideo.vue';
import BlogList from '@/components/BlogList.vue';
import BlogP from '@/components/BlogP.vue';
import BlogTitle from '@/components/BlogTitle.vue';
export default {
name: 'Blog',
components: {
BlogTitle,
BlogP,
BlogImg,
BlogVideo,
BlogHeader,
BlogList,
},
props: {
id: {
type: String,
},
},
data() {
const cacheData = getCachedData(this.$route.path);
if (cacheData) { return JSON.parse(cacheData); }
const isPrivatePost = (this.id.charAt(0) === '_');
if (!this.postContent) {
let url = `/api/public/${this.id}/post_data.json`;
let headers = {};
if (isPrivatePost) {
// see note in Home.vue as to why I don't bother obscuring these values
const authToken = getCachedData('ft-auth-token');
this.id = this.id.substring(1);
url = `https://nccu1znzcj.execute-api.us-east-2.amazonaws.com/Prod/post-data/${this.id}`;
headers = {
'X-Api-Key': 'oZE5pkcS5H4PlndobzKdH9wmoxO9uLqa2tY5wtaH',
Authorization: authToken,
};
}
axios.get(
url,
{ headers: headers || {} },
).then(({ data }) => {
setCachedData(this.$route.path, JSON.stringify({ postContent: data }));
this.postContent = data;
}).catch((error) => {
/* istanbul ignore next line */
console.log(error);
});
}
return {
postContent: [{ index: 0, type: 'p', rawMsg: 'Loading post...' }],
};
},
};
</script>