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