Skip to content

Commit

Permalink
fix(filepath): GitHub Api error with file path "//" (or more)
Browse files Browse the repository at this point in the history
Closes #206
  • Loading branch information
Mara-Li committed Aug 24, 2023
1 parent 64b2c01 commit b2121ad
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/conversion/file_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function createObsidianPath(
const fileNameOnly = path.split("/").at(-1) ?? "";
pathWithoutEnd = regexOnPath(pathWithoutEnd, settings);
if (pathWithoutEnd.trim().length === 0) return fileNameOnly;
return (pathWithoutEnd + "/" + fileNameOnly).replace(/^\//, "");
return (`${pathWithoutEnd}/${fileNameOnly}`).replace(/^\//, "");
}

/**
Expand Down Expand Up @@ -263,14 +263,11 @@ function createFrontmatterPath(
const uploadSettings = settings.upload;
const folderCategory = getCategory(frontmatter, settings);
const folderNote = folderNoteIndexYAML(fileName, frontmatter, settings);
let folderRoot = "";
if (uploadSettings.rootFolder.length > 0 && !folderCategory.includes(uploadSettings.rootFolder)) {
folderRoot = uploadSettings.rootFolder + "/";
}
const folderRoot = uploadSettings.rootFolder.length > 0 && !folderCategory.includes(uploadSettings.rootFolder) ? `${uploadSettings.rootFolder}/` : "";
if (folderCategory.trim().length === 0) return folderNote;
const folderRegex = regexOnPath(folderRoot + folderCategory, settings);
if (folderRegex.trim().length === 0) return folderNote;
return (folderRegex + "/" + folderNote).replace(/^\//, "");
return (`${folderRegex}/${folderNote}`).replace(/^\//, "");
}

/**
Expand Down Expand Up @@ -302,7 +299,7 @@ export function regexOnFileName(fileName: string, settings: GitHubPublisherSetti
}
}
}
return fileName + ".md";
return `${fileName}.md`;
}


Expand Down Expand Up @@ -389,18 +386,18 @@ export function getReceiptFolder(
}

if (frontmatter.path) {
const frontmatterPath = frontmatter["path"] instanceof Array ? frontmatter["path"].join("/") : frontmatter["path"];
const frontmatterPath = frontmatter.path instanceof Array ? frontmatter.path.join("/") : frontmatter.path;
if (frontmatterPath == "" || frontmatterPath == "/") {
return editedFileName;
}
return frontmatterPath + "/" + editedFileName;
return `${frontmatterPath}/${editedFileName}`;
} else if (settings.upload.behavior === FolderSettings.yaml) {
return createFrontmatterPath(settings, frontmatter, fileName);
return createFrontmatterPath(settings, frontmatter, fileName).replace(/\/{2,}/, "/");
} else if (settings.upload.behavior === FolderSettings.obsidian) {
return createObsidianPath(file, settings, vault, fileName);
return createObsidianPath(file, settings, vault, fileName).replace(/\/{2,}/, "/");
} else {
return settings.upload.defaultName.length > 0
? settings.upload.defaultName + "/" + editedFileName
? `${settings.upload.defaultName}/${editedFileName}`
: editedFileName;
}
}
Expand Down

0 comments on commit b2121ad

Please sign in to comment.