forked from kamranahmedse/developer-roadmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl.ts
27 lines (21 loc) · 1.08 KB
/
url.ts
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
import siteConfig from '../content/site.json';
export const prefixHost = (url: string) => {
// if it starts with forward slash then prefix site URL
// @todo proper handling of full URLs and trailing slashes
return /^\//.test(url) ? `${siteConfig?.url?.web}${url}` : url;
};
export const getTwitterUrl = (username: string) => {
return `https://twitter.com/${username}`;
};
export const getTwitterShareUrl = ({ text, url }: { text: string, url: string }) => {
return `https://twitter.com/intent/tweet?text=${text}&url=${encodeURI(prefixHost(url))}`;
};
export const getFacebookShareUrl = ({ text, url }: { text: string, url: string }) => {
return `https://www.facebook.com/sharer/sharer.php?quote=${text}&u=${encodeURI(prefixHost(url))}`;
};
export const getRedditShareUrl = ({ text, url }: { text: string, url: string }) => {
return `https://www.reddit.com/submit?title=${text}&url=${encodeURI(prefixHost(url))}`;
};
export const getHnShareUrl = ({ text, url }: { text: string, url: string }) => {
return `https://news.ycombinator.com/submitlink?t=${text}&u=${prefixHost(url)}`;
};