Skip to content

Commit 24e4a92

Browse files
feat: add forum topic section
1 parent 885ec89 commit 24e4a92

File tree

3 files changed

+176
-2
lines changed

3 files changed

+176
-2
lines changed

src/components/ForumTopics.vue

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<template>
2+
<div>
3+
<ul>
4+
<li v-for="topic in topicData.topics">
5+
<a
6+
:href="`https://discourse-earthcode.eox.at/t/${topic.slug}`"
7+
target="_blank"
8+
>
9+
<span class="title">{{ topic.unicode_title || topic.title }}</span>
10+
<span class="excerpt">{{
11+
topic.excerpt?.replace("&hellip\;", " ...")
12+
}}</span>
13+
<span class="date">{{
14+
new Date(topic.bumped_at).toLocaleDateString()
15+
}}</span>
16+
<span class="posts">
17+
<img
18+
v-for="avatar in new Set([
19+
...topicData.posts
20+
.filter((p) => p.topic_id === topic.id)
21+
.map((p) => p.avatar_template),
22+
])"
23+
:src="`https://discourse-earthcode.eox.at${avatar.replace(
24+
'{size}',
25+
'28'
26+
)}`"
27+
/>
28+
{{ topicData.posts.filter((p) => p.topic_id === topic.id).length }}
29+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
30+
<title>message-text-outline</title>
31+
<path
32+
fill="#C2C8CC"
33+
d="M20,2A2,2 0 0,1 22,4V16A2,2 0 0,1 20,18H6L2,22V4C2,2.89 2.9,2 4,2H20M4,4V17.17L5.17,16H20V4H4M6,7H18V9H6V7M6,11H15V13H6V11Z"
34+
/>
35+
</svg>
36+
{{ topic.posts_count }}
37+
</span>
38+
</a>
39+
</li>
40+
</ul>
41+
<i>
42+
<span v-if="topicData.topics?.length < 1">
43+
No related topics found?
44+
</span>
45+
<span v-else> Didn't find what you were looking for? </span>
46+
<a
47+
:href="`https://discourse-earthcode.eox.at/new-topic?title=${
48+
stacData.title
49+
}&category=Data & Workflows&tags=${capitalize(
50+
stacData['osc:type']
51+
)},${stacData.keywords?.join(',')},STAC`"
52+
target="_blank"
53+
><strong>Start a new topic on the EarthCODE forum</strong></a
54+
>!</i
55+
>
56+
</div>
57+
</template>
58+
59+
<script>
60+
export default {
61+
props: {
62+
stacData: {
63+
type: Object,
64+
default: {},
65+
},
66+
topicData: {
67+
type: Object,
68+
default: {},
69+
},
70+
},
71+
methods: {
72+
capitalize(s) {
73+
return String(s[0]).toUpperCase() + String(s).slice(1);
74+
},
75+
},
76+
};
77+
</script>
78+
79+
<style scoped>
80+
ul {
81+
padding: 0;
82+
}
83+
li {
84+
list-style: none;
85+
}
86+
li a {
87+
background: #fff;
88+
border: 1px solid #c2c8cc;
89+
border-radius: 8px;
90+
padding: 24px;
91+
margin-bottom: 12px;
92+
display: grid;
93+
grid-template-areas:
94+
"title"
95+
"date"
96+
"posts"
97+
"excerpt";
98+
gap: 16px;
99+
transition: all ease-in-out 0.3s;
100+
text-decoration: none;
101+
}
102+
.title {
103+
font-family: NotesESAbold, sans-serif;
104+
font-size: 18px;
105+
line-height: 27px;
106+
grid-area: title;
107+
margin-bottom: 8px;
108+
}
109+
.date {
110+
grid-area: date;
111+
color: #647078;
112+
font-size: 16px;
113+
line-height: 25px;
114+
}
115+
.excerpt {
116+
grid-area: excerpt;
117+
color: #8a969e;
118+
font-size: 16px;
119+
line-height: 25px;
120+
}
121+
.posts {
122+
grid-area: posts;
123+
display: flex;
124+
align-items: center;
125+
font-size: 16px;
126+
line-height: 25px;
127+
}
128+
.posts img {
129+
width: 28px;
130+
height: 28px;
131+
border-radius: 50%;
132+
margin-right: 8px;
133+
}
134+
.posts img:nth-child(n + 2) {
135+
margin-left: -20px;
136+
}
137+
.posts svg {
138+
margin-left: 16px;
139+
margin-right: 8px;
140+
height: 28px;
141+
}
142+
@media (min-width: 640px) {
143+
li a {
144+
grid-template-areas:
145+
"title date"
146+
"excerpt posts";
147+
}
148+
.date,
149+
.posts {
150+
justify-self: self-end;
151+
}
152+
}
153+
</style>

src/locales/en/custom.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"Time of Data begins": "Start date",
99
"Time of Data ends": "End date"
1010
},
11-
"browse": "Overview"
11+
"browse": "Overview",
12+
"topics": "Related EarthCODE Forum Topics"
1213
}

src/views/Catalog.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
</b-tabs>
3535
</b-card>
3636
</section>
37+
<section v-if="isCollection" class="mb-4">
38+
<h2>{{ $t('topics') }}</h2>
39+
<ForumTopics
40+
v-if="forumTopicData"
41+
:stacData="data"
42+
:topicData="forumTopicData"
43+
/>
44+
</section>
3745
<Assets v-if="hasAssets" :assets="assets" :context="data" :shown="shownAssets" @showAsset="showAsset" />
3846
<Assets v-if="hasItemAssets && !hasItems" :assets="data.item_assets" :context="data" :definition="true" />
3947
<Providers v-if="providers" :providers="providers" />
@@ -62,6 +70,7 @@
6270
import { mapState, mapGetters } from 'vuex';
6371
import Catalogs from '../components/Catalogs.vue';
6472
import Description from '../components/Description.vue';
73+
import ForumTopics from "../components/ForumTopics";
6574
import Items from '../components/Items.vue';
6675
import ReadMore from "vue-read-more-smooth";
6776
import ShowAssetMixin from '../components/ShowAssetMixin';
@@ -82,6 +91,7 @@ export default {
8291
CollectionLink: () => import('../components/CollectionLink.vue'),
8392
DeprecationNotice: () => import('../components/DeprecationNotice.vue'),
8493
Description,
94+
ForumTopics,
8595
Items,
8696
Keywords: () => import('../components/Keywords.vue'),
8797
Links: () => import('../components/Links.vue'),
@@ -131,7 +141,8 @@ export default {
131141
'auth:schemes',
132142
// Special handling for the STAC Browser config
133143
'stac_browser'
134-
]
144+
],
145+
forumTopicData: null,
135146
};
136147
},
137148
computed: {
@@ -235,6 +246,15 @@ export default {
235246
}
236247
}
237248
},
249+
async mounted() {
250+
const response = await fetch(`https://discourse-earthcode.eox.at/search.json?q=${this.data.title}`);
251+
if (!response.ok) {
252+
// TODO handle error
253+
return;
254+
}
255+
256+
this.forumTopicData = await response.json();
257+
},
238258
methods: {
239259
filtersShown(show) {
240260
this.$store.commit('updateState', {type: 'itemFilterOpen', value: show ? 1 : null});

0 commit comments

Comments
 (0)