@tryghost/social-urls 0.1.44 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +27 -2
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -40,8 +40,33 @@ module.exports.bluesky = function bluesky(username) {
|
|
|
40
40
|
* @returns {string}
|
|
41
41
|
*/
|
|
42
42
|
module.exports.mastodon = function mastodon(username) {
|
|
43
|
-
//
|
|
44
|
-
|
|
43
|
+
// Remove any leading @ symbols from the username
|
|
44
|
+
username = username.replace(/^@+/, '');
|
|
45
|
+
|
|
46
|
+
// Check if the input is in @username@instance format
|
|
47
|
+
if (username.includes('@') && !username.includes('/')) {
|
|
48
|
+
const [user, instance] = username.split('@');
|
|
49
|
+
return `https://${instance}/@${user}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Check if the input is in instance/@username format
|
|
53
|
+
if (username.includes('/@')) {
|
|
54
|
+
return `https://${username}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Check if the input is in hostInstance/@username@userInstance format
|
|
58
|
+
if (username.includes('/@') && username.includes('@', username.indexOf('/@') + 1)) {
|
|
59
|
+
return `https://${username}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// If we have a simple instance/username format
|
|
63
|
+
if (username.includes('/')) {
|
|
64
|
+
const [instance, user] = username.split('/');
|
|
65
|
+
return `https://${instance}/@${user}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Default case: assume it's a local handle on the instance
|
|
69
|
+
return `https://${username}`;
|
|
45
70
|
};
|
|
46
71
|
|
|
47
72
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/social-urls",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
4
4
|
"repository": "https://github.com/TryGhost/SDK/tree/main/packages/social-urls",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"should": "13.2.3",
|
|
24
24
|
"sinon": "20.0.0"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "5f82bd658f044ec36a0afef179eda718ccbaac7f"
|
|
27
27
|
}
|