Re-implement standard slugification with IRIs instead of URIs.
This commit is contained in:
@ -5,7 +5,8 @@ import GitGatewayBackend from "./git-gateway/implementation";
|
||||
import { resolveFormat } from "../formats/formats";
|
||||
import { selectListMethod, selectEntrySlug, selectEntryPath, selectAllowNewEntries, selectFolderEntryExtension } from "../reducers/collections";
|
||||
import { createEntry } from "../valueObjects/Entry";
|
||||
import sanitize from 'sanitize-filename';
|
||||
import { sanitizeIRI } from "../lib/urlHelper";
|
||||
import sanitizeFilename from 'sanitize-filename';
|
||||
|
||||
class LocalStorageAuthStore {
|
||||
storageKey = "netlify-cms-user";
|
||||
@ -57,7 +58,19 @@ const slugFormatter = (template = "{{slug}}", entryData) => {
|
||||
}
|
||||
});
|
||||
|
||||
return sanitize(slug, {replacement: "-"}).replace(/[.]/g, '-');
|
||||
// Convert slug to lower-case;
|
||||
slug = slug.toLocaleLowerCase();
|
||||
|
||||
// Replace periods and spaces with dashes.
|
||||
slug = slug.replace(/[.\s]/g, '-');
|
||||
// Sanitize as IRI (i18n URI) and as filename.
|
||||
slug = sanitizeIRI(slug, {replacement: "-"});
|
||||
slug = sanitizeFilename(slug, {replacement: "-"});
|
||||
|
||||
// Remove any doubled or trailing replacement characters (that were added in the sanitizers).
|
||||
slug = slug.replace(/-+/g, '-').replace(/-$/, '');
|
||||
|
||||
return slug;
|
||||
};
|
||||
|
||||
class Backend {
|
||||
|
Reference in New Issue
Block a user