Skip to content

Commit

Permalink
Merge branch 'release/3.5.10' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 9, 2025
2 parents a6aadc5 + 45ad94c commit f67e426
Show file tree
Hide file tree
Showing 29 changed files with 2,871 additions and 2,569 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# SEOmatic Changelog

## 3.5.10 - 2025.01.08
### Changed
* Encode the URI in the `canonical` `link` header ([#1519](https://github.com/nystudio107/craft-seomatic/issues/1519))
* Ensure that URLs that are a site index URL and have a path prefix strip trailing slashes as appropriate ([#717](https://github.com/nystudio107/craft-seomatic/issues/717)) ([#5675](https://github.com/craftcms/cms/issues/5675))

## 3.5.9 - 2024.12.21
### Changed
* If an incoming URL has a trailing slash, preserve it for things like the Canonical URL ([#1547](https://github.com/nystudio107/craft-seomatic/issues/1547))
Expand Down
2 changes: 1 addition & 1 deletion buildchain/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG TAG=20-alpine
FROM node:$TAG

RUN npm install -g npm@^10.0.0
RUN npm install -g npm@^11.0.0

WORKDIR /app/buildchain/

Expand Down
259 changes: 143 additions & 116 deletions buildchain/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-seomatic",
"description": "SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.",
"type": "craft-plugin",
"version": "3.5.9",
"version": "3.5.10",
"keywords": [
"craft",
"cms",
Expand Down
2 changes: 1 addition & 1 deletion docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG TAG=20-alpine
FROM node:$TAG

RUN npm install -g npm@^10.0.0
RUN npm install -g npm@^11.0.0

WORKDIR /app/

Expand Down
682 changes: 397 additions & 285 deletions docs/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/helpers/DynamicMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ public static function includeHttpHeaders()
if (is_array($href)) {
$headerValue = '';
foreach ($href as $hrefVal) {
$hrefVal = UrlHelper::encodeUrl($hrefVal);
$headerValue .= ('<' . $hrefVal . '>' . ',');
}
$headerValue = rtrim($headerValue, ',');
} else {
$href = UrlHelper::encodeUrl($href);
$headerValue = '<' . $href . '>';
}
$headerValue .= "; rel='canonical'";
Expand Down
51 changes: 50 additions & 1 deletion src/helpers/UrlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static function absoluteUrlWithProtocol($url): string
if ($generalConfig->addTrailingSlashesToUrls && !preg_match('/(.+\?.*)|(\.[^\/]+$)/', $url)) {
$url = rtrim($url, '/') . '/';
}
if (!$generalConfig->addTrailingSlashesToUrls && !$preserveTrailingSlash) {
if (!$generalConfig->addTrailingSlashesToUrls && (!$preserveTrailingSlash || self::urlIsSiteIndex($url))) {
$url = rtrim($url, '/');
}

Expand Down Expand Up @@ -219,6 +219,34 @@ public static function urlHasSubDir(string $url): bool
return !empty(parse_url(trim($url, '/'), PHP_URL_PATH));
}

/**
* See if the url is a site index, and if so, strip the trailing slash
* ref: https://github.com/craftcms/cms/issues/5675
*
* @param string $url
* @return bool
*/
public static function urlIsSiteIndex(string $url): bool
{
$sites = Craft::$app->getSites()->getAllSites();
$result = false;
foreach ($sites as $site) {
$sitePath = parse_url(self::siteUrl('/', null, null, $site->id), PHP_URL_PATH);
if (!empty($sitePath)) {
// Normalizes a URI path by trimming leading/ trailing slashes and removing double slashes
$sitePath = '/' . preg_replace('/\/\/+/', '/', trim($sitePath, '/'));
}
// Normalizes a URI path by trimming leading/ trailing slashes and removing double slashes
$url = '/' . preg_replace('/\/\/+/', '/', trim($url, '/'));
// See if this url ends with a site prefix, and thus is a site index
if (str_ends_with($url, $sitePath)) {
$result = true;
}
}

return $result;
}

/**
* Return the siteUrlOverride setting, which can be a string or an array of site URLs
* indexed by the site handle
Expand Down Expand Up @@ -250,6 +278,27 @@ public static function getSiteUrlOverrideSetting(?int $siteId = null): string
}
}

/**
* Encodes non-alphanumeric characters in a URL, except reserved characters and already-encoded characters.
*
* @param string $url
* @return string
* @since 4.13.0
*/
public static function encodeUrl(string $url): string
{
$parts = preg_split('/([:\/?#\[\]@!$&\'()*+,;=%])/', $url, flags: PREG_SPLIT_DELIM_CAPTURE);
$url = '';
foreach ($parts as $i => $part) {
if ($i % 2 === 0) {
$url .= urlencode($part);
} else {
$url .= $part;
}
}
return $url;
}

// Protected Methods
// =========================================================================

Expand Down
8 changes: 8 additions & 0 deletions src/web/assets/dist/assets/content-seo-BiyzyfRx.js

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
8 changes: 0 additions & 8 deletions src/web/assets/dist/assets/content-seo-CCLDRddz.js

This file was deleted.

Binary file not shown.
Binary file not shown.
Loading

0 comments on commit f67e426

Please sign in to comment.