-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBlogPostList.vue
More file actions
224 lines (195 loc) · 4.72 KB
/
BlogPostList.vue
File metadata and controls
224 lines (195 loc) · 4.72 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<script setup lang="ts">
const props = defineProps({
list: {
type: Array,
default: () => [],
},
})
const displayRange = ref({
end: 4,
})
const formattedEventDate = (date: string) => {
return new Date(date).toLocaleString('en-US', {
month: 'long',
day: 'numeric',
year: 'numeric',
})
}
const selectedTag = ref('')
const filteredList = computed(() => {
if (props.list && props.list.length > 0) {
return props.list
.filter((item) => {
const isBlogPost = item._path.includes('/blog/')
const isReadyToPublish = new Date(item.date) <= new Date()
const hasTags = item.tags && item.tags.includes(selectedTag.value)
const shouldPublish = selectedTag.value
? isBlogPost && isReadyToPublish && hasTags
: isBlogPost && isReadyToPublish
return shouldPublish
})
.sort((a, b) => new Date(b.date) - new Date(a.date))
}
return false
})
function loadMore() {
displayRange.value.end += 5
}
function updateSelectedTag(tag) {
selectedTag.value = tag
}
</script>
<template>
<div class="blog-list__container">
<div class="blog-list__header">
<h1 class="blog-list-title">Blog Posts</h1>
<div style="margin-left: 20px" class="tooltip-ex">
<strong><i class="fas fa-info-circle"></i></strong>
<span class="tooltip-ex-text tooltip-ex-bottom"
>Everything here is written via the stream of consciousness writing
technique and should be treated as a rough draft at best (i.e., very
little editing). However, I promise you one thing:
<strong
><em
>none of the posts below are meant to be offensive or malicious in
any way</em
></strong
>. So if you read something that you feel is offensive, please let me
know and I'll be happy to take the time to rewrite it!</span
>
</div>
</div>
<p>
To subscribe via RSS, you can use
<a href="/rss.xml">https://www.bencodezen.io/rss.xml</a>.
</p>
<h2 class="blog-list-subtitle">Most Recent</h2>
<div v-if="selectedTag" class="filtered-heading">
<h2>Filtered by {{ selectedTag }} tag</h2>
<button
type="button"
class="btn clear-filter-btn"
@click="selectedTag = ''"
>
Clear filter
</button>
</div>
<ul class="blog-list">
<li
v-for="(item, index) in filteredList"
:key="`blog-post-${index}`"
class="blog-list__item"
>
<BlogPostPreview
v-show="index <= displayRange.end"
:excerpt="item.excerpt"
:path="item._path"
:published="item.date"
:tags="item.tags"
:title="item.title"
@updateSelectedTag="updateSelectedTag"
/>
</li>
</ul>
<div
v-if="displayRange.end <= filteredList.length"
class="pagination-section"
>
<button class="button--load-more" type="button" @click="loadMore">
Load More
</button>
</div>
</div>
</template>
<style lang="scss" scoped>
$primary-color: #22aaff;
.blog-list {
padding: 0;
margin: 0;
}
.blog-list-subtitle {
@apply text-3xl;
@apply font-bold;
font-family: $ff-sans;
border-bottom: 1px solid $c-border;
@apply mb-3;
@apply pb-1;
}
.blog-list-title {
@apply text-4xl;
@apply font-bold;
font-family: $ff-sans;
@apply mb-4;
}
.blog-list__container {
margin-top: 2rem;
}
.blog-list__header {
display: flex;
align-items: center;
}
.blog-list__item {
list-style-type: none;
}
.button--load-more {
background-color: $primary-color;
border-radius: 4px;
border-color: $primary-color;
color: #fff;
font-size: 1rem;
padding: 0.5rem 0.75rem;
text-transform: uppercase;
font-weight: 500;
box-shadow: 0 0;
cursor: pointer;
transition: background-color 0.2s ease-in, color 0.2s ease-in;
}
.button--load-more:hover {
background-color: #fff;
border: 1px solid $primary-color;
border-radius: 4px;
color: $primary-color;
}
.clear-filter-btn {
align-self: center;
margin-left: 20px;
}
.filtered-heading {
display: flex;
}
.pagination {
text-align: center;
}
.tooltip-ex {
/* Container for our tooltip */
position: relative;
display: inline-block;
cursor: help;
margin-right: 20px;
display: inline-block;
float: left;
}
.tooltip-ex-bottom {
top: 135%;
left: 50%;
margin-left: -60px;
}
.tooltip-ex-text {
visibility: hidden;
position: absolute;
width: 300px;
background-color: #555;
color: #fff;
text-align: center;
padding: 20px;
border-radius: 6px;
z-index: 1;
opacity: 0;
transition: opacity 0.6s;
}
.tooltip-ex:hover .tooltip-ex-text {
/* Makes tooltip visible when hovered on */
visibility: visible;
opacity: 1;
}
</style>