Fix slug punctuation

This commit is contained in:
Elio Struyf
2021-10-20 15:21:27 +02:00
parent 8902e25021
commit f500749644
3 changed files with 22 additions and 9 deletions
+6
View File
@@ -1,5 +1,11 @@
# Change Log
## [5.x.x] - 2021-xx-xx
### 🐞 Fixes
- Value check when generating slug from title
## [5.2.0] - 2021-10-19
### 🎨 Enhancements
-1
View File
@@ -251,7 +251,6 @@ export class ArticleHelper {
const items = [{
title: "Check file",
action: async () => {
console.log(fileName);
await EditorHelper.showFile(fileName)
}
}];
+16 -8
View File
@@ -14,14 +14,18 @@ export class SlugHelper {
// Remove punctuation from input string, and split it into words.
let cleanTitle = this.removePunctuation(articleTitle);
cleanTitle = cleanTitle.toLowerCase();
// Split into words
let words = cleanTitle.split(/\s/);
// Removing stop words
words = this.removeStopWords(words);
cleanTitle = words.join("-");
cleanTitle = this.replaceCharacters(cleanTitle);
return cleanTitle;
if (cleanTitle) {
cleanTitle = cleanTitle.toLowerCase();
// Split into words
let words = cleanTitle.split(/\s/);
// Removing stop words
words = this.removeStopWords(words);
cleanTitle = words.join("-");
cleanTitle = this.replaceCharacters(cleanTitle);
return cleanTitle;
}
return null;
}
/**
@@ -30,6 +34,10 @@ export class SlugHelper {
* @param value
*/
private static removePunctuation(value: string): string {
if (typeof value !== "string") {
return "";
}
const punctuationless = value?.replace(/[\.,-\/#!$@%\^&\*;:{}=\-_`'"~()+\?<>]/g, " ");
// Remove double spaces
return punctuationless?.replace(/\s{2,}/g," ");