fix: normalize save and load paths

This commit is contained in:
chrislicodes 2023-05-19 11:27:55 +02:00
parent e7810f1da3
commit f6318f4c09
2 changed files with 7 additions and 5 deletions

View file

@ -36,7 +36,7 @@ This action will trigger a modal window, where you have the option to paste your
![chess-study-modal](imgs/chess-study-modal.png)
Once you click `Submit`, Obsidian will parse the PGN, generate a new JSON file in your vault located at `.obsidian/plugins/obsidian-chess-study/storage/{id}.json`, and insert a chessStudy codeblock at the cursor's position. Here's an example of the chessStudy codeblock:
Once you click `Submit`, Obsidian Chess Study will parse the PGN, generate a new JSON file in your vault located at `.obsidian/plugins/obsidian-chess-study/storage/{id}.json`, and insert a chessStudy codeblock at the cursor's position. Here's an example of the chessStudy codeblock:
![chess-study-codeblock](imgs/chess-study-codeblock.png)
@ -91,4 +91,4 @@ If you want to have a look at FENs instead, check out these alternative Obsidian
## License
[Obsidian Chess Study](https://github.com/chrislicodes/obsidian-chess-study) is licensed under the GPL-3.0 license. Refer to [LICENSE](https://github.com/chrislicodes/obsidian-chess-study/blob/trunk/LICENSE.TXT) for more informations.
[Obsidian Chess Study](https://github.com/chrislicodes/obsidian-chess-study) is licensed under the GPL-3.0 license. Refer to [LICENSE](https://github.com/chrislicodes/obsidian-chess-study/blob/trunk/LICENSE) for more informations.

View file

@ -4,7 +4,7 @@ import { Api } from 'chessground/api';
import { Config } from 'chessground/config';
import { DrawShape } from 'chessground/draw';
import { nanoid } from 'nanoid';
import { DataAdapter, parseYaml } from 'obsidian';
import { DataAdapter, normalizePath, parseYaml } from 'obsidian';
import { ChessStudyPluginSettings } from 'src/components/obsidian/SettingsTab';
//Chess Logic
@ -99,7 +99,7 @@ export class ChessStudyDataAdapter {
async saveFile(data: ChessStudyFileData, id?: string) {
const chessStudyId = id || nanoid();
await this.adapter.write(
`${this.storagePath}/${chessStudyId}.json`,
normalizePath(`${this.storagePath}/${chessStudyId}.json`),
JSON.stringify(data, null, 2),
{}
);
@ -108,7 +108,9 @@ export class ChessStudyDataAdapter {
}
async loadFile(id: string): Promise<ChessStudyFileData> {
const data = await this.adapter.read(`${this.storagePath}/${id}.json`);
const data = await this.adapter.read(
normalizePath(`${this.storagePath}/${id}.json`)
);
return JSON.parse(data);
}