Closed Mara-Li closed 1 year ago
Btw, you could use directly TFile
in needToRename, with for example, sourceFile
so you can get ride of path.posix
to use native TFile/TFabstract (.ext…)
Ex :
const oldNote = this.app.vault.getAbstractFileByPath(oldPath) as TFile;
// generate old note path and name
const oldNotePath = oldNote?.path as string;
const oldNoteExtension = oldNote?.extension as string;
const oldNoteName = oldNote?.basename as string;
Also, if file doesn't exists, I have some little function to get for example, the basename :
const basename = (name: string) => /([^/\\.]*)(\..*)?$/.exec(name)[1] || "";
In same example, for extension :
const getFileExtension = (filename: string): string => /\.([0-9a-z]+)$/i.exec(filename)?.[1] || "";
I have replaced the nodejs path library with a build in path lib. And now it should be work right on mobile devices.
Also, the plugin can be useful on mobile version. Unfortunately, the
path
is from node. Node is unsupported on mobile. https://marcus.se.net/obsidian-plugin-docs/reference/typescript/functions/normalizePath#parameters exists on Obsidian native, so you can use it.