Skip to content

Commit 09e667e

Browse files
authored
Merge pull request #2314 from hydephp/resolve-final-todos
[2.x] Normalize @ and & in makeSlug helper
2 parents 60f6793 + db2dbc6 commit 09e667e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ If you have used any of the following selectors in custom code you wrote yoursel
414414
- Rename HTML ID `#searchMenuButton` to `#search-menu-button`
415415
- Rename HTML ID `#searchMenuButtonMobile` to `#search-menu-button-mobile`
416416

417+
### Edge case changes to slug generation
418+
419+
Slug generation now normalizes two symbols before slugging (@ → at, & → and). This may change permalinks for titles containing these symbols. (https://github.com/hydephp/develop/pull/2314)
420+
417421
### New documentation search implementation
418422

419423
As the new documentation search implementation brings changes to their code API you may need to adapt your code

packages/framework/src/Foundation/Concerns/ImplementsStringHelpers.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public static function makeSlug(string $value): string
4646
// Transliterate international characters to ASCII
4747
$value = Str::transliterate($value);
4848

49-
// Todo: In v2.0 we will use the following dictionary: ['@' => 'at', '&' => 'and']
49+
// Normalize a couple of common symbols before slugging (since v2)
50+
$value = strtr($value, [
51+
'@' => ' at ',
52+
'&' => ' and ',
53+
]);
5054

5155
return Str::slug($value);
5256
}

packages/framework/tests/Unit/HydeHelperFacadeMakeSlugTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testMakeSlugHelperHandlesMultipleSpaces()
4343

4444
public function testMakeSlugHelperHandlesSpecialCharacters()
4545
{
46-
$this->assertSame('hello-world', Hyde::makeSlug('Hello & World!'));
46+
$this->assertSame('hello-and-world', Hyde::makeSlug('Hello & World!'));
4747
}
4848

4949
public function testMakeSlugHelperConvertsUppercaseToLowercase()
@@ -111,7 +111,7 @@ public function testMakeSlugHelperHandlesComplexMixedInput()
111111
public function testMakeSlugHelperHandlesEdgeCases()
112112
{
113113
$this->assertSame('', Hyde::makeSlug(''));
114-
$this->assertSame('at', Hyde::makeSlug('!@#$%^&*()'));
114+
$this->assertSame('at-and', Hyde::makeSlug('!@#$%^&*()'));
115115
$this->assertSame('', Hyde::makeSlug('... ...'));
116116
$this->assertSame('multiple-dashes', Hyde::makeSlug('multiple---dashes'));
117117
}

0 commit comments

Comments
 (0)