Skip to content

Commit 4e3fdb7

Browse files
committed
Stylize external indicator
1 parent a89bae2 commit 4e3fdb7

3 files changed

Lines changed: 70 additions & 28 deletions

File tree

components/ExternalIndicator.vue

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<script setup>
2+
const props = defineProps({
3+
site: {
4+
type: String,
5+
default: "",
6+
},
7+
});
8+
</script>
9+
10+
<template>
11+
<div
12+
class="inline-flex items-center gap-1 rounded border border-orange-500/30 bg-orange-500/20 px-2 py-0.5"
13+
>
14+
<span
15+
class="text-[10px] leading-none uppercase tracking-wide text-orange-300"
16+
>External - {{ site }}</span
17+
>
18+
<svg
19+
xmlns="http://www.w3.org/2000/svg"
20+
viewBox="0 0 20 20"
21+
fill="currentColor"
22+
class="size-3 shrink-0 text-orange-300"
23+
>
24+
<path
25+
fill-rule="evenodd"
26+
d="M4.25 5.5a.75.75 0 0 0-.75.75v8.5c0 .414.336.75.75.75h8.5a.75.75 0 0 0 .75-.75v-4a.75.75 0 0 1 1.5 0v4A2.25 2.25 0 0 1 12.75 17h-8.5A2.25 2.25 0 0 1 2 14.75v-8.5A2.25 2.25 0 0 1 4.25 4h5a.75.75 0 0 1 0 1.5h-5Z"
27+
clip-rule="evenodd"
28+
/>
29+
<path
30+
fill-rule="evenodd"
31+
d="M6.194 12.753a.75.75 0 0 0 1.06.053L16.5 4.44v2.81a.75.75 0 0 0 1.5 0v-4.5a.75.75 0 0 0-.75-.75h-4.5a.75.75 0 0 0 0 1.5h2.553l-9.056 8.194a.75.75 0 0 0-.053 1.06Z"
32+
clip-rule="evenodd"
33+
/>
34+
</svg>
35+
</div>
36+
</template>

components/section/BlogPosts.vue

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ const props = defineProps({
33
articles: Object,
44
show_dates: false,
55
});
6+
7+
function externalSite(article) {
8+
if (!article?.external_url) return ''
9+
if (article?.external_site) return article.external_site
10+
try {
11+
const u = new URL(article.external_url)
12+
return u.hostname.replace(/^www\./, '')
13+
} catch {
14+
return article.external_url
15+
}
16+
}
617
</script>
718
819
<template>
@@ -20,22 +31,19 @@ const props = defineProps({
2031
>
2132
{{ article.title }}
2233
</div>
23-
<template v-if="article.external_url">
24-
<span
25-
class="rounded border border-orange-500/30 bg-orange-500/20 px-2 py-0.5 text-[10px] uppercase tracking-wide text-orange-300"
26-
>External</span
27-
>
28-
</template>
29-
<template v-if="show_dates">
30-
<NuxtTime
31-
:datetime="article.date"
32-
class="text-sm text-gray-200"
33-
year="numeric"
34-
month="short"
35-
day="2-digit"
36-
/>
37-
</template>
34+
<div class="flex items-center gap-2 md:ml-auto">
35+
<ExternalIndicator v-if="article.external_url" :site="externalSite(article)" />
36+
</div>
3837
</div>
38+
<template v-if="show_dates">
39+
<NuxtTime
40+
:datetime="article.date"
41+
class="text-xs text-gray-300"
42+
year="numeric"
43+
month="short"
44+
day="2-digit"
45+
/>
46+
</template>
3947
<div class="line-clamp-3 text-sm text-gray-100">
4048
{{
4149
article.description ||

pages/blog/index.vue

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ watch(
215215
<template v-for="article in paginatedArticles" :key="article._id">
216216
<NuxtLink :to="article.path" class="h-full">
217217
<div
218-
class="flex flex-col justify-between space-y-3 bg-black/50 p-4 text-white drop-shadow-lg hover:ring-1 hover:ring-white"
218+
class="flex flex-col justify-between space-y-2 bg-black/50 p-4 text-white drop-shadow-lg hover:ring-1 hover:ring-white"
219219
>
220220
<div class="space-y-1">
221221
<div
@@ -227,21 +227,19 @@ watch(
227227
{{ article.title }}
228228
</p>
229229
<div class="flex items-center gap-2 md:ml-auto">
230-
<template v-if="article.external_url">
231-
<span
232-
class="rounded border border-orange-500/30 bg-orange-500/20 px-2 py-0.5 text-[10px] uppercase tracking-wide text-orange-300"
233-
>{{ externalSite(article) }}</span
234-
>
235-
</template>
236-
<NuxtTime
237-
:datetime="article.date"
238-
class="text-sm text-gray-300 md:text-right"
239-
year="numeric"
240-
month="short"
241-
day="2-digit"
230+
<ExternalIndicator
231+
v-if="article.external_url"
232+
:site="externalSite(article)"
242233
/>
243234
</div>
244235
</div>
236+
<NuxtTime
237+
:datetime="article.date"
238+
class="text-xs text-gray-300"
239+
year="numeric"
240+
month="short"
241+
day="2-digit"
242+
/>
245243
</div>
246244
<p
247245
v-if="article.description"

0 commit comments

Comments
 (0)