Skip to content

Commit e97469c

Browse files
feat(syndicator-mastodon): default url option to mastodon.social
1 parent 5b9fd9a commit e97469c

File tree

3 files changed

+16
-36
lines changed

3 files changed

+16
-36
lines changed

packages/syndicator-mastodon/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ When sharing content to Mastodon using this syndicator, any post visibility sett
4444
| Option | Type | Description |
4545
| :----------------- | :-------- | :------------------------------------------------------------------------------------------------------------ |
4646
| `accessToken` | `string` | Your Mastodon access token. _Required_, defaults to `process.env.MASTODON_ACCESS_TOKEN`. |
47-
| `url` | `string` | Your Mastodon server, i.e. `https://mastodon.social`. _Required_. |
4847
| `user` | `string` | Your Mastodon username (without the `@`). _Required_. |
48+
| `url` | `string` | Your Mastodon server. _Optional_, defaults to `https://mastodon.social`. |
4949
| `characterLimit` | `number` | Maximum number of characters before a post is truncated. _Optional_, defaults to `500`. |
5050
| `checked` | `boolean` | Tell a Micropub client whether this syndicator should be enabled by default. _Optional_, defaults to `false`. |
5151
| `includePermalink` | `boolean` | Always include a link to the original post. _Optional_, defaults to `false`. |

packages/syndicator-mastodon/index.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { mastodon } from "./lib/mastodon.js";
77

88
const defaults = {
99
accessToken: process.env.MASTODON_ACCESS_TOKEN,
10+
url: "https://mastodon.social",
1011
characterLimit: 500,
1112
checked: false,
1213
includePermalink: false,
@@ -28,54 +29,42 @@ export default class MastodonSyndicator {
2829
}
2930

3031
get #url() {
31-
return this.options?.url ? new URL(this.options.url) : false;
32+
return new URL(this.options.url);
3233
}
3334

3435
get #user() {
35-
return this.options?.user
36-
? `@${this.options.user.replace("@", "")}`
37-
: false;
36+
return this.options?.user ? `@${this.options.user.replace("@", "")}` : "";
3837
}
3938

4039
get environment() {
4140
return ["MASTODON_ACCESS_TOKEN"];
4241
}
4342

4443
get info() {
45-
const service = {
46-
name: "Mastodon",
47-
photo: "/assets/@indiekit-syndicator-mastodon/icon.svg",
48-
};
4944
const user = this.#user;
5045
const url = this.#url;
51-
52-
if (!url) {
53-
return {
54-
error: "Server URL required",
55-
service,
56-
};
57-
}
58-
59-
if (!user) {
60-
return {
61-
error: "User name required",
62-
service,
63-
};
64-
}
65-
6646
const uid = `${url.protocol}//${path.join(url.hostname, user)}`;
67-
service.url = url.href;
6847

69-
return {
48+
const info = {
7049
checked: this.options.checked,
7150
name: `${user}@${url.hostname}`,
7251
uid,
73-
service,
52+
service: {
53+
name: "Mastodon",
54+
photo: "/assets/@indiekit-syndicator-mastodon/icon.svg",
55+
url: url.href,
56+
},
7457
user: {
7558
name: user,
7659
url: uid,
7760
},
7861
};
62+
63+
if (!user) {
64+
info.error = "User name required";
65+
}
66+
67+
return info;
7968
}
8069

8170
get prompts() {

packages/syndicator-mastodon/test/index.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ describe("syndicator-mastodon", () => {
3636
assert.ok(mastodon.info.service);
3737
});
3838

39-
it("Returns error information if no server URL provided", async () => {
40-
const result = new MastodonSyndicator({
41-
accessToken: "token",
42-
user: "username",
43-
});
44-
45-
assert.equal(result.info.error, "Server URL required");
46-
});
47-
4839
it("Returns error information if no username provided", () => {
4940
const result = new MastodonSyndicator({
5041
accessToken: "token",

0 commit comments

Comments
 (0)