diff options
| author | winter | 2025-01-26 17:23:11 +0000 |
|---|---|---|
| committer | winter | 2025-01-26 17:23:11 +0000 |
| commit | df5ead7bd4adac405811b91fed1e5f0b3775206b (patch) | |
| tree | 20402ccab2fba3af35a83bd034f13876aabd4f5b | |
| parent | e8106abb8006f5e60e1f2d42621c64ae3d78e372 (diff) | |
add link preview metadata
| -rw-r--r-- | Digitigrade/Model/Actor.php | 4 | ||||
| -rw-r--r-- | templates/actor_profile_page.php | 7 | ||||
| -rw-r--r-- | templates/skeleton.php | 19 | ||||
| -rw-r--r-- | templates/thread_page.php | 7 |
4 files changed, 33 insertions, 4 deletions
diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php index f2eecae..62d1b39 100644 --- a/Digitigrade/Model/Actor.php +++ b/Digitigrade/Model/Actor.php @@ -286,8 +286,8 @@ class Actor extends PushableModel implements RpcReceiver { return $instances; } - public function getFullHandle(): string { - return $this->handle . ($this->isLocal ? '' : '@' . hostname_from_uri($this->uri)); + public function getFullHandle(bool $alwaysIncludeDomain = false): string { + return $this->handle . (($alwaysIncludeDomain || !$this->isLocal) ? '@' . hostname_from_uri($this->uri) : ''); } public function jsonSerialize(): array { diff --git a/templates/actor_profile_page.php b/templates/actor_profile_page.php index 3b6eb84..dbeb86a 100644 --- a/templates/actor_profile_page.php +++ b/templates/actor_profile_page.php @@ -5,7 +5,12 @@ use Digitigrade\Model\UserAccount; call_template('skeleton', [ 'pageTitle' => "$actor->displayName - @" . $actor->getFullHandle(), - 'renderTitleHeading' => false + 'renderTitleHeading' => false, + 'ogTitle' => $actor->displayName, + 'ogDesc' => $actor->bio, + 'ogImage' => $actor->avatar ?? path_to_uri('/static/default-avatar.png'), + 'ogType' => 'profile', + 'ogHandle' => '@' . $actor->getFullHandle(true) ], function () { global $actor; $user = UserAccount::findByCurrentSession(); diff --git a/templates/skeleton.php b/templates/skeleton.php index a9c3424..7f40611 100644 --- a/templates/skeleton.php +++ b/templates/skeleton.php @@ -11,6 +11,25 @@ $settings = GlobalSettings::getInstance(); <head> <title><?= $pageTitle ?> — <?= $settings->get('instance.name') ?></title> + <!-- metadata for link previews --> + <meta property="og:type" content="<?= $ogType ?? 'website' ?>"> + <meta name="twitter:card" content="summary"> + <meta property="og:title" content="<?= htmlspecialchars($ogTitle ?? $pageTitle) ?>"> + <meta name="twitter:title" content="<?= htmlspecialchars($ogTitle ?? $pageTitle) ?>"> + <meta property="og:site_name" content="<?= htmlspecialchars($settings->get('instance.name')) ?>"> + <?php if (isset($ogDesc)): ?> + <meta name="description" content="<?= htmlspecialchars($ogDesc) ?>"> + <meta property="og:description" content="<?= htmlspecialchars($ogDesc) ?>"> + <meta name="twitter:description" content="<?= htmlspecialchars($ogDesc) ?>"> + <?php endif; ?> + <?php if (isset($ogImage)): ?> + <meta property="og:image" content="<?= htmlspecialchars($ogImage) ?>"> + <meta name="twitter:image" content="<?= htmlspecialchars($ogImage) ?>"> + <?php endif; ?> + <?php if (isset($ogHandle)): ?> + <meta name="fediverse:creator" content="<?= $ogHandle ?>"> + <?php endif; ?> + <!-- other page resources --> <?php call_template('head_tags'); ?> </head> diff --git a/templates/thread_page.php b/templates/thread_page.php index 119f879..b46c968 100644 --- a/templates/thread_page.php +++ b/templates/thread_page.php @@ -4,7 +4,12 @@ use Digitigrade\Model\UserAccount; call_template('skeleton', [ 'pageTitle' => '"' . $note->plainContent . '" - @' . $note->author->getFullHandle(), - 'renderTitleHeading' => false + 'renderTitleHeading' => false, + 'ogTitle' => $note->author->displayName, + 'ogDesc' => $note->plainContent, + 'ogImage' => $note->author->avatar ?? path_to_uri('/static/default-avatar.png'), + 'ogType' => 'article', + 'ogHandle' => '@' . $note->author->getFullHandle(true) ], function () { global $note; $notes = Note::findAllInThread($note->threadApex ?? $note); |
