Skip to content

Commit

Permalink
Fixed absolute URL including token query parameter
Browse files Browse the repository at this point in the history
Fixes #457
  • Loading branch information
Tam committed Aug 18, 2023
1 parent 215d51c commit f2b657b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.2.0 - 2023-08-18
### Fixed
- Fixed absolute URL including token query parameter (Fixes #457)
- Fixed error on Shopify plugin products (#456 via @ttempleton)

## 4.1.2 - 2023-05-15
### Fixed
- Fix robots always injecting no-index (Fixes #432)
Expand Down
14 changes: 14 additions & 0 deletions src/models/data/SeoData.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,20 @@ public function getCanonical ()
return UrlHelper::siteUrl($this->advanced['canonical']);
}

public function getAbsolute ()
{
$url = Craft::$app->getRequest()->getAbsoluteUrl();
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $parts);

if (empty($parts)) return $url;

// Remove token param
unset($parts['token']);

return preg_replace('/\?([^#]*)/m', '?' . http_build_query($parts), $url);
}

// Helpers
// =========================================================================

Expand Down
4 changes: 2 additions & 2 deletions src/templates/_seo/meta.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{% set fb = seo.social.facebook -%}
<meta property="fb:app_id" content="{{ fb.handle }}">
<meta property="og:url" content="{{ craft.app.request.absoluteUrl }}" />
<meta property="og:url" content="{{ seo.absolute }}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="{{ fb.title }}" />
<meta property="og:image" content="{{ craft.seo.facebookImage(fb.image) }}" />
Expand All @@ -29,7 +29,7 @@
{% set tw = seo.social.twitter -%}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="{{ tw.handle }}" />
<meta name="twitter:url" content="{{ craft.app.request.absoluteUrl }}" />
<meta name="twitter:url" content="{{ seo.absolute }}" />
<meta name="twitter:title" content="{{ tw.title }}" />
<meta name="twitter:description" content="{{ tw.description }}" />
<meta name="twitter:image" content="{{ craft.seo.twitterImage(tw.image) }}" />
Expand Down

0 comments on commit f2b657b

Please sign in to comment.