fix(mastodon.php): add feed helper to improve handling of utf-8 charachters and html entities

This commit is contained in:
Cory Dransfeldt 2025-06-03 13:36:39 -07:00
parent ac39f029eb
commit c792427c07
No known key found for this signature in database
3 changed files with 11 additions and 5 deletions

View file

@ -85,15 +85,21 @@ class MastodonPostHandler extends ApiHandler
foreach ($rss->channel->item as $item) { foreach ($rss->channel->item as $item) {
$items[] = [ $items[] = [
"title" => (string) $item->title, "title" => $this->cleanText((string) $item->title),
"link" => (string) $item->link, "link" => (string) $item->link,
"description" => (string) $item->description, "description" => $this->cleanText((string) $item->description),
]; ];
} }
return $items; return $items;
} }
private function cleanText(string $text): string
{
$decoded = html_entity_decode($text, ENT_QUOTES | ENT_XML1, 'UTF-8');
return mb_convert_encoding($decoded, 'UTF-8', 'UTF-8');
}
private function postToMastodon(string $content): ?string private function postToMastodon(string $content): ?string
{ {
$headers = [ $headers = [

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "8.2.6", "version": "8.2.7",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "8.2.6", "version": "8.2.7",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"minisearch": "^7.1.2", "minisearch": "^7.1.2",

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "8.2.6", "version": "8.2.7",
"description": "The source for my personal site. Built using 11ty (and other tools).", "description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module", "type": "module",
"engines": { "engines": {