This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
/
index.vue
142 lines (135 loc) · 3.8 KB
/
index.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<template lang="pug">
subpage(source-url)
section
h1.display-1 Блог
blog-post(v-for="(post, postIndex) in posts"
:key="postIndex"
:folded="postIndex>0"
:document="post"
:standalone="false")
</template>
<script lang="js">
export default {
name: 'Blog',
data()
{
return {
posts: [],
};
},
computed:
{
page()
{
if (this && this.$store)
{
return this.$store.getters['pages/pageById'](
this.$store.state.pages.pageId);
}
else
{
return null;
}
},
},
async asyncData({ $content, error, store })
{
let posts = [];
try
{
posts = await $content('blog')
.where({ visible: { $eq: true } })
.sortBy('date', 'desc')
.limit(5)
.fetch();
if (!posts)
{
error({ statusCode: 404, message: 'Чланци се не могу учитати' });
}
posts.forEach(async (post) =>
{
if (post.gistId)
{
try
{
await store.dispatch('gists/loadGist', {
gistId: post.gistId
});
const gist = store.getters['gists/gistById'](
post.gistId
);
if (gist)
{
post.gist = gist.data;
}
}
catch (err)
{
error({ statusCode: 500,
message: `Гист ${post.gistId} не може да се учита`
});
}
}
});
}
catch(err)
{
error({ statusCode: 500,
message: 'Чланци не могу да се учитају' });
}
return {
posts,
};
},
async mounted()
{
let posts = [];
try
{
posts = await this.$content('blog')
.where({ visible: { $eq: true } })
.sortBy('date', 'desc')
.limit(5)
.fetch();
if (!posts)
{
this.$nuxt.error({ statusCode: 404,
message: 'Чланци се не могу учитати'});
}
posts.forEach(async (post) =>
{
if (post.gistId)
{
try
{
await this.$store.dispatch('gists/loadGist', {
gistId: post.gistId
});
const gist = this.$store.getters['gists/gistById'](
post.gistId
);
if (gist)
{
post.gist = gist.data;
}
}
catch (err)
{
this.$nuxt.error({ statusCode: 500,
message: `Гист ${post.gistId} не може да се учита`
});
}
}
});
}
catch(err)
{
this.$nuxt.error({ statusCode: 500,
message: 'Чланци не могу да се учитају' });
}
this.posts = posts;
}
};
</script>
<style lang="sass" scoped>
</style>