Skip to content

Commit

Permalink
fix(relativePath): if two same folder name, the src generated is false
Browse files Browse the repository at this point in the history
fix #32
  • Loading branch information
Mara-Li committed Oct 9, 2022
1 parent d70701c commit 06bd9be
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions plugin/contents_conversion/filePathConvertor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ function createRelativePath(
const targetPath = targetFile.linked.extension === 'md' ? getReceiptFolder(targetFile.linked, settings, metadata, vault) : getImageLinkOptions(targetFile.linked, settings, getFrontmatterCondition(frontmatter, settings));
const sourceList = sourcePath.split('/');
const targetList = targetPath.split('/');
const diffSourcePath = sourceList.filter(x => !targetList.includes(x));
const diffTargetPath = targetList.filter(x => !sourceList.includes(x));

const excludeUtilDiff = (sourceList: string[], targetList: string[]): string[] => {
let i = 0;
while (sourceList[i] === targetList[i]) {
i++;
}
return sourceList.slice(i);
}

const diffSourcePath = excludeUtilDiff(sourceList, targetList);
const diffTargetPath = excludeUtilDiff(targetList, sourceList);
const diffTarget = function (folderPath: string[]) {
const relativePath = [];
for (const folder of folderPath) {
Expand All @@ -81,6 +90,7 @@ function createRelativePath(
if (relative.trim() === '.' || relative.trim() === '') { //in case of errors
relative = getReceiptFolder(targetFile.linked, settings, metadata, vault).split('/').at(-1);
}
console.log(sourceList, targetList, relativePath, diffSourcePath, diffTargetPath, relative);
return relative;
}

Expand Down

0 comments on commit 06bd9be

Please sign in to comment.