Fixed issue where file name cannot be parsed

This commit is contained in:
Tuan Cao 2022-04-25 12:57:36 +07:00
parent 9cdde4be3e
commit 47d0eb25ba
2 changed files with 9 additions and 4 deletions

View File

@ -125,8 +125,13 @@ export const Transformer = {
}, },
/* Parse file name from path then sanitize it */ /* Parse file name from path then sanitize it */
parseFileNameFromPath: function (filepath) { parseFileNameFromPath: function (filepath) {
const parsedFileFromPath = filepath.split("/")[filepath.split("/").length - 1] if (typeof filepath ==='string' && filepath.includes("/")) {
return parsedFileFromPath.replace(".md", "") const parsedFileFromPath = filepath.split("/")[filepath.split("/").length - 1]
return parsedFileFromPath.replace(".md", "")
} else {
console.log("Failed: CANNOT Parse" + filepath)
return null
}
}, },
/* Pair provided and existing Filenames*/ /* Pair provided and existing Filenames*/
getInternalLinks: function (aFilePath) { getInternalLinks: function (aFilePath) {

View File

@ -61,7 +61,7 @@ export function toFilePath(slug) {
} else { } else {
filePath = Node.getMarkdownFolder() + slug filePath = Node.getMarkdownFolder() + slug
.replaceAll('__', '/') .replaceAll('__', '/')
.replaceAll('--', ' ') .replaceAll('++++', ' ')
.replaceAll('ambersand', '&') .replaceAll('ambersand', '&')
+ ".md"; + ".md";
} }
@ -79,7 +79,7 @@ export function toSlug(filePath) {
if (Node.isFile(filePath) && filePath.includes(Node.getMarkdownFolder())) { if (Node.isFile(filePath) && filePath.includes(Node.getMarkdownFolder())) {
return filePath.replace(Node.getMarkdownFolder(), '') return filePath.replace(Node.getMarkdownFolder(), '')
.replaceAll('/', '__') .replaceAll('/', '__')
.replaceAll(' ', '--') .replaceAll(' ', '++++')
.replaceAll('&', 'ambersand') .replaceAll('&', 'ambersand')
.replace('.md', '') .replace('.md', '')
} else { } else {