diff --git a/CHANGELOG.md b/CHANGELOG.md index eea60f3..4da645d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # ChangeLog +## 0.36.2 + +- Ensure that when accessing folders in the vault we always uses "/" as the directory separator, rather than `path.sep` which is the underlying O/S's preferred slash. + ## 0.36.1 - Update all the Obsidian-specific version files so that users know that the improvements added in 0.36.0 are actually present in their Vault. diff --git a/main.ts b/main.ts index e8c40ec..039fdf7 100644 --- a/main.ts +++ b/main.ts @@ -4,7 +4,7 @@ const Papa = require('papaparse'); let handlebars = require('handlebars'); let hb_helpers = require('@budibase/handlebars-helpers')({handlebars: handlebars}); let hb_utils = require('handlebars-utils'); -let path = require('path'); +//let path = require('path'); // Remember to rename these classes and interfaces! @@ -42,6 +42,8 @@ const DEFAULT_SETTINGS: JsonImportSettings = { uniqueNames: false } +// Obsidian.md always uses forward slash as separator in vault paths. +const DIR_SEP = "/"; //path.sep; function convertCsv(source: string) { @@ -227,7 +229,7 @@ export default class JsonImport extends Plugin { * @param filename */ async checkPath(filename: string) { - let pos = filename.lastIndexOf(path.sep); + let pos = filename.lastIndexOf(DIR_SEP); if (pos < 0) return true; let filepath = filename.slice(0,pos); if (this.knownpaths.has(filepath)) return true; @@ -347,8 +349,7 @@ export default class JsonImport extends Plugin { new Notice(`Incomplete conversion for '${notefile}'. Look for '[object Object]' (also reported in console)`); } - // path.join, just without creating a full O/S absolute path - let filename:string = settings.folderName + path.sep + this.validFilename(notefile); + let filename:string = settings.folderName + DIR_SEP + this.validFilename(notefile); // Check for filename uniqueness ONLY during this import (not with other existing Notes in the vault) if (settings.uniqueNames) { let basename = filename; @@ -360,21 +361,21 @@ export default class JsonImport extends Plugin { this.nameMap.add(filename); } filename += ".md"; - filename = filename.replaceAll(/(\/|\\)+/g, path.sep); + filename = filename.replaceAll(/(\/|\\)+/g, DIR_SEP); await this.checkPath(filename); // Delete the old version, if it exists let file = this.app.vault.getAbstractFileByPath(filename); - if (!file) - await this.app.vault.create(filename, body).catch(err => console.log(`app.vault.create(${filename}): ${err}`)); + if (file === null) + await this.app.vault.create(filename, body).catch(err => console.log(`app.vault.create("${filename}"): ${err}`)); else switch (settings.handleExistingNote) { case ExistingNotes.REPLACE_EXISTING: - await this.app.vault.modify(file as TFile, body).catch(err => console.log(`app.vault.modify(${file.path}): ${err}`)); + await this.app.vault.modify(file as TFile, body).catch(err => console.log(`app.vault.modify("${file.path}"): ${err}`)); break; case ExistingNotes.APPEND_TO_EXISTING: - await this.app.vault.append(file as TFile, body).catch(err => console.log(`app.vault.append(${file.path}): ${err}`)); + await this.app.vault.append(file as TFile, body).catch(err => console.log(`app.vault.append("${file.path}"): ${err}`)); break; default: new Notice(`Note already exists for '${filename}' - ignoring entry in data file`); diff --git a/manifest.json b/manifest.json index 60a02a0..d557925 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-import-json", "name": "JSON/CSV Importer", - "version": "0.36.1", + "version": "0.36.2", "minAppVersion": "1.1.15", "description": "This plugin imports a JSON/CSV file (or text block) and creates notes from a Handlebars template file", "author": "farling42", diff --git a/package.json b/package.json index 618fb02..3034867 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-import-json", - "version": "0.36.1", + "version": "0.36.2", "description": "This plugin imports a JSON/CSV file (or text block) and creates notes from a Handlebars template file", "main": "main.js", "scripts": { diff --git a/versions.json b/versions.json index 11a2fd2..3b8385f 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { + "0.36.2": "1.1.15", "0.36.1": "1.1.15", "0.35.0": "1.1.15", "0.34.0": "1.1.15",