web/src/components/form/Social.astro

134 lines · 3134 bytes

  1---
  2import Icon from '@components/form/FontAwesome.svelte';
  3import {
  4	site,
  5	title as defaultTitle,
  6	description as defaultDescription,
  7} from '@utils/config';
  8
  9interface Props {
 10	url?: string;
 11	title?: string;
 12	description?: string;
 13}
 14
 15const url = Astro.props.url || site;
 16const title = Astro.props.title || defaultTitle;
 17const description = Astro.props.description || defaultDescription;
 18
 19const encodedUrl = encodeURIComponent(url);
 20const encodedTitle = encodeURIComponent(title);
 21const encodedDescription = encodeURIComponent(description);
 22
 23const socialMedias = {
 24	mastodon: {
 25		url: `https://mastodon.social/share?text=${encodeURIComponent(`${title} ${description}`)}&url=${encodedUrl}`,
 26		title: 'Mastodon',
 27		icon: 'mastodon',
 28		color: '#6364FF',
 29	},
 30	twitter: {
 31		url: `https://twitter.com/intent/tweet?text=${encodeURIComponent(`${title} ${description}`)}&url=${url}`,
 32		title: 'Twitter',
 33		icon: 'twitter',
 34		color: '#444343',
 35	},
 36	reddit: {
 37		url: `https://reddit.com/submit?url=${encodedUrl}&title=${encodedTitle}`,
 38		title: 'Reddit',
 39		icon: 'reddit',
 40		color: '#FF4500',
 41	},
 42	linkedIn: {
 43		url: `https://www.linkedin.com/shareArticle?mini=true&url=${encodedUrl}&title=${encodedTitle}&summary=${encodedDescription}`,
 44		title: 'LinkedIn',
 45		icon: 'linkedin',
 46		color: '#0A66C2',
 47	},
 48	pinterest: {
 49		url: `https://pinterest.com/pin/create/button/?url=${encodedUrl}&description=${encodedTitle}`,
 50		title: 'Pinterest',
 51		icon: 'pinterest',
 52		color: '#BD081C',
 53	},
 54	telegram: {
 55		url: `https://t.me/share/url?url=${encodedUrl}&text=${encodeURIComponent(`${title} ${description}`)}`,
 56		title: 'Telegram',
 57		icon: 'telegram',
 58		color: '#26A5E4',
 59	},
 60	whatsapp: {
 61		url: `https://wa.me/?text=${encodedTitle} ${encodedUrl}`,
 62		title: 'WhatsApp',
 63		icon: 'whatsapp',
 64		color: '#25D366',
 65	},
 66	signal: {
 67		url: `https://signal.me/#p/+${encodedUrl}`,
 68		title: 'Signal',
 69		icon: 'signal',
 70		color: '#3A76F0',
 71	},
 72	pocket: {
 73		url: `https://getpocket.com/save?url=${encodedUrl}&title=${encodedTitle}`,
 74		title: 'Pocket',
 75		icon: 'pocket',
 76		color: '#EF3F56',
 77	},
 78};
 79---
 80
 81<ul class="social-share">
 82	{
 83		Object.entries(socialMedias).map(([platform, shareUrl]) => (
 84			<li style={`--color: ${shareUrl.color}`}>
 85				<a
 86					title={`Share on ${platform}`}
 87					href={shareUrl.url}
 88					target="_blank"
 89					rel="noopener noreferrer"
 90				>
 91					<Icon iconName={shareUrl.icon} />
 92				</a>
 93			</li>
 94		))
 95	}
 96</ul>
 97
 98<style lang="scss">
 99	.social-share {
100		list-style: none;
101		padding: 0;
102		display: flex;
103		gap: var(--space-sm);
104		flex-wrap: wrap;
105		li {
106			padding: 0;
107			margin: 0;
108			opacity: var(--opacity-subtle);
109			border: var(--border-light);
110			box-shadow: var(--shadow-xs);
111			border-radius: var(--curve-sm);
112			transition: var(--transition-normal);
113			background: var(--background-form);
114			a {
115				display: flex;
116				color: var(--foreground);
117				transition: var(--transition-normal);
118				padding: 4px;
119				:global(svg) {
120					width: 2rem;
121					height: 2rem;
122				}
123			}
124			&:hover {
125				box-shadow: var(--shadow-xs-hover);
126				border-radius: var(--curve-md);
127				opacity: 1;
128				a {
129					color: var(--color);
130				}
131			}
132		}
133	}
134</style>