Skip to content

Commit 94a3bb0

Browse files
committed
improvement: also use url of translation
1 parent 5fb617e commit 94a3bb0

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

lib/BlueskySender.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public function __construct(
2222

2323
public function sendPost($page)
2424
{
25-
2625
if (!$this->enabled) {
2726
return false;
2827
}
@@ -50,8 +49,8 @@ public function sendPost($page)
5049
}
5150

5251
try {
53-
$pageUrl = $page->url();
54-
$trimTextPosition = $this->calculatePostTextLength($page->url());
52+
$pageUrl = $this->getPostUrl($page);
53+
$trimTextPosition = $this->calculatePostTextLength($pageUrl);
5554
$language = 'en';
5655

5756
$message = $this->getTextFieldContent($page, $trimTextPosition);
@@ -61,6 +60,10 @@ public function sendPost($page)
6160
$language = $defaultLanguage->code();
6261
}
6362

63+
if ($this->forceLanguage !== false) {
64+
$language = $this->forceLanguage;
65+
}
66+
6467
$bluesky = new BlueskyApi();
6568
$bluesky->auth($this->handle, $this->password);
6669

lib/ExternalPostSender.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public function __construct(
1010
public ?array $textfields = null,
1111
public ?string $imagefield = null,
1212
public ?string $forceLanguage = null,
13+
public ?bool $usePermalinkUrl = null,
1314
private ?int $maxPostLength = null,
1415
public ?UrlChecks $urlChecks = null,
1516
public ?PageChecks $pageChecks = null
@@ -18,7 +19,8 @@ public function __construct(
1819

1920
$this->textfields = $textfields ?? option('mauricerenck.indieConnector.post.textfields', ['description']);
2021
$this->imagefield = $imagefield ?? option('mauricerenck.indieConnector.post.imagefield', false);
21-
$this->forceLanguage = $imagefield ?? option('mauricerenck.indieConnector.post.forceLanguage', false);
22+
$this->forceLanguage = $forceLanguage ?? option('mauricerenck.indieConnector.post.forceLanguage', false);
23+
$this->usePermalinkUrl = $usePermalinkUrl ?? option('mauricerenck.indieConnector.post.usePermalinkUrl', false);
2224
$this->maxPostLength = $maxPostLength ?? 300;
2325

2426
$this->urlChecks = $urlChecks ?? new UrlChecks();
@@ -60,6 +62,17 @@ public function getTextFieldContent($page, $trimTextPosition)
6062
return Str::short($content['title'], $trimTextPosition);
6163
}
6264

65+
public function getPostUrl($page)
66+
{
67+
$url = $page->url($this->forceLanguage);
68+
69+
if ($this->usePermalinkUrl) {
70+
$url = $page->permalink();
71+
}
72+
73+
return $url;
74+
}
75+
6376
public function calculatePostTextLength(string $url)
6477
{
6578
$urlLength = Str::length($url);

lib/MastodonSender.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public function sendPost($page)
6767
}
6868

6969
try {
70-
$pageUrl = $page->url();
71-
$trimTextPosition = $this->calculatePostTextLength($page->url());
70+
$pageUrl = $this->getPostUrl($page);
71+
$trimTextPosition = $this->calculatePostTextLength($pageUrl);
7272

7373
$message = $this->getTextFieldContent($page, $trimTextPosition);
7474
$message .= "\n" . $pageUrl;

0 commit comments

Comments
 (0)