Skip to content

Commit 2653b4f

Browse files
committed
parse links in posts
1 parent 3a1bbdf commit 2653b4f

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

components/bluesky/actions/create-post/create-post.mjs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "bluesky-create-post",
66
name: "Create Post",
77
description: "Creates a new post on Bluesky. [See the documentation](https://docs.bsky.app/docs/api/com-atproto-repo-create-record).",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
app,
@@ -15,6 +15,40 @@ export default {
1515
description: "The text content of the post.",
1616
},
1717
},
18+
methods: {
19+
parseUrls(text) {
20+
const spans = [];
21+
const urlRegex = /(?:[$|\W])(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*[-a-zA-Z0-9@%_+~#//=])?)/g;
22+
23+
let match;
24+
while ((match = urlRegex.exec(text)) !== null) {
25+
spans.push({
26+
start: match.index + 1,
27+
end: urlRegex.lastIndex,
28+
url: match[1],
29+
});
30+
}
31+
return spans;
32+
},
33+
parseFacets(text) {
34+
const facets = [];
35+
for (const link of this.parseUrls(text)) {
36+
facets.push({
37+
index: {
38+
byteStart: link["start"],
39+
byteEnd: link["end"],
40+
},
41+
features: [
42+
{
43+
["$type"]: "app.bsky.richtext.facet#link",
44+
uri: link["url"],
45+
},
46+
],
47+
});
48+
}
49+
return facets;
50+
},
51+
},
1852
async run({ $ }) {
1953
const {
2054
app,
@@ -28,6 +62,7 @@ export default {
2862
record: {
2963
["$type"]: constants.RESOURCE_TYPE.POST,
3064
text,
65+
facets: this.parseFacets(text),
3166
createdAt: new Date().toISOString(),
3267
},
3368
},

components/bluesky/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/bluesky",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Pipedream Bluesky Components",
55
"main": "bluesky.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)