Skip to content

Commit 05b5dd3

Browse files
authored
Merge pull request #16 from aoout/14-update-an-anime-by-reimporting-it
feat: 14 update an anime by reimporting it
2 parents 627fe7a + 3b132cc commit 05b5dd3

4 files changed

Lines changed: 19 additions & 13 deletions

File tree

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
"isDesktopOnly": false,
99
"minAppVersion": "0.16.0",
10-
"version": "0.2.7"
10+
"version": "0.2.8"
1111
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "anime-parser",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"description": "Parse a local directory to a anime.",
55
"main": "main.js",
66
"scripts": {

src/main.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,23 @@ export default class AnimeParserPlugin extends Plugin {
163163
};
164164

165165
const notePath = this.settings.savePath
166-
? path.join("/", this.settings.savePath, name + ".md")
166+
? path.posix.join(this.settings.savePath, name + ".md")
167167
: name + ".md";
168168

169-
await createNote(
170-
this.app,
171-
notePath,
172-
tFrontmatter(parseYaml(templateBuild(this.settings.yamlTemplate, variables))) +
173-
"\n" +
174-
content
175-
);
176-
new Notice(`${name}has been imported`);
169+
const existingFile = this.app.vault.getFileByPath(notePath);
170+
if (!existingFile) {
171+
await createNote(
172+
this.app,
173+
notePath,
174+
tFrontmatter(parseYaml(templateBuild(this.settings.yamlTemplate, variables))) +
175+
"\n" +
176+
content
177+
);
178+
} else {
179+
const frontmatter = this.app.metadataCache.getFileCache(existingFile).frontmatter;
180+
await this.app.vault.modify(existingFile, tFrontmatter(frontmatter) + "\n" + content);
181+
}
182+
new Notice(`${name} has been ${existingFile ? "updated" : "imported"}`);
177183
}
178184

179185
async playAnime(currentFile: TFile) {

0 commit comments

Comments
 (0)