Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/Tags/AltSeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function meta_array()
'og_image' => $this->getSocialImage(),

'twitter_card' => 'summary_large_image',
'twitter_domain' => config('app.url'),
'twitter_domain' => $this->context->value('site')->url,
'twitter_url' => $this->getCanonical(),
'twitter_title' => $this->getSocialTitle(),
'twitter_description' => strip_tags($this->getSocialDescription()),
Expand All @@ -89,7 +89,7 @@ private function meta_array()
*/
public function replaceVars($string){
$blueprintPageTitle = $this->context->value('title'); // Page Title
$appName = $this->context->value('config.app.name'); // App Name
$appName = $this->context->value('site')->name; // App Name
$string = str_replace('{title}', $blueprintPageTitle, $string);
$string = str_replace('{site_name}', $appName, $string);
return $string;
Expand All @@ -112,7 +112,7 @@ public function getTitle()
return $this->replaceVars($title);
}

return $this->context->value('title') . ' | ' . $this->context->value('config.app.name');
return $this->context->value('title') . ' | ' . $this->context->value('site')->name;
}

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ public function getSocialTitle()
return $this->replaceVars($title);
}

return $this->context->value('title') . ' | ' . $this->context->value('config.app.name');
return $this->context->value('title') . ' | ' . $this->context->value('site')->name;
}

/**
Expand Down Expand Up @@ -211,18 +211,33 @@ public function getSocialImage()
{
$imageURL = '';
if(!empty($this->context->value('alt_seo_social_image'))) {
$imageURL = str_replace('/assets/', '', Antlers::parse($this->context->value('alt_seo_social_image')));
$imageURL = Antlers::parse($this->context->value('alt_seo_social_image'));
} else {
$data = new Data('settings');
if($data->get('alt_seo_social_image_default')) {
$image = $data->get('alt_seo_social_image_default');
$imageURL = str_replace('/assets/', '', $image);
$imageURL = $image;
}
}
$appUrl = config('app.url');
if(!empty($imageURL) && !str_contains($imageURL, $appUrl)) {
$imageURL = $appUrl . '/assets/' . $imageURL;

// If the image is an absolute URL (e.g., S3), use it as is
if (preg_match('/^https?:\/\//', $imageURL)) {
return $imageURL;
} else {
// Check if Statamic is configured to use S3 or local assets
$assetContainer = \Statamic\Facades\AssetContainer::findByHandle('assets');
$disk = $assetContainer ? $assetContainer->disk() : null;
$assetBaseUrl = $assetContainer ? $assetContainer->url() : null;

if ($disk && $assetBaseUrl && !empty($imageURL)) {
// Remove leading slash if present
$imageURL = ltrim($imageURL, '/');
$imageURL = rtrim($assetBaseUrl, '/') . '/' . $imageURL;
} else {
$imageURL = str_replace('/assets/', '', $imageURL);
}
}

return $imageURL;
}

Expand Down