Skip to content

Commit d86dac0

Browse files
committed
feat: set a prefered language for posting to mastodon or bluesky
1 parent 94a3bb0 commit d86dac0

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ Use one of these three methods to install the plugin:
4343

4444
## Roadmap
4545

46+
- [x] Manual queue cleanup
4647
- [ ] Queue for sending webmentions
4748
- [ ] Queue for sending mastodon posts
4849
- [ ] Queue for sending bluesky posts
4950
- [ ] Nested indieweb replies
5051
- [ ] Blocklist for users on Mastodon and Bluesky
5152
- [ ] Manual post to Mastodon and Bluesky
52-
- [x] Manual queue cleanup
5353
- [ ] Block hosts from within the panel
5454
- [ ] Post complete texts to Mastodon and Bluesky splitted in threads
5555
- [ ] Option for using Kirby UUID permalinks in Mastodon/Bluesky posts

docs/mastodon.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ Depending on your Mastodon instance the text length may vary. The default is 500
4242
'mauricerenck.indieConnector.mastodon.text-length' => 500,
4343
```
4444

45+
### Setting a language
46+
47+
If you want to use another language than your default language to use the text from, you can set the following option:
48+
49+
```php
50+
'mauricerenck.indieConnector.post.prefereLanguage' => 'en',
51+
```
52+
53+
This might be handy if your default language is for example German but you only want to post in English on Mastodon or Bluesky. This way the english translation is used as a source for the text or title.
54+
55+
### Use the permalink URL
56+
57+
If you want to use the permalink URL instead of the page URL, you can set the following option:
58+
59+
```php
60+
'mauricerenck.indieConnector.post.usePermalinkUrl' => true,
61+
```
62+
63+
This url will never change, even if you change the slug of the page. This way you can ensure that the link in your Mastodon post will always work.
64+
65+
4566
### Get the URL of the post
4667

4768
If you want to display te URL of your Mastodon post on your page, so that people can use it to interact with your post, you can use the following page method:

docs/options.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@
6262

6363
## Posting to external services
6464

65-
| Option | Default | Description |
66-
| ----------------------- | ------------------ | ----------------------------------------------------------- |
67-
| `post.textfields` | `['description']` | Text source fields for posting elsewhere |
68-
| `post.imagefield` | `''` | Image source field for posting elsewhere, must be one image |
69-
| `post.allowedTemplates` | `[]` | Set templates allowed to send webmentions |
70-
| `post.blockedTemplates` | `[]` | Block templates from sending webmentions |
65+
| Option | Default | Description |
66+
| ----------------------- | ------------------ | -------------------------------------------------------------------- |
67+
| `post.prefereLanguage` | `-` | Use another language than your default language to use the text from |
68+
| `post.usePermalinkUrl` | `false` | Use the permalink url instead of the page url |
69+
| `post.textfields` | `['description']` | Text source fields for posting elsewhere |
70+
| `post.imagefield` | `''` | Image source field for posting elsewhere, must be one image |
71+
| `post.allowedTemplates` | `[]` | Set templates allowed to send webmentions |
72+
| `post.blockedTemplates` | `[]` | Block templates from sending webmentions |
7173

7274

7375
### Mastodon ([details](mastodon.md))

lib/BlueskySender.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public function sendPost($page)
6060
$language = $defaultLanguage->code();
6161
}
6262

63-
if ($this->forceLanguage !== false) {
64-
$language = $this->forceLanguage;
63+
if ($this->prefereLanguage !== false) {
64+
$language = $this->prefereLanguage;
6565
}
6666

6767
$bluesky = new BlueskyApi();

lib/ExternalPostSender.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ExternalPostSender extends Sender
99
public function __construct(
1010
public ?array $textfields = null,
1111
public ?string $imagefield = null,
12-
public ?string $forceLanguage = null,
12+
public ?string $prefereLanguage = null,
1313
public ?bool $usePermalinkUrl = null,
1414
private ?int $maxPostLength = null,
1515
public ?UrlChecks $urlChecks = null,
@@ -19,7 +19,7 @@ public function __construct(
1919

2020
$this->textfields = $textfields ?? option('mauricerenck.indieConnector.post.textfields', ['description']);
2121
$this->imagefield = $imagefield ?? option('mauricerenck.indieConnector.post.imagefield', false);
22-
$this->forceLanguage = $forceLanguage ?? option('mauricerenck.indieConnector.post.forceLanguage', false);
22+
$this->prefereLanguage = $prefereLanguage ?? option('mauricerenck.indieConnector.post.prefereLanguage', false);
2323
$this->usePermalinkUrl = $usePermalinkUrl ?? option('mauricerenck.indieConnector.post.usePermalinkUrl', false);
2424
$this->maxPostLength = $maxPostLength ?? 300;
2525

@@ -43,7 +43,7 @@ public function __construct(
4343

4444
public function getTextFieldContent($page, $trimTextPosition)
4545
{
46-
$pageOfLanguage = $page->translation($this->forceLanguage);
46+
$pageOfLanguage = $page->translation($this->prefereLanguage);
4747
$content = !is_null($pageOfLanguage) ? $pageOfLanguage->content() : $page->content()->toArray();
4848

4949
if (is_array($this->textfields)) {
@@ -64,7 +64,7 @@ public function getTextFieldContent($page, $trimTextPosition)
6464

6565
public function getPostUrl($page)
6666
{
67-
$url = $page->url($this->forceLanguage);
67+
$url = $page->url($this->prefereLanguage);
6868

6969
if ($this->usePermalinkUrl) {
7070
$url = $page->permalink();

lib/MastodonSender.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public function sendPost($page)
8484
$requestBody['language'] = $defaultLanguage->code();
8585
}
8686

87-
if ($this->forceLanguage !== false) {
88-
$requestBody['language'] = $this->forceLanguage;
87+
if ($this->prefereLanguage !== false) {
88+
$requestBody['language'] = $this->prefereLanguage;
8989
}
9090

9191
if ($mediaId = $this->uploadImage($page)) {

0 commit comments

Comments
 (0)