From 98f8b3045b287a4170617e851bc122a422a5d026 Mon Sep 17 00:00:00 2001 From: Mara Date: Fri, 17 Jun 2022 20:18:51 +0200 Subject: [PATCH] fix: error with checkcallback use callback with async --- mkdocsPublisher/utils/commands.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/mkdocsPublisher/utils/commands.ts b/mkdocsPublisher/utils/commands.ts index 110f715d..289add23 100644 --- a/mkdocsPublisher/utils/commands.ts +++ b/mkdocsPublisher/utils/commands.ts @@ -6,7 +6,7 @@ import { deleteFromGithub } from '../githubInteraction/delete' import { GetFiles } from "../githubInteraction/getFiles"; import {GithubBranch} from "../githubInteraction/branch"; import { Octokit } from "@octokit/core"; -import {Notice, TFile} from "obsidian"; +import {Notice, TFile, Vault} from "obsidian"; export async function shareAllMarkedNotes(publish: MkdocsPublish, settings: MkdocsPublicationSettings, octokit: Octokit, shareFiles: GetFiles, githubBranch: GithubBranch, statusBarItems: HTMLElement, branchName: string, sharedFiles: TFile[], createGithubBranch=true) { @@ -19,14 +19,7 @@ export async function shareAllMarkedNotes(publish: MkdocsPublish, settings: Mkdo if (sharedFiles.length > 0) { const publishedFiles = sharedFiles.map( (file) => file.name); - const publishedFilesText = JSON.stringify(publishedFiles).toString(); if (createGithubBranch) {await githubBranch.newBranch(branchName);} - const vaultPublisherJSON = settings.folderDefaultName.length > 0 ? `${settings.folderDefaultName}/vault_published.json` : `vault_published.json`; - await publish.uploadText( - "vault_published.json", - publishedFilesText, - vaultPublisherJSON, "", branchName - ); for ( let files = 0; files < sharedFiles.length; @@ -90,10 +83,22 @@ export async function shareOneNote(branchName: string, githubBranch: GithubBranc } catch (error) { console.error(error); - new Notice("Error publishing to " + this.settings.githubRepo + "."); + new Notice("Error publishing to " + settings.githubRepo + "."); } } +export async function shareNewNote(githubBranch: GithubBranch, publish:MkdocsPublish ,settings: MkdocsPublicationSettings, octokit: Octokit, shareFiles: GetFiles, branchName: string, vault: Vault) { + const branchMaster = await githubBranch.getMasterBranch(); + const sharedFilesWithPaths = shareFiles.getAllFileWithPath(); + const githubSharedNotes = await shareFiles.getAllFileFromRepo(branchMaster, octokit, settings); + const newlySharedNotes = shareFiles.getNewFiles(sharedFilesWithPaths, githubSharedNotes, vault); + if (newlySharedNotes.length > 0) { + const statusBarElement = this.addStatusBarItem(); + await githubBranch.newBranch(branchName); + await shareAllMarkedNotes(publish, this.settings, octokit, shareFiles, githubBranch, statusBarElement, branchName, newlySharedNotes); + } else { + new Notice("No new notes to share."); + } }