Skip to content

Commit

Permalink
fix: use the file contents when creating unique file name
Browse files Browse the repository at this point in the history
I am hoping this will resolve some bugs where re-importing the same page
is causing the wrong images to show up on the wrong toggles.
  • Loading branch information
aalemayhu committed Dec 14, 2024
1 parent ae80842 commit a5da864
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/lib/parser/exporters/embedFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,27 @@ export const embedFile = (input: EmbedFileInput): string | null => {
const suffix = SuffixFrom(filePath);
const file = getFile(exporter, files, filePath, workspace);

/**
* The found file can be a file path in the workspace or a file in the zip or url.
* The contents is used first to avoid name conflicts. URL can have conflicts but so far
* no bug reports.
*/
if (file) {
const newName = getUniqueFileName(filePath) + suffix;
const contents = file.contents as string;
const newName = getUniqueFileName(contents ?? filePath) + suffix;
if (contents) {
exporter.addMedia(newName, contents);
}
return newName;
} else {
console.debug(
JSON.stringify({
hint: 'Missing relative path',
filePath: filePath,
fileNames: files.map((f) => f.name),
})
);
}

console.debug(
JSON.stringify({
hint: 'Missing relative path',
filePath: filePath,
fileNames: files.map((f) => f.name),
})
);

return null;
};

0 comments on commit a5da864

Please sign in to comment.