Skip to content

Commit

Permalink
feat: code review change requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwoz123 committed Nov 1, 2023
1 parent fa63e90 commit fb5bce7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Editor, MarkdownView, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { App, Editor, MarkdownView, Plugin, PluginSettingTab, Setting, TFile } from 'obsidian';


interface PluginSettings {
Expand Down Expand Up @@ -42,15 +42,20 @@ export default class ArchiveToSingleFilePlugin extends Plugin {
}
}

function archiveFile( editor: Editor, app: App , settings: PluginSettings) {
async function archiveFile( editor: Editor, app: App , settings: PluginSettings) {
const activeFile = app.workspace.getActiveFile();
if (!activeFile) {
return;
}
const {basename} = activeFile;

const toBeArchivedContents = `# ${basename} \n${editor.getValue()}`;
app.vault.adapter.append(settings.archiveFile, toBeArchivedContents);
if (! await app.vault.adapter.exists(settings.archiveFile)) {
app.vault.create(settings.archiveFile, toBeArchivedContents);
}else {
const archiveTFile = app.vault.getAbstractFileByPath(settings.archiveFile);
app.vault.append(<TFile>archiveTFile, toBeArchivedContents)
}
app.vault.delete(activeFile);
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fb5bce7

Please sign in to comment.