Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: attachment path #58

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class MarkdownExportSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName("Custom attachment path(optional)")
.setDesc("attachment path")
.setDesc("attachment path, relative to the output path")
.addText((text) =>
text
.setPlaceholder("Enter attachment path")
Expand Down
16 changes: 16 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ export function getResourceOsPath(
return ".";
}

/**
*
* @param path a/b/c.md
* @returns click path: unix: ../../ or windows: ..\..\, but need: ../
*/
export function getClickSubRoute(p: string): string {
const parentLevels = p.split(path.sep).length - 1;
const parentRoute = ".." + path.sep;

return parentRoute.repeat(parentLevels - 1);
}

export function fileExists(path: string): boolean {
try {
return fs.statSync(path).isFile();
Expand Down Expand Up @@ -318,8 +330,12 @@ export async function tryCopyMarkdownByRead(
const imageLinkMd5 = md5(imageLink);
const imageExt = path.extname(imageLink);
// Unify the link separator in obsidian as a forward slash instead of the default back slash in windows, so that the referenced images can be displayed properly

const clickSubRoute = getClickSubRoute(file.path);

const hashLink = path
.join(
clickSubRoute,
plugin.settings.attachment,
imageLinkMd5.concat(imageExt)
)
Expand Down
Loading