-
-
Notifications
You must be signed in to change notification settings - Fork 25
🎨 Changed and improved the slug generation and validation #860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dittnamn
wants to merge
4
commits into
TryGhost:main
Choose a base branch
from
dittnamn:slug-upgrade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+70
−11
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
658f179
🎨 Changed and improved the slug generation and validation
dittnamn ac2ad0b
Updated validator and test to match the changes in slugify()
dittnamn fb4d3de
Updated validator to disallow leading combining marks after a separator
dittnamn f0582c0
Updated and simplified validator regex to do as intended along with
dittnamn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,19 @@ | ||
| const slugify = require('@tryghost/string').slugify; | ||
|
|
||
| // @TODO: the safe() function can possibly be removed from here if Ghost uses slugify() directly instead | ||
|
|
||
| /** | ||
| * @param {string} string | ||
| * @param {{importing?: boolean}} [options] | ||
| * @param {string} string - the string we want to slugify | ||
| * @param {object} [options] - filter options | ||
| * @param {bool} [options.importing] - don't perform optional cleanup, e.g. removing extra dashes | ||
| * @param {bool} [options.unicodeSlugs] - don't perform optional transliteration, e.g. keep smörgåsbord as it is instead of turning it into smorgasbord | ||
| * @param {string} [options.slugSeparator] - separator to be used for the slugs, can be ` `, `_` or `-`, defaults to `-` | ||
| * @returns {string} - a slugified string | ||
| */ | ||
| module.exports.safe = function safe(string, options = {}) { | ||
| return slugify(string, { requiredChangesOnly: options.importing === true }); | ||
| return slugify(string, { | ||
| requiredChangesOnly: options.importing === true, | ||
| unicodeSlugs: options.unicodeSlugs === true, | ||
| slugSeparator: options.slugSeparator | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TryGhost/framework
Length of output: 957
🏁 Script executed:
Repository: TryGhost/framework
Length of output: 4673
🌐 Web query:
@tryghost/string 0.3.5 npm source slugify unicodeSlugs slugSeparator💡 Result:
The package
@tryghost/stringversion 0.3.5 is a utility library maintained by the Ghost Foundation, primarily used within the Ghost publishing platform [1][2][3]. Regarding your specific search terms: 1. slugify: The package provides slugification functionality used to convert strings into URL-friendly slugs [4][5]. In modern versions of Ghost, the slugification logic is designed to handle character encoding specifically to ensure compatibility across browsers [4][6]. 2. unicodeSlugs: There is no native option or parameter named unicodeSlugs in the@tryghost/stringlibrary. Ghost's default slugification process often strips non-ASCII characters or uses encoding methods to produce predictable, ASCII-compatible slugs [4][7][6]. Users seeking to support non-Latin (Unicode) characters in slugs often find it necessary to manually modify the underlying slugify logic in their Ghost installation, as there is no built-in configuration option for this [5][7][6]. 3. slugSeparator: Similar to unicodeSlugs, there is no explicit parameter named slugSeparator exposed in the public interface of this package to configure the separator character (which defaults to a hyphen) [4]. Because@tryghost/stringis a private or internal-facing utility for the Ghost project, it lacks public, comprehensive API documentation [8][9]. The implementation of slugification is typically found in the core codebase of Ghost, where it is used to process titles and other strings into slugs [4][5][7]. If you require specific customization, you would need to inspect the source code within the Ghost repository or the specific version of the package installed in your node_modules directory [4][7].Citations:
🌐 Web query:
npmx.dev@tryghost/stringv0.3.5 slugify.js unicodeSlugs slugSeparator💡 Result:
The
@tryghost/stringpackage, including version 0.3.5 [1][2], is a utility library maintained by the Ghost Foundation, commonly used within the Ghost ecosystem to handle string operations such as URL slug generation [3][4][5]. Regarding the specific terms mentioned: slugify.js: This is a core component within the@tryghost/stringpackage (and historically within other internal Ghost packages like@tryghost/kg-utils) that provides the logic for converting strings into URL-safe slugs [6][3][7]. The implementation typically involves replacing reserved URL characters, handling whitespace, and normalizing the string to lowercase [6]. unicodeSlugs and slugSeparator: These terms are not explicit configuration options or variables found within the standard slugify.js implementation of@tryghost/string. The library’s slugification logic is generally prescriptive rather than highly configurable via these specific names [6]. While different versions of Ghost have evolved their slugification strategies—moving from aggressive character replacement (using dashes as separators) to URL encoding in newer versions—they do not expose a public API using the specific identifiers "unicodeSlugs" or "slugSeparator" [8][9]. If you are looking for advanced configuration for slug generation (such as custom separators or specific Unicode handling), libraries like@sindresorhus/slugifyare often used in the broader JavaScript ecosystem as they provide explicit options for features like separators and Unicode transliteration [10].Citations:
🌐 Web query:
"app.unpkg.com" "@tryghost/string@0.3.5" "unicodeSlugs" "slugSeparator"💡 Result:
The package
@tryghost/stringversion 0.3.5 is a utility library maintained by the Ghost project, primarily used for string processing tasks such as generating URL slugs [1]. Technical analysis of the library and its usage within the Ghost ecosystem indicates the following regarding the terms mentioned: 1. unicodeSlugs: There is no native configuration option named unicodeSlugs in the@tryghost/stringlibrary [1][2]. Ghost's default slugification behavior historically strips non-ASCII characters or encodes them [3][2]. For example, in newer versions (4.x+), the slugify function uses encodeURIComponent to handle non-Latin characters, which results in percent-encoded strings rather than retaining the original Unicode characters in the URL slug [3][2]. Users requiring full Unicode support in slugs often have to implement custom modifications to the library's slugify logic or validator expressions to override these constraints [4]. 2. slugSeparator: Similarly, the library does not expose a public configuration option named slugSeparator to change the default character used to separate words in slugs [1]. The internal implementation of the slugify function defaults to using a hyphen (-) as the separator [3][2]. If you are encountering these terms, they are likely references to custom implementations, intended features in a different context, or modifications made by users attempting to bypass the library's default ASCII-focused or hyphen-delimited behavior [4]. For standard usage, the library follows the patterns defined in the Ghost codebase, which utilize a hardcoded hyphen separator and sanitize inputs to maintain URL compatibility [3][2].Citations:
🌐 Web query:
@tryghost/string package 0.3.5 npm source "slugSeparator" "unicodeSlugs"💡 Result:
The
@tryghost/stringpackage, specifically version 0.3.5, is an internal utility package maintained by the Ghost organization for string manipulation, including slug generation [1][2]. Regarding your specific queries: 1. slugSeparator: The@tryghost/stringpackage uses a hardcoded hyphen (-) as the slug separator in modern versions (Ghost 4.x and later) [3][4]. The logic within the package is designed to replace whitespace with hyphens and strip or URL-encode other characters [3][4]. There is no configurable slugSeparator option exposed in the public API of this package [3]. 2. unicodeSlugs: The package historically prioritizes ASCII-friendly URLs [5][6]. While Ghost's slugification logic has evolved, it typically performs operations like removing non-word characters or using encodeURIComponent to handle non-ASCII input [3][4]. It does not natively support "unicode slugs" in the sense of keeping raw UTF-8 characters in the URL path; instead, it tends to strip non-ASCII characters or encode them [3][4]. Users seeking to support non-Latin languages in URLs have historically had to patch the package or modify core Ghost files to bypass these restrictions [6]. Because this is an internal package used by the Ghost platform, documentation is minimal and tailored to the platform's internal requirements [2][7]. It is not intended for general public use as a standalone library [7].Citations:
Make the supported slugify options match the workspace dependency.
packages/security/lib/string.jspassesunicodeSlugsandslugSeparator, but the lockfile resolves@tryghost/stringto0.3.5, and that build exposesunidecodebacking rather than those custom options. Either upgrade/patch the workspace dependency to support these options or keep passing only the options that the resolved@tryghost/string@0,3.5implementation honors.🤖 Prompt for AI Agents