Skip to content

Commit b18f96c

Browse files
authored
Merge pull request #161 from otoyo/support-other-social-media
Support other social media
2 parents 4eb9c62 + 9ffc366 commit b18f96c

File tree

6 files changed

+267
-21
lines changed

6 files changed

+267
-21
lines changed

src/components/notion-blocks/Embed.astro

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
---
22
import * as interfaces from '../../lib/interfaces.ts'
3-
import { isTweetURL } from '../../lib/blog-helpers.ts'
3+
import {
4+
isTweetURL,
5+
isTikTokURL,
6+
isInstagramURL,
7+
isPinterestURL,
8+
} from '../../lib/blog-helpers.ts'
49
import Bookmark from './Bookmark.astro'
510
import TweetEmbed from './TweetEmbed.astro'
11+
import TikTokEmbed from './TikTokEmbed.astro'
12+
import InstagramEmbed from './InstagramEmbed.astro'
13+
import PinterestEmbed from './PinterestEmbed.astro'
614
715
export interface Props {
816
block: interfaces.Block
@@ -13,7 +21,7 @@ const { block, urlMap } = Astro.props
1321
1422
let url: URL
1523
try {
16-
url = block.Embed.Url
24+
url = new URL(block.Embed.Url)
1725
} catch (err) {
1826
console.log(err)
1927
}
@@ -22,22 +30,15 @@ try {
2230
{
2331
url ? (
2432
isTweetURL(url) ? (
25-
<div class="tweet-embed">
26-
<TweetEmbed url={url} />
27-
</div>
33+
<TweetEmbed url={url} />
34+
) : isTikTokURL(url) ? (
35+
<TikTokEmbed url={url} />
36+
) : isInstagramURL(url) ? (
37+
<InstagramEmbed url={url} />
38+
) : isPinterestURL(url) ? (
39+
<PinterestEmbed url={url} />
2840
) : (
2941
<Bookmark block={block} urlMap={urlMap} />
3042
)
3143
) : null
3244
}
33-
34-
<style>
35-
.tweet-embed {
36-
width: 100%;
37-
max-width: 600px;
38-
margin: auto;
39-
}
40-
.tweet-embed div:first-child div:first-child {
41-
margin: auto;
42-
}
43-
</style>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
export interface Props {
3+
url: string
4+
}
5+
const { url } = Astro.props
6+
const id = url.pathname.split('/')[2]
7+
---
8+
9+
<blockquote
10+
class="instagram-media"
11+
data-instgrm-captioned
12+
data-instgrm-permalink={`https://www.instagram.com/reel/${id}/?utm_source=ig_embed&utm_campaign=loading`}
13+
data-instgrm-version="14"
14+
style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:540px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"
15+
>
16+
<div style="padding:16px;">
17+
<a
18+
href={`https://www.instagram.com/reel/${id}/?utm_source=ig_embed&utm_campaign=loading`}
19+
style=" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;"
20+
target="_blank"
21+
>
22+
<div style=" display: flex; flex-direction: row; align-items: center;">
23+
<div
24+
style="background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;"
25+
>
26+
</div>
27+
<div
28+
style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center;"
29+
>
30+
<div
31+
style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;"
32+
>
33+
</div>
34+
<div
35+
style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;"
36+
>
37+
</div>
38+
</div>
39+
</div><div style="padding: 19% 0;"></div>
40+
<div style="display:block; height:50px; margin:0 auto 12px; width:50px;">
41+
<svg
42+
width="50px"
43+
height="50px"
44+
viewBox="0 0 60 60"
45+
version="1.1"
46+
xmlns="https://www.w3.org/2000/svg"
47+
xmlns:xlink="https://www.w3.org/1999/xlink"
48+
><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"
49+
><g transform="translate(-511.000000, -20.000000)" fill="#000000"
50+
><g
51+
><path
52+
d="M556.869,30.41 C554.814,30.41 553.148,32.076 553.148,34.131 C553.148,36.186 554.814,37.852 556.869,37.852 C558.924,37.852 560.59,36.186 560.59,34.131 C560.59,32.076 558.924,30.41 556.869,30.41 M541,60.657 C535.114,60.657 530.342,55.887 530.342,50 C530.342,44.114 535.114,39.342 541,39.342 C546.887,39.342 551.658,44.114 551.658,50 C551.658,55.887 546.887,60.657 541,60.657 M541,33.886 C532.1,33.886 524.886,41.1 524.886,50 C524.886,58.899 532.1,66.113 541,66.113 C549.9,66.113 557.115,58.899 557.115,50 C557.115,41.1 549.9,33.886 541,33.886 M565.378,62.101 C565.244,65.022 564.756,66.606 564.346,67.663 C563.803,69.06 563.154,70.057 562.106,71.106 C561.058,72.155 560.06,72.803 558.662,73.347 C557.607,73.757 556.021,74.244 553.102,74.378 C549.944,74.521 548.997,74.552 541,74.552 C533.003,74.552 532.056,74.521 528.898,74.378 C525.979,74.244 524.393,73.757 523.338,73.347 C521.94,72.803 520.942,72.155 519.894,71.106 C518.846,70.057 518.197,69.06 517.654,67.663 C517.244,66.606 516.755,65.022 516.623,62.101 C516.479,58.943 516.448,57.996 516.448,50 C516.448,42.003 516.479,41.056 516.623,37.899 C516.755,34.978 517.244,33.391 517.654,32.338 C518.197,30.938 518.846,29.942 519.894,28.894 C520.942,27.846 521.94,27.196 523.338,26.654 C524.393,26.244 525.979,25.756 528.898,25.623 C532.057,25.479 533.004,25.448 541,25.448 C548.997,25.448 549.943,25.479 553.102,25.623 C556.021,25.756 557.607,26.244 558.662,26.654 C560.06,27.196 561.058,27.846 562.106,28.894 C563.154,29.942 563.803,30.938 564.346,32.338 C564.756,33.391 565.244,34.978 565.378,37.899 C565.522,41.056 565.552,42.003 565.552,50 C565.552,57.996 565.522,58.943 565.378,62.101 M570.82,37.631 C570.674,34.438 570.167,32.258 569.425,30.349 C568.659,28.377 567.633,26.702 565.965,25.035 C564.297,23.368 562.623,22.342 560.652,21.575 C558.743,20.834 556.562,20.326 553.369,20.18 C550.169,20.033 549.148,20 541,20 C532.853,20 531.831,20.033 528.631,20.18 C525.438,20.326 523.257,20.834 521.349,21.575 C519.376,22.342 517.703,23.368 516.035,25.035 C514.368,26.702 513.342,28.377 512.574,30.349 C511.834,32.258 511.326,34.438 511.181,37.631 C511.035,40.831 511,41.851 511,50 C511,58.147 511.035,59.17 511.181,62.369 C511.326,65.562 511.834,67.743 512.574,69.651 C513.342,71.625 514.368,73.296 516.035,74.965 C517.703,76.634 519.376,77.658 521.349,78.425 C523.257,79.167 525.438,79.673 528.631,79.82 C531.831,79.965 532.853,80.001 541,80.001 C549.148,80.001 550.169,79.965 553.369,79.82 C556.562,79.673 558.743,79.167 560.652,78.425 C562.623,77.658 564.297,76.634 565.965,74.965 C567.633,73.296 568.659,71.625 569.425,69.651 C570.167,67.743 570.674,65.562 570.82,62.369 C570.966,59.17 571,58.147 571,50 C571,41.851 570.966,40.831 570.82,37.631"
53+
></path></g
54+
></g
55+
></g
56+
></svg
57+
>
58+
</div><div style="padding-top: 8px;">
59+
<div
60+
style=" color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;"
61+
>
62+
View this post on Instagram
63+
</div>
64+
</div><div style="padding: 12.5% 0;"></div>
65+
<div
66+
style="display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;"
67+
>
68+
<div>
69+
<div
70+
style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);"
71+
>
72+
</div>
73+
<div
74+
style="background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;"
75+
>
76+
</div>
77+
<div
78+
style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);"
79+
>
80+
</div>
81+
</div><div style="margin-left: 8px;">
82+
<div
83+
style=" background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;"
84+
>
85+
</div>
86+
<div
87+
style=" width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)"
88+
>
89+
</div>
90+
</div><div style="margin-left: auto;">
91+
<div
92+
style=" width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);"
93+
>
94+
</div>
95+
<div
96+
style=" background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);"
97+
>
98+
</div>
99+
<div
100+
style=" width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);"
101+
>
102+
</div>
103+
</div>
104+
</div>
105+
<div
106+
style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center; margin-bottom: 24px;"
107+
>
108+
<div
109+
style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 224px;"
110+
>
111+
</div>
112+
<div
113+
style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 144px;"
114+
>
115+
</div>
116+
</div></a
117+
><p
118+
style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;"
119+
>
120+
<a
121+
href={`https://www.instagram.com/reel/${id}/?utm_source=ig_embed&utm_campaign=loading`}
122+
style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;"
123+
target="_blank">A post shared by Instagram</a
124+
>
125+
</p>
126+
</div>
127+
</blockquote>
128+
129+
<script async src="//www.instagram.com/embed.js"></script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
export interface Props {
3+
url: string
4+
}
5+
const { url } = Astro.props
6+
---
7+
8+
<a href={url.toString()} data-pin-do="embedPin"></a>
9+
10+
<script
11+
type="text/javascript"
12+
async
13+
defer
14+
src="//assets.pinterest.com/js/pinit.js"
15+
></script>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
export interface Props {
3+
url: string
4+
}
5+
const { url } = Astro.props
6+
const user = url.pathname.split('/')[1]
7+
const videoId = url.pathname.split('/')[3]
8+
---
9+
10+
<blockquote
11+
class="tiktok-embed"
12+
cite={url.toString()}
13+
data-video-id={videoId}
14+
style="max-width: 605px;min-width: 325px;"
15+
>
16+
<section>
17+
<a
18+
target="_blank"
19+
title={user}
20+
href="https://www.tiktok.com/{user}?refer=embed">{user}</a
21+
><a
22+
title="foryoupage"
23+
target="_blank"
24+
href="https://www.tiktok.com/tag/foryoupage?refer=embed">#foryoupage</a
25+
>
26+
<a
27+
title="petsoftiktok"
28+
target="_blank"
29+
href="https://www.tiktok.com/tag/petsoftiktok?refer=embed"
30+
>#petsoftiktok</a
31+
>
32+
<a
33+
title="aesthetic"
34+
target="_blank"
35+
href="https://www.tiktok.com/tag/aesthetic?refer=embed">#aesthetic</a
36+
>
37+
<a
38+
target="_blank"
39+
title="♬ original sound - tiff"
40+
href="https://www.tiktok.com/music/original-sound-6689804660171082501?refer=embed"
41+
>♬ original sound - tiff</a
42+
>
43+
</section>
44+
</blockquote>
45+
46+
<script async src="https://www.tiktok.com/embed.js"></script>

src/components/notion-blocks/TweetEmbed.astro

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ export interface Props {
44
}
55
66
const { url } = Astro.props
7+
8+
const postURL =
9+
url.hostname === 'x.com' || url.hostname === 'www.x.com'
10+
? new URL(url.pathname, 'https://twitter.com')
11+
: url
712
---
813

9-
<blockquote class="twitter-tweet">
10-
<a href={url}></a>
11-
</blockquote>
14+
<div class="tweet-embed">
15+
<blockquote class="twitter-tweet">
16+
<a href={postURL}></a>
17+
</blockquote>
18+
</div>
1219

13-
<script is:inline>
20+
<script>
1421
window.twttr = (function (d, s, id) {
1522
var js,
1623
fjs = d.getElementsByTagName(s)[0],
@@ -29,3 +36,14 @@ const { url } = Astro.props
2936
return t
3037
})(document, 'script', 'twitter-wjs')
3138
</script>
39+
40+
<style>
41+
.tweet-embed {
42+
width: 100%;
43+
max-width: 640px;
44+
margin: auto;
45+
}
46+
.tweet-embed div:first-child div:first-child {
47+
margin: auto;
48+
}
49+
</style>

src/lib/blog-helpers.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,44 @@ export const buildHeadingId = (heading: Heading1 | Heading2 | Heading3) => {
180180
}
181181

182182
export const isTweetURL = (url: URL): boolean => {
183-
return /https:\/\/twitter.com\/[^/]+\/status\/[\d]+/.test(url.toString())
183+
if (
184+
url.hostname !== 'twitter.com' &&
185+
url.hostname !== 'www.twitter.com' &&
186+
url.hostname !== 'x.com' &&
187+
url.hostname !== 'www.x.com'
188+
) {
189+
return false
190+
}
191+
return /\/[^/]+\/status\/[\d]+/.test(url.pathname)
192+
}
193+
194+
export const isTikTokURL = (url: URL): boolean => {
195+
if (url.hostname !== 'tiktok.com' && url.hostname !== 'www.tiktok.com') {
196+
return false
197+
}
198+
return /\/[^/]+\/video\/[\d]+/.test(url.pathname)
199+
}
200+
201+
export const isInstagramURL = (url: URL): boolean => {
202+
if (
203+
url.hostname !== 'instagram.com' &&
204+
url.hostname !== 'www.instagram.com'
205+
) {
206+
return false
207+
}
208+
return /\/p\/[^/]+/.test(url.pathname)
209+
}
210+
211+
export const isPinterestURL = (url: URL): boolean => {
212+
if (
213+
url.hostname !== 'pinterest.com' &&
214+
url.hostname !== 'www.pinterest.com' &&
215+
url.hostname !== 'pinterest.jp' &&
216+
url.hostname !== 'www.pinterest.jp'
217+
) {
218+
return false
219+
}
220+
return /\/pin\/[\d]+/.test(url.pathname)
184221
}
185222

186223
export const isYouTubeURL = (url: URL): boolean => {

0 commit comments

Comments
 (0)