From 51b89cc84b08c4c104addb52a343eec290565ebf Mon Sep 17 00:00:00 2001 From: Caleb Date: Fri, 29 Sep 2017 14:56:15 -0600 Subject: [PATCH] Switch from `slug` to `sanitize-filename`. --- package.json | 2 +- src/backends/backend.js | 6 +++--- yarn.lock | 26 ++++++++++++++++---------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 00bf5588..3cd76a57 100644 --- a/package.json +++ b/package.json @@ -149,12 +149,12 @@ "remark-parse": "^3.0.1", "remark-rehype": "^2.0.0", "remark-stringify": "^3.0.1", + "sanitize-filename": "^1.6.1", "semaphore": "^1.0.5", "slate": "^0.21.0", "slate-edit-list": "^0.7.1", "slate-edit-table": "^0.10.1", "slate-soft-break": "^0.3.0", - "slug": "^0.9.1", "toml-j0.4": "^1.1.1", "unified": "^6.1.4", "unist-builder": "^1.0.2", diff --git a/src/backends/backend.js b/src/backends/backend.js index 782422bc..6f38f184 100644 --- a/src/backends/backend.js +++ b/src/backends/backend.js @@ -5,7 +5,7 @@ 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 slug from 'slug'; +import sanitize from 'sanitize-filename'; class LocalStorageAuthStore { storageKey = "netlify-cms-user"; @@ -51,9 +51,9 @@ const slugFormatter = (template = "{{slug}}", entryData) => { case "day": return (`0${ date.getDate() }`).slice(-2); case "slug": - return slug(getIdentifier(entryData).trim(), {lower: true}); + return sanitize(getIdentifier(entryData).trim().toLowerCase(), {replacement: "-"}); default: - return slug(entryData.get(field, "").trim(), {lower: true}); + return sanitize(entryData.get(field, "").trim().toLowerCase(), {replacement: "-"}); } }); }; diff --git a/yarn.lock b/yarn.lock index e7722533..657f2ebd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7622,6 +7622,12 @@ sane@~1.6.0: walker "~1.0.5" watch "~0.10.0" +sanitize-filename@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/sanitize-filename/-/sanitize-filename-1.6.1.tgz#612da1c96473fa02dccda92dcd5b4ab164a6772a" + dependencies: + truncate-utf8-bytes "^1.0.0" + sax@^1.2.1, sax@~1.2.1: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" @@ -7815,12 +7821,6 @@ slice-ansi@0.0.4: version "0.0.4" resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35" -slug@^0.9.1: - version "0.9.1" - resolved "https://registry.yarnpkg.com/slug/-/slug-0.9.1.tgz#af08f608a7c11516b61778aa800dce84c518cfda" - dependencies: - unicode ">= 0.3.1" - sntp@1.x.x: version "1.0.9" resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198" @@ -8547,6 +8547,12 @@ trough@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.1.tgz#a9fd8b0394b0ae8fff82e0633a0a36ccad5b5f86" +truncate-utf8-bytes@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz#405923909592d56f78a5818434b0b78489ca5f2b" + dependencies: + utf8-byte-length "^1.0.1" + tryit@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb" @@ -8635,10 +8641,6 @@ unherit@^1.0.4: inherits "^2.0.1" xtend "^4.0.1" -"unicode@>= 0.3.1": - version "9.0.1" - resolved "https://registry.yarnpkg.com/unicode/-/unicode-9.0.1.tgz#104706272c6464c574801be1b086f7245cf25158" - unified@^6.1.4: version "6.1.5" resolved "https://registry.yarnpkg.com/unified/-/unified-6.1.5.tgz#716937872621a63135e62ced2f3ac6a063c6fb87" @@ -8793,6 +8795,10 @@ user-home@^2.0.0: dependencies: os-homedir "^1.0.0" +utf8-byte-length@^1.0.1: + version "1.0.4" + resolved "https://registry.yarnpkg.com/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz#f45f150c4c66eee968186505ab93fcbb8ad6bf61" + util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"