From 0cbaaf1326b7dd8a6849292e49ea390a19bf861b Mon Sep 17 00:00:00 2001 From: Kevin Van Lierde Date: Fri, 19 Jan 2024 01:57:58 +0100 Subject: [PATCH] WIP --- lib/index.d.ts | 6 ++++ package-lock.json | 36 +++++++++---------- src/index.js | 4 +-- .../expected/two/levels/deep/index.html | 1 + .../no-pattern/src/two/levels/deep.html | 1 + .../title}/index.html | 0 .../slash}/index.html | 0 7 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 test/fixtures/no-pattern/expected/two/levels/deep/index.html create mode 100644 test/fixtures/no-pattern/src/two/levels/deep.html rename test/fixtures/permalink-invalid-chars/expected/{html-head-essential-tags-meta-title => html-head-essential-tags-meta/title}/index.html (100%) rename test/fixtures/permalink-invalid-chars/expected/{special-chars-in-html-f-ward-slash => special-chars-in-html-f-ward/slash}/index.html (100%) diff --git a/lib/index.d.ts b/lib/index.d.ts index 5a01869..18d9076 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -58,6 +58,12 @@ export type Linkset = { pattern?: string; /** * [Slugify options](https://github.com/simov/slugify) or a custom slug function of the form `(pathpart) => string` + * @default + * { + * lower: true, + * remove: /[^\\w\\s$_+~.()!\\-@/]|[<>:"|?*]/g, + * extend: {':': '-', '|': '-', '<': '', '>': ''} + * } */ slug?: SlugifyOptions | slugFunction; /** diff --git a/package-lock.json b/package-lock.json index 4c12eb9..57956e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2488,9 +2488,9 @@ "dev": true }, "node_modules/@types/istanbul-lib-coverage": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", + "integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==", "dev": true }, "node_modules/@types/json5": { @@ -8272,9 +8272,9 @@ } }, "node_modules/istanbul-lib-coverage": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.0.tgz", - "integrity": "sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", + "integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==", "dev": true, "engines": { "node": ">=8" @@ -13586,9 +13586,9 @@ "dev": true }, "node_modules/v8-to-istanbul": { - "version": "9.1.3", - "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.1.3.tgz", - "integrity": "sha512-9lDD+EVI2fjFsMWXc6dy5JJzBsVTcQ2fVkfBvncZ6xJWG9wtBhOldG+mHkSL0+V1K/xgZz0JDO5UT5hFwHUghg==", + "version": "9.2.0", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.2.0.tgz", + "integrity": "sha512-/EH/sDgxU2eGxajKdwLCDmQ4FWq+kpi3uCmBGpw1xJtnAxEjlD8j8PEiGWpCIMIs3ciNAgH0d3TTJiUkYzyZjA==", "dev": true, "dependencies": { "@jridgewell/trace-mapping": "^0.3.12", @@ -15788,9 +15788,9 @@ "dev": true }, "@types/istanbul-lib-coverage": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", + "integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==", "dev": true }, "@types/json5": { @@ -20010,9 +20010,9 @@ } }, "istanbul-lib-coverage": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.0.tgz", - "integrity": "sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", + "integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==", "dev": true }, "istanbul-lib-report": { @@ -23793,9 +23793,9 @@ "dev": true }, "v8-to-istanbul": { - "version": "9.1.3", - "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.1.3.tgz", - "integrity": "sha512-9lDD+EVI2fjFsMWXc6dy5JJzBsVTcQ2fVkfBvncZ6xJWG9wtBhOldG+mHkSL0+V1K/xgZz0JDO5UT5hFwHUghg==", + "version": "9.2.0", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.2.0.tgz", + "integrity": "sha512-/EH/sDgxU2eGxajKdwLCDmQ4FWq+kpi3uCmBGpw1xJtnAxEjlD8j8PEiGWpCIMIs3ciNAgH0d3TTJiUkYzyZjA==", "dev": true, "requires": { "@jridgewell/trace-mapping": "^0.3.12", diff --git a/src/index.js b/src/index.js index c255cfc..100c1a1 100644 --- a/src/index.js +++ b/src/index.js @@ -76,7 +76,7 @@ const dupeHandlers = { // These are the invalid path chars on Windows, on *nix systems all are valid except forward slash. // However, it is highly unlikely that anyone would want these to appear in a file path and they can still be overridden if necessary const invalidPathChars = '[<>:"|?*]' -const defaultSlugifyRemoveChars = '[^\\w\\s$_+~.()!\\-@\\/]+' +const defaultSlugifyRemoveChars = `[^\\w\\s$_+~.()!\\-@/]+` const emptyStr = '' const dash = '-' @@ -94,7 +94,6 @@ const defaultLinkset = { // by default slugify strips these, resulting in word concatenation. Map these chars to dash to force a word break ':': dash, '|': dash, - '/': dash, // by default slugify translates these to "smaller" & "greater", unwanted when a tag is in the permalink '<': emptyStr, '>': emptyStr @@ -203,7 +202,6 @@ const replace = ({ pattern, ...options }, data) => { ret[key] = options.slug(val.toString()) } } - let transformed = route.inject(remapped, ret) if (path.basename(transformed) === path.basename(options.directoryIndex, path.extname(options.directoryIndex))) transformed = path.dirname(transformed) diff --git a/test/fixtures/no-pattern/expected/two/levels/deep/index.html b/test/fixtures/no-pattern/expected/two/levels/deep/index.html new file mode 100644 index 0000000..bfe53d7 --- /dev/null +++ b/test/fixtures/no-pattern/expected/two/levels/deep/index.html @@ -0,0 +1 @@ +nested \ No newline at end of file diff --git a/test/fixtures/no-pattern/src/two/levels/deep.html b/test/fixtures/no-pattern/src/two/levels/deep.html new file mode 100644 index 0000000..bfe53d7 --- /dev/null +++ b/test/fixtures/no-pattern/src/two/levels/deep.html @@ -0,0 +1 @@ +nested \ No newline at end of file diff --git a/test/fixtures/permalink-invalid-chars/expected/html-head-essential-tags-meta-title/index.html b/test/fixtures/permalink-invalid-chars/expected/html-head-essential-tags-meta/title/index.html similarity index 100% rename from test/fixtures/permalink-invalid-chars/expected/html-head-essential-tags-meta-title/index.html rename to test/fixtures/permalink-invalid-chars/expected/html-head-essential-tags-meta/title/index.html diff --git a/test/fixtures/permalink-invalid-chars/expected/special-chars-in-html-f-ward-slash/index.html b/test/fixtures/permalink-invalid-chars/expected/special-chars-in-html-f-ward/slash/index.html similarity index 100% rename from test/fixtures/permalink-invalid-chars/expected/special-chars-in-html-f-ward-slash/index.html rename to test/fixtures/permalink-invalid-chars/expected/special-chars-in-html-f-ward/slash/index.html