From cc3ebe2f7955ad806e4ecba853628b2ca0e34057 Mon Sep 17 00:00:00 2001 From: phacks Date: Tue, 8 Jan 2019 13:14:40 +0100 Subject: [PATCH] Fix unsuitable WP titles as paths --- package-lock.json | 14 ++++++++++++++ package.json | 1 + writing.js | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index ff7772f..0e0f6d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,15 @@ } } }, + "@sindresorhus/slugify": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/slugify/-/slugify-0.7.0.tgz", + "integrity": "sha512-3XQu4oFaTHy4wguh+Vz22GwPCm3t8qCq2/rN2+iah+H2gmf2297NQC8RkO+vvU9EW0REoaSZXwTPAJAzmVflxA==", + "requires": { + "escape-string-regexp": "^1.0.5", + "lodash.deburr": "^4.1.0" + } + }, "@types/node": { "version": "10.12.18", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.18.tgz", @@ -3398,6 +3407,11 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" }, + "lodash.deburr": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/lodash.deburr/-/lodash.deburr-4.1.0.tgz", + "integrity": "sha1-3bG7s+8HRYwBd7oH3hRCLLAz/5s=" + }, "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", diff --git a/package.json b/package.json index a6f4193..eebc834 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "author": "Costa Alexoglou ", "license": "MIT", "dependencies": { + "@sindresorhus/slugify": "^0.7.0", "chalk": "2.4.1", "cheerio": "1.0.0-rc.2", "fs-extra": "7.0.1", diff --git a/writing.js b/writing.js index f3d1044..6304c81 100644 --- a/writing.js +++ b/writing.js @@ -1,5 +1,6 @@ const fs = require("fs-extra"); const fetch = require("node-fetch"); +const slugify = require('@sindresorhus/slugify'); var path = require("path"); // Custom Styling for Command Line printing @@ -17,7 +18,7 @@ const error = chalk.bold.red; const writing = (post, title, images, destination) => { // Converting the title to the proper folder name - const dirTitle = title.toLowerCase().replace(/\ /g, "-"); + const dirTitle = slugify(title); destination = path.isAbsolute(destination) ? destination