Skip to content

Commit 2c69291

Browse files
authored
Feat/add telegram share (#73)
1 parent 2fd29b3 commit 2c69291

File tree

6 files changed

+41
-28
lines changed

6 files changed

+41
-28
lines changed

src/components/PostReactions.vue

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,29 @@ import {
66
type Reactions,
77
} from "@/ts/types/reactions"
88
import type { Mentions } from "@/ts/types/mentions"
9+
import { getLangFromUrl, useTranslations } from "@/i18n/utils"
10+
import { urlBuilder } from "@/ts/functions"
911
1012
const props = defineProps<{
1113
url: URL
1214
title: string
1315
author: string
16+
instantView?: string
1417
}>()
1518
19+
const lang = getLangFromUrl(props.url)
20+
const t = useTranslations(lang)
21+
22+
const apiUrl = "https://webmention.io/api"
23+
const reactions = ref<Reaction[]>([])
24+
1625
function getMentionsUrl(props: Mentions.Props): string {
1726
return urlBuilder(`${props.apiUrl}/mentions.html`, {
1827
target: props.postUrl,
1928
"wm-property": props?.filter,
2029
}).toString()
2130
}
2231
23-
const apiUrl = "https://webmention.io/api"
24-
const reactions = ref<Reaction[]>([])
2532
const mentions = reactive({
2633
count: 0,
2734
url: getMentionsUrl({
@@ -31,25 +38,14 @@ const mentions = reactive({
3138
}),
3239
})
3340
34-
function urlBuilder(
35-
baseUrl: string,
36-
queryParameters: Record<string, string | undefined | null>,
37-
): URL {
38-
const result = new URL(baseUrl)
39-
40-
Object.entries(queryParameters).forEach(([key, value]) => {
41-
if (value) result.searchParams.append(key, value)
42-
})
43-
44-
return result
45-
}
46-
47-
const twitterLink = computed(() =>
48-
urlBuilder("https://twitter.com/intent/tweet", {
49-
original_referer: `${props.url.origin}`,
50-
text: props.title,
51-
url: props.url.href,
52-
via: props.author,
41+
const telegramLink = computed(() =>
42+
urlBuilder("https://t.me/share/url", {
43+
url: props.instantView
44+
? urlBuilder("https://t.me/iv", {
45+
url: props.url.href,
46+
rhash: props.instantView,
47+
}).toString()
48+
: props.url.href,
5349
}).toString(),
5450
)
5551
@@ -89,11 +85,11 @@ onMounted(() => fetchReactions())
8985

9086
<div class="flex justify-between items-center">
9187
<a
92-
class="text-sm bg-[#1da1f2] text-white rounded py-1 px-2 flex gap-2"
93-
:href="twitterLink"
88+
class="text-sm bg-[#54a9eb] text-white rounded py-1 px-2 flex gap-2 capitalize"
89+
:href="telegramLink"
9490
>
95-
<span class="icon"><i class="fab fa-twitter"></i></span>
96-
<span>Tweet</span>
91+
<span class="icon"><i class="fab fa-telegram"></i></span>
92+
<span>{{ t("compartir") }}</span>
9793
</a>
9894

9995
<div class="reactions">

src/content.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ const authors = defineCollection({
2424
}),
2525
)
2626
.optional(),
27+
telegram: z
28+
.object({
29+
channel: z.string().optional(),
30+
instantView: z.string().optional(),
31+
})
32+
.default(() => ({})),
2733
}),
2834
})
2935

@@ -47,7 +53,7 @@ const posts = defineCollection({
4753
title: z.string(),
4854
date: z.coerce.date(),
4955

50-
categories: z.array(reference("categories")).default([]),
56+
categories: z.array(reference("categories")).default(() => []),
5157
hasInstantView: z.boolean().default(true),
5258

5359
canonicalUrl: z.string().optional(),

src/content/authors/halivert.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@
3434
"type": "linkedin",
3535
"icon": "fab fa-linkedin"
3636
}
37-
]
37+
],
38+
"telegram": {
39+
"channel": "@halivertsblog",
40+
"instantView": "ff503d2109b312"
41+
}
3842
}

src/content/blog/2019-03-01-mathematical-induction.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ author: halivert
33
categories: ["Matemáticas"]
44
date: "2019-03-01 11:03"
55
hasMath: true
6+
hasInstantView: false
67
tags: ["Inducción"]
78
title: "Inducción matemática"
89
---

src/i18n/ui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,6 @@ export const ui = {
8383
Sitio: "Site",
8484
por: "by",
8585
publicado: "posted",
86+
compartir: "share",
8687
},
8788
} as const

src/pages/blog/[...slug].astro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const tags = Object.fromEntries(
2828
const authorTelegramUrl =
2929
author?.data.social?.find(({ type }) => type === "telegram")?.url ?? ""
3030
31+
const telegram = author?.data.telegram
32+
3133
const lang = getLangFromUrl(Astro.url)
3234
const t = useTranslations(lang)
3335
@@ -54,7 +56,7 @@ function getTagClass(tag: string): string {
5456

5557
<meta property="author:name" content={author?.data.firstName ?? ""} />
5658
<meta property="telegram:author" content={authorTelegramUrl} />
57-
<meta property="telegram:channel" content="@halivertsblog" />
59+
<meta property="telegram:channel" content={telegram.channel} />
5860

5961
<meta property="og:title" content={post.data.title} />
6062
<meta property="author" content={post.data.author.id} />
@@ -168,6 +170,9 @@ function getTagClass(tag: string): string {
168170
client:load
169171
url={Astro.url}
170172
author={author?.data.username ?? ""}
173+
instantView={post.data.hasInstantView
174+
? telegram.instantView
175+
: undefined}
171176
title={post.data.title}
172177
/>
173178

0 commit comments

Comments
 (0)