Skip to content

Commit

Permalink
Always use "/" separator when accessing the vault
Browse files Browse the repository at this point in the history
  • Loading branch information
farling42 committed Apr 14, 2024
1 parent 0db9207 commit d5ab04b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
19 changes: 10 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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`);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit d5ab04b

Please sign in to comment.