diff --git a/src/GitHub/branch.ts b/src/GitHub/branch.ts index c465cfe8..5b8b2453 100644 --- a/src/GitHub/branch.ts +++ b/src/GitHub/branch.ts @@ -2,10 +2,10 @@ import { Octokit } from "@octokit/core"; import i18next from "i18next"; import {Notice } from "obsidian"; -import GithubPublisher from "../main"; import { RepoFrontmatter, -} from "../settings/interface"; +} from "../interfaces/main"; +import GithubPublisher from "../main"; import { logs, notif } from "../utils"; import { FilesManagement } from "./files"; diff --git a/src/GitHub/delete.ts b/src/GitHub/delete.ts index 9ac4202f..c2508644 100644 --- a/src/GitHub/delete.ts +++ b/src/GitHub/delete.ts @@ -11,7 +11,7 @@ import { GithubRepo, MonoRepoProperties, RepoFrontmatter, -} from "../settings/interface"; +} from "../interfaces"; import { logs, notif, trimObject} from "../utils"; import {isAttachment, verifyRateLimitAPI} from "../utils/data_validation_test"; import { frontmatterSettingsRepository } from "../utils/parse_frontmatter"; diff --git a/src/GitHub/files.ts b/src/GitHub/files.ts index 8cec471f..99aa5be5 100644 --- a/src/GitHub/files.ts +++ b/src/GitHub/files.ts @@ -6,14 +6,14 @@ import { getImagePath, getReceiptFolder, } from "../conversion/file_path"; -import GithubPublisher from "../main"; import { ConvertedLink, FrontmatterConvert, GithubRepo, LinkedNotes, RepoFrontmatter, Repository, -} from "../settings/interface"; +} from "../interfaces/main"; +import GithubPublisher from "../main"; import {logs} from "../utils"; import { isAttachment, isShared } from "../utils/data_validation_test"; import { frontmatterFromFile, getRepoFrontmatter } from "../utils/parse_frontmatter"; @@ -62,7 +62,7 @@ export class FilesManagement extends Publisher { * @param {Repository | null} repo The repository * @return {TFile[]} The shared files */ - getSharedFileOfFolder(folder: TFolder, repo: Repository | null): TFile[] { + getSharedFileOfFolder(folder: TFolder, repo: Repository | null, addFolderNote?: boolean): TFile[] { const files: TFile[] = []; for (const file of folder.children) { if (file instanceof TFolder) { @@ -78,7 +78,17 @@ export class FilesManagement extends Publisher { } } } - return files; + /* get if external folder note exists */ + if (addFolderNote) { + const folderNote = this.vault.getAbstractFileByPath(`${folder.path}.md`); + if (folderNote && folderNote instanceof TFile) { + const frontMatter = this.metadataCache.getCache(folderNote.path)?.frontmatter; + if (isShared(frontMatter, this.settings, folderNote, repo) && !files.includes(folderNote)) { + files.push(folderNote); + } + } + } + return [...new Set(files)]; //prevent duplicate; } /** diff --git a/src/GitHub/upload.ts b/src/GitHub/upload.ts index 893884da..ea61e991 100644 --- a/src/GitHub/upload.ts +++ b/src/GitHub/upload.ts @@ -19,7 +19,6 @@ import { getImagePath, getReceiptFolder, } from "../conversion/file_path"; -import GithubPublisher from "../main"; import { Deleted, GitHubPublisherSettings, @@ -28,7 +27,8 @@ import { MultiProperties, MultiRepoProperties, RepoFrontmatter, UploadedFiles, -} from "../settings/interface"; +} from "../interfaces"; +import GithubPublisher from "../main"; import { logs, noticeMobile, diff --git a/src/commands/callback.ts b/src/commands/callback.ts index 7c2ee2b5..9fcaf46f 100644 --- a/src/commands/callback.ts +++ b/src/commands/callback.ts @@ -7,8 +7,8 @@ import i18next from "i18next"; import {Command, Notice } from "obsidian"; +import {MonoRepoProperties,MultiRepoProperties,Repository} from "../interfaces"; import GithubPublisher from "../main"; -import {MonoRepoProperties, MultiRepoProperties, Repository} from "../settings/interface"; import {createLink} from "../utils"; import {checkRepositoryValidity, isShared} from "../utils/data_validation_test"; import { frontmatterFromFile, frontmatterSettingsRepository, getRepoFrontmatter } from "../utils/parse_frontmatter"; diff --git a/src/commands/file_menu.ts b/src/commands/file_menu.ts index 2615697f..60e45997 100644 --- a/src/commands/file_menu.ts +++ b/src/commands/file_menu.ts @@ -1,8 +1,8 @@ import i18next from "i18next"; import { Menu, MenuItem, Platform, TFile, TFolder} from "obsidian"; +import {MonoRepoProperties, Repository} from "../interfaces"; import GithubPublisher from "../main"; -import {MonoRepoProperties, Repository} from "../settings/interface"; import {defaultRepo, getRepoSharedKey, isExcludedPath, isInDryRunFolder, isShared, multipleSharedKey} from "../utils/data_validation_test"; import { frontmatterFromFile, frontmatterSettingsRepository, getRepoFrontmatter } from "../utils/parse_frontmatter"; import {shareAllMarkedNotes, shareOneNote} from "."; @@ -29,7 +29,7 @@ export async function shareFolderRepo(plugin: GithubPublisher, folder: TFolder, statusBarItems, branchName, monoProperties, - publisher.getSharedFileOfFolder(folder, repo), + publisher.getSharedFileOfFolder(folder, repo, true), true, ); } diff --git a/src/commands/index.ts b/src/commands/index.ts index 34de5245..692eb821 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -5,7 +5,7 @@ import merge from "ts-deepmerge"; import { GithubBranch } from "../GitHub/branch"; import { deleteFromGithub } from "../GitHub/delete"; -import { MonoRepoProperties, MultiRepoProperties, Repository, UploadedFiles} from "../settings/interface"; +import { MonoRepoProperties, MultiRepoProperties, Repository, UploadedFiles} from "../interfaces"; import { ListChangedFiles } from "../settings/modals/list_changed"; import { createLink, diff --git a/src/commands/plugin_commands.ts b/src/commands/plugin_commands.ts index 2dc2f527..ef9af857 100644 --- a/src/commands/plugin_commands.ts +++ b/src/commands/plugin_commands.ts @@ -6,8 +6,8 @@ import i18next from "i18next"; import { Notice } from "obsidian"; +import {MonoRepoProperties, MultiRepoProperties, Repository} from "../interfaces"; import GithubPublisher from "../main"; -import {MonoRepoProperties, MultiRepoProperties, Repository} from "../settings/interface"; import {createLink} from "../utils"; import {checkRepositoryValidity, isShared} from "../utils/data_validation_test"; import { frontmatterFromFile, frontmatterSettingsRepository, getRepoFrontmatter } from "../utils/parse_frontmatter"; diff --git a/src/commands/suggest_other_repo_commands_modal.ts b/src/commands/suggest_other_repo_commands_modal.ts index ed456135..b6bd71fc 100644 --- a/src/commands/suggest_other_repo_commands_modal.ts +++ b/src/commands/suggest_other_repo_commands_modal.ts @@ -2,8 +2,8 @@ import i18next from "i18next"; import { App, FuzzySuggestModal } from "obsidian"; import { defaultRepo } from "src/utils/data_validation_test"; +import { FolderSettings, GitHubPublisherSettings, Repository } from "../interfaces"; import GithubPublisher from "../main"; -import { FolderSettings, GitHubPublisherSettings, Repository } from "../settings/interface"; import { createLinkOnActiveFile, deleteCommands, repositoryValidityActiveFile, shareActiveFile, diff --git a/src/conversion/compiler/dataview.ts b/src/conversion/compiler/dataview.ts index 4e7da9cc..03adb59a 100644 --- a/src/conversion/compiler/dataview.ts +++ b/src/conversion/compiler/dataview.ts @@ -7,9 +7,9 @@ import i18next from "i18next"; import { Component, FrontMatterCache, htmlToMarkdown,TFile } from "obsidian"; import { getAPI, isPluginEnabled,Literal, Success } from "obsidian-dataview"; import GithubPublisher from "src/main"; -import { FrontmatterConvert, LinkedNotes, MultiProperties } from "src/settings/interface"; import { logs, notif } from "src/utils"; +import { FrontmatterConvert, LinkedNotes, MultiProperties } from "../../interfaces"; import { convertToInternalGithub, convertWikilinks, escapeRegex } from "../links"; /** diff --git a/src/conversion/compiler/embeds.ts b/src/conversion/compiler/embeds.ts index ab8c964c..fac30263 100644 --- a/src/conversion/compiler/embeds.ts +++ b/src/conversion/compiler/embeds.ts @@ -20,7 +20,7 @@ import GithubPublisher from "src/main"; import { GitHubPublisherSettings, LinkedNotes, - MultiProperties} from "../../settings/interface"; + MultiProperties} from "../../interfaces"; import {isShared} from "../../utils/data_validation_test"; import { addToYaml } from ".."; import { createRelativePath, getTitleField, regexOnFileName } from "../file_path"; diff --git a/src/conversion/file_path.ts b/src/conversion/file_path.ts index c9504d85..940c3db6 100644 --- a/src/conversion/file_path.ts +++ b/src/conversion/file_path.ts @@ -17,7 +17,7 @@ import { MultiProperties, RepoFrontmatter, Repository, -} from "../settings/interface"; +} from "../interfaces"; import { logs, } from "../utils"; diff --git a/src/conversion/find_and_replace_text.ts b/src/conversion/find_and_replace_text.ts index 0c58558e..7a850d2d 100644 --- a/src/conversion/find_and_replace_text.ts +++ b/src/conversion/find_and_replace_text.ts @@ -1,7 +1,7 @@ import { logs } from "src/utils"; -import { FIND_REGEX, GitHubPublisherSettings } from "../settings/interface"; +import { FIND_REGEX, GitHubPublisherSettings } from "../interfaces"; import { escapeRegex } from "./links"; /** diff --git a/src/conversion/index.ts b/src/conversion/index.ts index 68d841d1..35fe8ea2 100644 --- a/src/conversion/index.ts +++ b/src/conversion/index.ts @@ -11,13 +11,13 @@ import { } from "obsidian"; import { isFolderNote } from "src/utils/data_validation_test"; -import GithubPublisher from "../main"; import { FrontmatterConvert, GitHubPublisherSettings, LinkedNotes, MultiProperties, -} from "../settings/interface"; +} from "../interfaces"; +import GithubPublisher from "../main"; import { notif } from "../utils"; import { convertDataviewQueries } from "./compiler/dataview"; import { bakeEmbeds, convertInlineDataview } from "./compiler/embeds"; diff --git a/src/conversion/links.ts b/src/conversion/links.ts index 53cfd259..b9ff8d22 100644 --- a/src/conversion/links.ts +++ b/src/conversion/links.ts @@ -6,7 +6,7 @@ import { GitHubPublisherSettings, LinkedNotes, MultiProperties, -} from "../settings/interface"; +} from "../interfaces"; import { isAttachment, noTextConversion } from "../utils/data_validation_test"; import { createRelativePath, linkIsInFormatter, textIsInFrontmatter } from "./file_path"; import { replaceText } from "./find_and_replace_text"; diff --git a/src/i18n/locales/af.json b/src/i18n/locales/af.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/af.json +++ b/src/i18n/locales/af.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/ar.json b/src/i18n/locales/ar.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/ar.json +++ b/src/i18n/locales/ar.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/ca.json b/src/i18n/locales/ca.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/ca.json +++ b/src/i18n/locales/ca.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/cs.json b/src/i18n/locales/cs.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/cs.json +++ b/src/i18n/locales/cs.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/da.json b/src/i18n/locales/da.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/da.json +++ b/src/i18n/locales/da.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/el.json b/src/i18n/locales/el.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/el.json +++ b/src/i18n/locales/el.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 175bbc71..370ac916 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -113,8 +113,8 @@ "scanningRepo": "Scanning the repository, may take a while...", "sendMessage": "Upload {{- nbNotes}} notes to {{- repo.owner}}/{{- repo.repo}}", "startingClean": "Starting cleaning {{- repo.owner}}/{{- repo.repo}}", - "successPublishOneNote": "Successfully uploaded {{- file}} to {{- repo.owner}}/{{- repo.repo}}", "successfulPublish": "Successfully uploaded {{- nbNotes}} to {{- repo.owner}}/{{- repo.repo}}", + "successPublishOneNote": "Successfully uploaded {{- file}} to {{- repo.owner}}/{{- repo.repo}}", "waitingWorkflow": "Now, waiting for the workflow to be completed..." }, "modals": { diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/fi.json b/src/i18n/locales/fi.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/fi.json +++ b/src/i18n/locales/fi.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index d66a98c9..ed86820a 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -113,8 +113,8 @@ "scanningRepo": "Scan du dépôt, veuillez patienter...", "sendMessage": "Transfert de {{- nbNotes}} notes vers {{- repo.owner}}/{{- repo.repo}}", "startingClean": "Début du nettoyage de {{- repo.owner}}/{{- repo.repo}}", - "successPublishOneNote": "Transfert réussi de {{- file}} vers {{- repo.owner}}/{{- repo.repo}}", "successfulPublish": "Transfert réussi de {{- nbNotes}} notes vers {{- repo.owner}}/{{- repo.repo}}", + "successPublishOneNote": "Transfert réussi de {{- file}} vers {{- repo.owner}}/{{- repo.repo}}", "waitingWorkflow": "Maintenant, attente de la fin du workflow..." }, "modals": { diff --git a/src/i18n/locales/he.json b/src/i18n/locales/he.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/he.json +++ b/src/i18n/locales/he.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/hu.json b/src/i18n/locales/hu.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/hu.json +++ b/src/i18n/locales/hu.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/it.json b/src/i18n/locales/it.json index 817b72e6..96d060dd 100644 --- a/src/i18n/locales/it.json +++ b/src/i18n/locales/it.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/ko.json b/src/i18n/locales/ko.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/ko.json +++ b/src/i18n/locales/ko.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/nl.json b/src/i18n/locales/nl.json index 817b72e6..96d060dd 100644 --- a/src/i18n/locales/nl.json +++ b/src/i18n/locales/nl.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/no.json b/src/i18n/locales/no.json index 817b72e6..96d060dd 100644 --- a/src/i18n/locales/no.json +++ b/src/i18n/locales/no.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/pl.json b/src/i18n/locales/pl.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/pl.json +++ b/src/i18n/locales/pl.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/pt-BR.json b/src/i18n/locales/pt-BR.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/pt-BR.json +++ b/src/i18n/locales/pt-BR.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/pt.json b/src/i18n/locales/pt.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/pt.json +++ b/src/i18n/locales/pt.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/ro.json b/src/i18n/locales/ro.json index 817b72e6..96d060dd 100644 --- a/src/i18n/locales/ro.json +++ b/src/i18n/locales/ro.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/sr.json b/src/i18n/locales/sr.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/sr.json +++ b/src/i18n/locales/sr.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/sv.json b/src/i18n/locales/sv.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/sv.json +++ b/src/i18n/locales/sv.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/tr.json b/src/i18n/locales/tr.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/tr.json +++ b/src/i18n/locales/tr.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/uk.json b/src/i18n/locales/uk.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/uk.json +++ b/src/i18n/locales/uk.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/vi.json b/src/i18n/locales/vi.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/vi.json +++ b/src/i18n/locales/vi.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/i18n/locales/zh-TW.json b/src/i18n/locales/zh-TW.json index cf6f48e7..186e7c2a 100644 --- a/src/i18n/locales/zh-TW.json +++ b/src/i18n/locales/zh-TW.json @@ -113,8 +113,8 @@ "scanningRepo": "", "sendMessage": "", "startingClean": "", - "successPublishOneNote": "", "successfulPublish": "", + "successPublishOneNote": "", "waitingWorkflow": "" }, "modals": { diff --git a/src/interfaces/constant.ts b/src/interfaces/constant.ts new file mode 100644 index 00000000..3c4395af --- /dev/null +++ b/src/interfaces/constant.ts @@ -0,0 +1,109 @@ +import { FolderSettings, GithubTiersVersion } from "./enum"; +import { GitHubPublisherSettings } from "./main"; + +/** Find a regex encapsuled in // */ +export const FIND_REGEX = /^\/(.*)\/[igmsuy]*$/; + + +/** + * Just a constant for the token path + * @type {string} TOKEN_PATH + */ +export const TOKEN_PATH: string = "%configDir%/plugins/%pluginID%/env"; + +export const DEFAULT_SETTINGS: Partial = { + github: { + user: "", + repo: "", + branch: "main", + automaticallyMergePR: true, + dryRun: { + enable: false, + folderName: "github-publisher", + }, + tokenPath: TOKEN_PATH, + api: { + tiersForApi: GithubTiersVersion.free, + hostname: "", + }, + workflow: { + commitMessage: "[PUBLISHER] Merge", + name: "", + }, + otherRepo: [], + verifiedRepo: false, + rateLimit: 0, + }, + upload: { + behavior: FolderSettings.fixed, + defaultName: "", + rootFolder: "", + yamlFolderKey: "", + frontmatterTitle: { + enable: false, + key: "title", + }, + replaceTitle: [], + replacePath: [], + autoclean: { + enable: false, + excluded: [], + }, + folderNote: { + enable: false, + rename: "index.md", + addTitle: { + enable: false, + key: "title", + } + }, + metadataExtractorPath: "", + }, + conversion: { + hardbreak: false, + dataview: true, + censorText: [], + tags: { + inline: false, + exclude: [], + fields: [], + }, + links: { + internal: false, + unshared: false, + wiki: false, + slugify: "disable", + }, + }, + embed: { + attachments: true, + overrideAttachments: [], + keySendFile: [], + notes: false, + folder: "", + convertEmbedToLinks: "keep", + charConvert: "->", + unHandledObsidianExt: [], + sendSimpleLinks: true, + }, + plugin: { + shareKey: "share", + fileMenu: false, + editorMenu: false, + excludedFolder: [], + copyLink: { + enable: false, + links: "", + removePart: [], + addCmd: false, + transform: { + toUri: true, + slugify: "lower", + applyRegex: [], + } + }, + noticeError: false, + displayModalRepoEditing: false, + setFrontmatterKey: "Set" + } +}; \ No newline at end of file diff --git a/src/interfaces/enum.ts b/src/interfaces/enum.ts new file mode 100644 index 00000000..f8f9bf23 --- /dev/null +++ b/src/interfaces/enum.ts @@ -0,0 +1,42 @@ + +/** + * @enum TypeOfEditRegex + * @description Allow to set a value for the regex replace settings, to replace the path or the title of a file with a regex + * - `path` : replace the path of the file + * - `title` : replace the title of the file + */ +export enum TypeOfEditRegex { + path = "path", + title = "title", +} + +export enum EnumbSettingsTabId { + github = "github-configuration", + upload = "upload-configuration", + text = "text-conversion", + embed = "embed-configuration", + plugin = "plugin-settings", + help = "help", +} + +/** + * Allow to set a value for the folder settings + * @enum FolderSettings + */ +export enum FolderSettings { + /** Use YAML frontmatter for settings the path */ + yaml = "yaml", + /** Use the obsidian tree */ + obsidian = "obsidian", + /** Use a fixed folder and send all in it */ + fixed = "fixed", +} + +/** + * @enum GithubTiersVersion + * @description Allow to set a value for the github tiers + */ +export enum GithubTiersVersion { + free = "Github Free/Pro/Team (default)", + entreprise = "Enterprise", +} \ No newline at end of file diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts new file mode 100644 index 00000000..78f6ebf4 --- /dev/null +++ b/src/interfaces/index.ts @@ -0,0 +1,32 @@ +//export interface in a file to prevent breaking & allow to easily find the interface + +import { DEFAULT_SETTINGS,FIND_REGEX, TOKEN_PATH } from "./constant"; +import {EnumbSettingsTabId,FolderSettings, GithubTiersVersion, TypeOfEditRegex } from "./enum"; +import { Deleted, ListEditedFiles, UploadedFiles } from "./list_edited_files"; +import { FrontmatterConvert, GitHubPublisherSettings,GithubRepo,LinkedNotes, OverrideAttachments, Path, RegexReplace, RepoFrontmatter,Repository, SetRepositoryFrontmatter, TextCleaner } from "./main"; +import { MonoProperties,MonoRepoProperties,MultiProperties, MultiRepoProperties } from "./properties"; +import { MetadataExtractor } from "./settings"; + +export {DEFAULT_SETTINGS,EnumbSettingsTabId,FIND_REGEX,FolderSettings,GithubTiersVersion,TOKEN_PATH, TypeOfEditRegex, +}; + +export type { + Deleted, + FrontmatterConvert, + GitHubPublisherSettings, + GithubRepo, + LinkedNotes, + ListEditedFiles, + MetadataExtractor, + MonoProperties, + MonoRepoProperties, + MultiProperties, + MultiRepoProperties, + OverrideAttachments, + Path, + RegexReplace, + RepoFrontmatter, + Repository, + SetRepositoryFrontmatter, + TextCleaner, + UploadedFiles}; \ No newline at end of file diff --git a/src/interfaces/list_edited_files.ts b/src/interfaces/list_edited_files.ts new file mode 100644 index 00000000..7be8a5d0 --- /dev/null +++ b/src/interfaces/list_edited_files.ts @@ -0,0 +1,42 @@ + +/** + * Interface for list edited files + * Allow to know which files was edited, deleted, added, unpublished, not deleted + */ +export interface ListEditedFiles { + /** List of edited file path on the repository */ + edited: string[]; + /** List of deleted file path on the repository */ + deleted: string[]; + /** List of added file path on the repository */ + added: string[]; + /** List of unpublished file path on the repository */ + unpublished: string[]; + /** List of not deleted file path on the repository */ + notDeleted: string[]; +} + +/** + * Interface for uploaded files + * Used in ListEditedFiles to create it + */ +export interface UploadedFiles { + /** Know if the file was updated on the repo or created */ + isUpdated: boolean; + /** The path of the file */ + file: string; +} + +/** + * Interface for deleted files + * Used in ListEditedFiles to create it + * List deleted and undeleted file + */ +export interface Deleted { + success: boolean; + deleted: string[]; + undeleted: string[]; +} + + + diff --git a/src/interfaces/main.ts b/src/interfaces/main.ts new file mode 100644 index 00000000..576ac33f --- /dev/null +++ b/src/interfaces/main.ts @@ -0,0 +1,296 @@ +import { FrontMatterCache, TFile } from "obsidian"; + +import { EnumbSettingsTabId, FolderSettings,TypeOfEditRegex } from "./enum"; +import { Api, Conversion, CopyLink, Embed, GitHub, PluginBehavior, ShareAll, Upload, Workflow } from "./settings"; + +/** + * @interface RegexReplace + * @description Interface for the regex replace settings, to replace the path or the title of a file with a regex + */ +export interface RegexReplace { + regex: string; + replacement: string; + type: TypeOfEditRegex; +} + +/** + * @interface Repository + * @description Interface when registering another repository than the default one + */ +export interface Repository { + /** + * The smart key of the repository (used to identify the repository) + */ + smartKey: string; + /** + * The user of the repository (can be a real user or a community) + */ + user: string; + /** + * The repository name + */ + repo: string; + /** + * The branch of the repository (default: main) + */ + branch: string; + /** + * If the PR should be automatically merged + */ + automaticallyMergePR: boolean; + /** + * if the validity of the repository was checked and valide + */ + verifiedRepo?: boolean; + /** + * The rate limit of the GitHub API + */ + rateLimit?: number; + /** + * The github token if needed ; use the default one if not set + */ + token?: string; + /** + * The github API hostname + */ + api: Api; + /** + * The workflow settings for merging the PR or active a github action + */ + workflow: Workflow; + /** + * Create a shortcut in obsidian menus (right-click / file menu / editor menu) for action on this repository + */ + createShortcuts: boolean; + /** + * The name of the share key + */ + shareKey: string; + /** + * Share all file without a sharing key + */ + shareAll?: ShareAll; + /** + * Setting for copy link commands + */ + copyLink: CopyLink, + /** + * Allow to set a file for settings that override for example path, dataview, hardbreak... + * Useful for autoclean settings, but also for other settings without needing to change the frontmatter and use the set function + */ + set: string | null; +} + +/** + * @interface GitHubPublisherSettings + * @description Interface for the settings of the plugin + */ +export interface GitHubPublisherSettings { + /** + * Save the tabs id when the settings was closed, pretty useful when quick tests are done + */ + tabsID?: EnumbSettingsTabId; + /** + * GitHub settings for the default repository + */ + github: GitHub; + /** Path settings, including converting like, replace path (with regex), folder note support... */ + upload: Upload; + /** + * Settings for the content like hardbreak, dataview, censor text, tags, links... + */ + conversion: Conversion; + /** Files attached to other files by embedded or links. Include attachments settings (image...) */ + embed: Embed; + plugin: PluginBehavior; +} + + +/** + * @interface LinkedNotes + * @description Interface for the linked notes, with the file, the link from, the alt text and the destination file path + */ +export interface LinkedNotes { + /** The TFile linked */ + linked: TFile; + /** The source (where the file was found) from */ + linkFrom: string; + /** The alt text/alias of the link */ + altText?: string; + /** The destination file path if any (frontmatter settings, like title etc)*/ + destinationFilePath?: string; + /** If the file was linked by an anchor + * Include the `#` in the anchor + * @example `[[file#anchor]]` + */ + anchor?: string; + /** If the file was linked by an embed or a link */ + type: "embed" | "link"; + /** Position of the embed /link if any (used for bake) */ + position?: { + start: number; + end: number; + } +} + +/** + * @interface ConvertedLink + * A type for the shared files in the vault that includes the repoFrontmatter, but also the real path in Obsidian and the converted path in GitHub + */ +export interface ConvertedLink { + /** Path in GitHub */ + converted: string; + /** Path in Obsidian */ + real: string; + /** The repoFrontmatter */ + repoFrontmatter?: RepoFrontmatter | RepoFrontmatter[]; +} + +/** + * @interface GithubRepo + * @description File in the github Repository with the sha + */ +export interface GithubRepo { + file: string; + sha: string; +} + +/** + * @interface TextCleaner + * @description Interface for the text cleaner settings, to replace some text in the files + */ +export interface TextCleaner { + /** Text to replace */ + entry: string; + /** Replacement (support regex)*/ + replace: string; + /** After or before all other conversion */ + after: boolean; + /** If the text is a regex with flags*/ + flags?: string; + /** Change the text in codeBlocks too. */ + inCodeBlocks?: boolean; +} + +/** + * @interface Path + * Override the path of a file using the frontmatter settings + * It can override majority of {@link Upload} settings + * The frontmatter can be written in the syntax `key.subkey: value` + * Also, it supports smartkey so: `smartkey.key.subkey: value` override the path only for the linked {@link Repository} with the smartkey + */ +export interface Path { + /** Folder settings + * - `yaml` : Use YAML frontmatter for settings the path + * - `obsidian` : Use the obsidian tree + * - `fixed` : Use a fixed folder and send all in it + */ + type: FolderSettings; + /** The default receipt folder, used by `yaml` type only */ + defaultName: string; + /** The root folde */ + rootFolder: string; + /** If the category key is overridden */ + category?: { + /** The name of the key */ + key: string; + /** The value found */ + value: string; + }; + /** Override the entire path, from root and must include the extension */ + override?: string; + /** If a smartkey is found, for repository settings */ + smartkey?: string; + /** Override attachement settings */ + attachment?: { + /** Send or not attachment */ + send: boolean; + /** Default folder for attachment */ + folder: string; + }; +} + +/** A sort of extension of RepoFrontmatter, but include settings like bake embed, dataview or unshared links conversion */ +export interface FrontmatterConvert { + /** Convert links */ + links: boolean; + /** Send attachment */ + attachment: boolean; + /** Send embed */ + embed: boolean; + /** Folder receipt of file */ + attachmentLinks?: string; + /** Convert wikilinks to markdown */ + convertWiki: boolean; + /** Remove embed or bake it */ + removeEmbed: "keep" | "remove" | "links" | "bake"; + /** Add text before embed, like `-> [[embed]]` instead of `![[embed]]` */ + charEmbedLinks: string; + /** Convert dataview queries */ + dataview: boolean; + /** Add hardbreak */ + hardbreak: boolean; + /** convert link of unshared files */ + unshared: boolean; + /** Convert internal links to their part in the github repo */ + convertInternalLinks: boolean; + /** Include also linked files in the send/conversion */ + includeLinks: boolean; +} + +/** A very important interface that handle a repository from the frontmatter and a lot of usefull settings that override the default plugin behavior, including {@link Path}. + * RepoFrontmatter also handle {@link Repository} settings. +*/ +export interface RepoFrontmatter { + /** Branch name */ + branch: string; + /** The repository name */ + repo: string; + /** The owner of the repository */ + owner: string; + /** Allow autoclean the repo */ + autoclean: boolean; + /** workflow name if needed to activate it */ + workflowName: string; + /** commitMsg if the default is not okay for this repo */ + commitMsg: string; + /** Automatically merge the PR */ + automaticallyMergePR: boolean; + /** If the repository was checked */ + verifiedRepo?: boolean; + /** Override path settings */ + path?: Path; + /** Save the rate Limit from {@link Repository} */ + rateLimit?: number; + /** If the dryRun is enabled and which settings are used */ + dryRun: { + /** Enable the dryRun */ + enable: boolean; + /** The folder receipt */ + folderName: string; + /** If autoclean must perform in it */ + autoclean: boolean; + } +} +/** + * Preset from the official repository + */ +export interface Preset { + name: string; + settings: GitHubPublisherSettings; +} + +export type SetRepositoryFrontmatter = {[repository: string] : FrontMatterCache | null | undefined}; + +/** + * Override attachments settings, allowing force push and changing the destination + */ +export interface OverrideAttachments { + /** Path to override. + * Support `{{all}}` special keys for handled all attachment */ + path: string; + /** Destination of the files, use `{{default}}` to send into their default repository */ + destination: string; + /** Force push the attachments */ + forcePush: boolean; +} \ No newline at end of file diff --git a/src/interfaces/properties.ts b/src/interfaces/properties.ts new file mode 100644 index 00000000..cb9d7607 --- /dev/null +++ b/src/interfaces/properties.ts @@ -0,0 +1,54 @@ +import { FrontMatterCache } from "obsidian"; + +import GithubPublisher from "../main"; +import { FrontmatterConvert, RepoFrontmatter, Repository } from "./main"; + +/** + * @interface MultiProperties + * @description Interface for the properties of a multiple {@link RepoFrontmatter} int the frontmatter + * Allow to know the plugin, the frontmatter, the repository and the filepath + */ +export interface MultiProperties { + plugin: GithubPublisher; + frontmatter: { + general: FrontmatterConvert; + repo: RepoFrontmatter | RepoFrontmatter[]; + }, + repository: Repository | null; + filepath: string; +} + +/** + * @interface MonoProperties + * Same as {@link MultiProperties} but for a single {@link RepoFrontmatter} + */ +export interface MonoProperties { + plugin: GithubPublisher; + frontmatter: { + general: FrontmatterConvert; + repo: RepoFrontmatter; + source: FrontMatterCache | null | undefined; + }, + repository: Repository | null; + filepath: string; + +} + +/** + * @interface MonoRepoProperties + * A resume of {@link MonoProperties} and {@link MultiProperties} for a single repoFrontmatter + */ +export interface MonoRepoProperties { + frontmatter: RepoFrontmatter; + repo: Repository | null; + convert: FrontmatterConvert; +} + +/** + * @interface MultiRepoProperties + * A resume of {@link MonoProperties} and {@link MultiProperties} for multiple repoFrontmatter + */ +export interface MultiRepoProperties { + frontmatter: RepoFrontmatter[] | RepoFrontmatter; + repo: Repository | null; +} \ No newline at end of file diff --git a/src/interfaces/settings.ts b/src/interfaces/settings.ts new file mode 100644 index 00000000..9dbeae58 --- /dev/null +++ b/src/interfaces/settings.ts @@ -0,0 +1,306 @@ +import { FolderSettings, GithubTiersVersion } from "./enum"; +import { OverrideAttachments,RegexReplace, Repository, TextCleaner } from "./main"; + +export type Api = { + /** + * The tier of the API + * @default GithubTiersVersion.free + */ + tiersForApi: GithubTiersVersion; + /** + * The hostname of the API + */ + hostname: string; +} + +export type Workflow = { + /** + * The commit message when the PR is merged + */ + commitMessage: string; + /** + * The path of the github action file + * The github action needs to be set on "workflow_dispatch" to be able to be triggered + */ + name: string; +} + +export type ShareAll = { + enable: boolean; + /** + * The name of the files to exclude + */ + excludedFileName: string; +} + +export type CopyLink = { + /** + * Link to made the copy link command + */ + links: string; + /** + * Remove part of the link + */ + removePart: string[]; + /** + * Adjust the created link + */ + transform: { + /** + * Transform the link to an uri + */ + toUri: boolean; + /** + * Slugify the link + * - `lower` : slugify the link in lower case + * - `strict` : slugify the link in lower case and remove all special characters (including chinese or russian one) + * - `disable` : do not slugify the link + */ + slugify: "lower" | "strict" | "disable"; + /** + * Apply a regex to the link + */ + applyRegex: { + regex: string; + replacement: string; + }[] + } +} + +/** + * The GitHub settings of the plugin + */ +export interface GitHub { + + /** The user that belongs to the repository, can be also a community (like obsidian-publisher) */ + user: string; + /** The name of the repository */ + repo: string; + /** + * The branch of the repository (default: main) + */ + branch: string; + /** + * The path where the token is stored (as the token is not saved in the settings directly, to prevent mistake and security issue) + * @default `%configDir%/plugins/%pluginID%/env` + */ + tokenPath: string; + /** + * If the PR should be automatically merged + */ + automaticallyMergePR: boolean; + /** + * Don't push the changes to the repository, or make any action on the repository + * It will use a local folder instead to mimic the behavior of the plugin + */ + dryRun: { + enable: boolean; + /** The folder name that mimic the folder, allow special keys to mimic multiple repository + * @key `%owner%` the owner of the repository (equivalent to `user`) + * @key `%repo%` the name of the repository + * @key `%branch%` the branch of the repository + */ + folderName: string; + } + /** + * The settings for the github API + */ + api: Api, + /** workflow and action of the plugin in github */ + workflow: Workflow, + /** Enable the usage of different repository */ + otherRepo: Repository[]; + /** If the default repository is verified */ + verifiedRepo?: boolean; + /** The rate limit of the Github API */ + rateLimit: number; + +} + +/** + * The settings for the upload settings tabs + */ +export interface Upload { + + /** The behavior of the folder settings + * - `yaml` : use a yaml frontmatter to set the path + * - `obsidian` : use the obsidian path + * - `fixed` : use a fixed folder and send all in it + */ + behavior: FolderSettings; + /** The default name of the folder + * Used only with `yaml` behavior, when the `category: XXX` is not set in the frontmatter. + */ + defaultName: string; + /** The root folder of the repository + * Used with all behavior + */ + rootFolder: string; + /** The "category" key name if used with YAML behavior */ + yamlFolderKey: string; + /** Generate the filename using a frontmatter key, to change it in the repository. + */ + frontmatterTitle: { + enable: boolean; + /** @default `title` */ + key: string; + } + /** Edit the title by using regex */ + replaceTitle: RegexReplace[], + /** Edit the path by using regex; apply also on attachment path (will be applied on all path)*/ + replacePath: RegexReplace[], + /** Auto remove file that was unshared (deleted in Obsidian or removed by set `share: false`) */ + autoclean: { + enable: boolean; + /** Prevent deleting files */ + excluded: string[]; + } + /** Allow to set a folder note in `index.md` (example) when some settings are met + * For example, auto-rename to `index.md` when the file name and the folder name are the same. + */ + folderNote: { + enable: boolean; + /** The name of the index, by default `index.md`*/ + rename: string; + /** save the old title in the frontmatter */ + addTitle: { + enable: boolean; + key: string; + }; + } + /** The path to the metadata extractor plugin */ + metadataExtractorPath: string; +} + +export interface Conversion { + /** Add the two markdown space at the end of each line */ + hardbreak: boolean; + /** Convert dataview queries to markdown */ + dataview: boolean; + /** Allow to edit the content of files with regex */ + censorText: TextCleaner[]; + /** Add tags into frontmatter */ + tags: { + /** Allow to add inline tags into the frontmatter, like #tags into tags: [] */ + inline: boolean; + /** Exclude some tags from that */ + exclude: string[]; + /** add the fields value into tags too */ + fields: string[]; + } + /** Settings for the links */ + links: { + /** Convert internal links to their proper path into Obsidian */ + internal: boolean; + /** Also convert the internal path for unshared files */ + unshared: boolean; + /** Convert wikilinks to markdown links */ + wiki: boolean; + /** Slugify links if needed + * - `disable` : do not slugify the link + * - `strict` : slugify the link in lower case and remove all special characters (including chinese or russian one) + * - `lower` : slugify the link in lower case + * @default `disable` + */ + slugify: "disable" | "strict" | "lower" | boolean; + } +} + +/** + * The settings for the embed settings tabs + * Allow to set the behavior of the embeds, like attachments, notes, links... + */ +export interface Embed { + /** Allow to send attachments */ + attachments: boolean; + /** Force push attachments and change their path. + * Will be before the replacePath settings + */ + overrideAttachments: OverrideAttachments[]; + /** Use the obsidian folder for the attachments */ + useObsidianFolder?: boolean; + /** Send files linkeds to a frontmatter keys */ + keySendFile: string[]; + /** Also send embeddednotes */ + notes: boolean; + /** The folder where the attachments are stored */ + folder: string; + /** Modify the embeds: + * - `links` : convert the embed to links + * - `remove` : remove the embed + * - `keep` : keep the embed + * - `bake` : bake the embed into the text + */ + convertEmbedToLinks: "links" | "remove" | "keep" | "bake"; + /** Allow to insert character(s) before the link + * @example `->` allow to convert `[[file]]` to `-> [[file]]` + */ + charConvert: string; + /** Baking settings when including the text of the embed directly into the notes */ + bake?: { + /** Allow */ + textBefore: string; + textAfter: string; + }; + /** Allow send file not natively supported by obsidian + * Support regex (with `/regex/flags` format) + */ + unHandledObsidianExt: string[]; + /** Also send files /attachments linkeds by links (ie [[file]]) + * Will apply all previous settings + */ + sendSimpleLinks: boolean; +} + +/** + * The settings for the plugin behavior + * Allow to set the behavior of the plugin, like commands added, share all, logs... + */ +export interface PluginBehavior { + /** The native key for sharing + * @default `share` + */ + shareKey: string; + /** Allow to share all file without using a frontmatter key */ + shareAll?: ShareAll; + /** Allow to create shortcuts in the file menu (right click in explorer)*/ + fileMenu: boolean; + /** Allow to create shortcuts in the editor menu (right click in editor)*/ + editorMenu: boolean; + /** The folder to exclude from the plugin */ + excludedFolder: string[]; + /** Allow to create a commands to copy the link */ + copyLink: { + /** Enable globally the creator when a file is created => send it in the clipboard */ + enable: boolean; + /** Create a commands in the palette */ + addCmd: boolean; + } & CopyLink; + /** Send an obsidian notification on error */ + noticeError: boolean; + /** Send all logs in the console */ + dev?: boolean; + /** Display a strange modal when a file is send, resuming the action of the plugin */ + displayModalRepoEditing: boolean; + /** If the settings was migrated from previous version. */ + migrated?: boolean; + /** Allow to save the tabsId. + * If disabled, the user will always return to the default tab when the settings are closed. + */ + saveTabId?: boolean; + /** Key used for "link" a frontmatter (overriding default settings) into another frontmatter + * @default `Set` + * @example `Set: [[frontmatter]]` + */ + setFrontmatterKey: string; +} + +/** + * @interface MetadataExtractor + * @description Interface for the metadata extractor plugin + */ +export interface MetadataExtractor { + allExceptMdFile: string | null; + metadataFile: string | null; + tagsFile: string | null; +} diff --git a/src/main.ts b/src/main.ts index 5a575cdc..21bed089 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,13 +16,14 @@ import { ChooseWhichRepoToRun } from "./commands/suggest_other_repo_commands_mod import { getTitleField, regexOnFileName } from "./conversion/file_path"; import { GithubBranch } from "./GitHub/branch"; import { resources, translationLanguage } from "./i18n/i18next"; -import { GithubPublisherSettingsTab } from "./settings"; import { DEFAULT_SETTINGS, GitHubPublisherSettings, GithubTiersVersion, Repository, -} from "./settings/interface"; + SetRepositoryFrontmatter, +} from "./interfaces"; +import { GithubPublisherSettingsTab } from "./settings"; import { migrateSettings, OldSettings } from "./settings/migrate"; import { createTokenPath, monkeyPatchConsole, notif } from "./utils"; import { checkRepositoryValidity, verifyRateLimitAPI } from "./utils/data_validation_test"; @@ -35,6 +36,7 @@ import { checkRepositoryValidity, verifyRateLimitAPI } from "./utils/data_valida export default class GithubPublisher extends Plugin { settings!: GitHubPublisherSettings; branchName: string = ""; + repositoryFrontmatter: SetRepositoryFrontmatter = {}; /** * Get the title field of a file @@ -213,6 +215,17 @@ export default class GithubPublisher extends Plugin { const repoOctokit = await this.reloadOctokit(repository.smartKey); repository.verifiedRepo = await checkRepositoryValidity(repoOctokit, repository, null, false); repository.rateLimit = await verifyRateLimitAPI(repoOctokit.octokit, this.settings); + + if (repository.set) { + //take the file and update the frontmatter + const file = this.app.vault.getAbstractFileByPath(repository.set); + if (file && file instanceof TFile) { + const frontmatter = this.app.metadataCache.getFileCache(file)?.frontmatter; + if (frontmatter) { + this.repositoryFrontmatter[repository.smartKey] = frontmatter; + } + } + } } await this.saveSettings(); diff --git a/src/settings.ts b/src/settings.ts index 9aac8796..e2cbd848 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,6 +1,9 @@ import i18next from "i18next"; import { App, Notice, PluginSettingTab, setIcon, Setting } from "obsidian"; +import { + EnumbSettingsTabId, FolderSettings, GitHubPublisherSettings, GithubTiersVersion, Repository +} from "./interfaces"; import GithubPublisherPlugin from "./main"; import { help, @@ -9,9 +12,6 @@ import { supportMe, usefulLinks } from "./settings/help"; -import { - EnumbSettingsTabId, FolderSettings, GitHubPublisherSettings, GithubTiersVersion, Repository -} from "./settings/interface"; import { migrateToken } from "./settings/migrate"; import { ExportModal, ImportLoadPreset, ImportModal, loadAllPresets } from "./settings/modals/import_export"; import { ModalAddingNewRepository } from "./settings/modals/manage_repo"; @@ -1400,6 +1400,10 @@ export class GithubPublisherSettingsTab extends PluginSettingTab { // eslint-disable-next-line copy(object: any) { - return JSON.parse(JSON.stringify(object)); + try { + return JSON.parse(JSON.stringify(object)); + } catch (e) { + console.log("error with stringify for", object); + } } } diff --git a/src/settings/help.ts b/src/settings/help.ts index aae9419b..8fb7790a 100644 --- a/src/settings/help.ts +++ b/src/settings/help.ts @@ -2,7 +2,7 @@ import i18next from "i18next"; import { normalizePath } from "obsidian"; import { regexOnPath } from "../conversion/file_path"; -import { FolderSettings, GitHubPublisherSettings } from "./interface"; +import { FolderSettings, GitHubPublisherSettings } from "../interfaces"; function spanAtRule(text: string, code: DocumentFragment, br: boolean = true): HTMLElement { if (br) code.createEl("br"); diff --git a/src/settings/interface.ts b/src/settings/interface.ts deleted file mode 100644 index 0bcda8f6..00000000 --- a/src/settings/interface.ts +++ /dev/null @@ -1,467 +0,0 @@ -import { FrontMatterCache, TFile } from "obsidian"; - -import GithubPublisher from "../main"; - -export enum TypeOfEditRegex { - path = "path", - title = "title", -} - -export enum EnumbSettingsTabId { - github = "github-configuration", - upload = "upload-configuration", - text = "text-conversion", - embed = "embed-configuration", - plugin = "plugin-settings", - help = "help", -} - -export interface RegexReplace { - regex: string; - replacement: string; - type: TypeOfEditRegex; -} - -export interface Repository { - smartKey: string; - user: string; - repo: string; - branch: string; - automaticallyMergePR: boolean; - verifiedRepo?: boolean; - rateLimit?: number; - token?: string; - api: { - tiersForApi: GithubTiersVersion; - hostname: string; - } - workflow: { - commitMessage: string; - name: string; - } - createShortcuts: boolean; - shareKey: string; - shareAll?: { - enable: boolean; - excludedFileName: string; - } - copyLink: { - links: string; - removePart: string[]; - transform: { - toUri: boolean; - slugify: "lower" | "strict" | "disable"; - applyRegex: { - regex: string; - replacement: string; - }[] - } - }, - set: string; -} - -/** - * @interface GitHubPublisherSettings - * @description Interface for the settings of the plugin - */ -export interface GitHubPublisherSettings { - tabsID?: EnumbSettingsTabId; - github: { - user: string; - repo: string; - branch: string; - tokenPath: string; - automaticallyMergePR: boolean; - dryRun: { - enable: boolean; - folderName: string; - } - api: { - tiersForApi: GithubTiersVersion; - hostname: string; - } - workflow: { - commitMessage: string; - name: string; - }, - otherRepo: Repository[]; - verifiedRepo?: boolean; - rateLimit: number; - } - upload: { - behavior: FolderSettings; - defaultName: string; - rootFolder: string; - yamlFolderKey: string; - frontmatterTitle: { - enable: boolean; - key: string; - } - replaceTitle: RegexReplace[], - replacePath: RegexReplace[], - autoclean: { - enable: boolean; - excluded: string[]; - } - folderNote: { - enable: boolean; - rename: string; - addTitle: { - enable: boolean; - key: string; - }; - } - metadataExtractorPath: string; - } - conversion: { - hardbreak: boolean; - dataview: boolean; - censorText: TextCleaner[]; - tags: { - inline: boolean; - exclude: string[]; - fields: string[]; - } - links: { - internal: boolean; - unshared: boolean; - wiki: boolean; - slugify: "disable" | "strict" | "lower" | boolean; - } - } - embed: { - attachments: boolean; - overrideAttachments: OverrideAttachments[]; - useObsidianFolder?: boolean; - keySendFile: string[]; - notes: boolean; - folder: string; - convertEmbedToLinks: "links" | "remove" | "keep" | "bake"; - charConvert: string; - bake?: { - textBefore: string; - textAfter: string; - }; - unHandledObsidianExt: string[]; - sendSimpleLinks: boolean; - } - plugin: - { - shareKey: string; - shareAll?: { - enable: boolean; - excludedFileName: string; - } - fileMenu: boolean; - editorMenu: boolean; - excludedFolder: string[]; - copyLink: { - enable: boolean; - links: string; - removePart: string[]; - addCmd: boolean; - transform: { - toUri: boolean; - slugify: "lower" | "strict" | "disable"; - applyRegex: { - regex: string; - replacement: string; - }[] - } - } - noticeError: boolean; - dev?: boolean; - displayModalRepoEditing: boolean; - migrated?: boolean; - saveTabId?: boolean; - setFrontmatterKey: string; - - } -} - - - -/** - * Allow to set a value for the folder settings - * @enum FolderSettings - */ -export enum FolderSettings { - yaml = "yaml", - obsidian = "obsidian", - fixed = "fixed", -} - -/** - * @enum GithubTiersVersion - * @description Allow to set a value for the github tiers - */ -export enum GithubTiersVersion { - free = "Github Free/Pro/Team (default)", - entreprise = "Enterprise", -} - -export interface MultiProperties { - plugin: GithubPublisher; - frontmatter: { - general: FrontmatterConvert; - repo: RepoFrontmatter | RepoFrontmatter[]; - }, - repository: Repository | null; - filepath: string; -} - -export interface MonoProperties { - plugin: GithubPublisher; - frontmatter: { - general: FrontmatterConvert; - repo: RepoFrontmatter; - source: FrontMatterCache | null | undefined; - }, - repository: Repository | null; - filepath: string; - -} - -export interface MonoRepoProperties { - frontmatter: RepoFrontmatter; - repo: Repository | null; - convert: FrontmatterConvert; -} - -export interface MultiRepoProperties { - frontmatter: RepoFrontmatter[] | RepoFrontmatter; - repo: Repository | null; - -} - - -/** - * Just a constant for the token path - * @type {string} TOKEN_PATH - */ -export const TOKEN_PATH: string = "%configDir%/plugins/%pluginID%/env"; - -export const DEFAULT_SETTINGS: Partial = { - github: { - user: "", - repo: "", - branch: "main", - automaticallyMergePR: true, - dryRun: { - enable: false, - folderName: "github-publisher", - }, - tokenPath: TOKEN_PATH, - api: { - tiersForApi: GithubTiersVersion.free, - hostname: "", - }, - workflow: { - commitMessage: "[PUBLISHER] Merge", - name: "", - }, - otherRepo: [], - verifiedRepo: false, - rateLimit: 0, - }, - upload: { - behavior: FolderSettings.fixed, - defaultName: "", - rootFolder: "", - yamlFolderKey: "", - frontmatterTitle: { - enable: false, - key: "title", - }, - replaceTitle: [], - replacePath: [], - autoclean: { - enable: false, - excluded: [], - }, - folderNote: { - enable: false, - rename: "index.md", - addTitle: { - enable: false, - key: "title", - } - }, - metadataExtractorPath: "", - }, - conversion: { - hardbreak: false, - dataview: true, - censorText: [], - tags: { - inline: false, - exclude: [], - fields: [], - }, - links: { - internal: false, - unshared: false, - wiki: false, - slugify: "disable", - }, - }, - embed: { - attachments: true, - overrideAttachments: [], - keySendFile: [], - notes: false, - folder: "", - convertEmbedToLinks: "keep", - charConvert: "->", - unHandledObsidianExt: [], - sendSimpleLinks: true, - }, - plugin: { - shareKey: "share", - fileMenu: false, - editorMenu: false, - excludedFolder: [], - copyLink: { - enable: false, - links: "", - removePart: [], - addCmd: false, - transform: { - toUri: true, - slugify: "lower", - applyRegex: [], - } - }, - noticeError: false, - displayModalRepoEditing: false, - setFrontmatterKey: "Set" - } -}; - -/** - * @interface MetadataExtractor - * @description Interface for the metadata extractor plugin - */ -export interface MetadataExtractor { - allExceptMdFile: string | null; - metadataFile: string | null; - tagsFile: string | null; -} - - -/** - * @interface LinkedNotes - * @description Interface for the linked notes, with the file, the link from, the alt text and the destination file path - */ -export interface LinkedNotes { - linked: TFile; - linkFrom: string; - altText?: string; - destinationFilePath?: string; - anchor?: string; - type: "embed" | "link"; - position?: { - start: number; - end: number; - } -} - -export interface ConvertedLink { - converted: string; - real: string; - repoFrontmatter?: RepoFrontmatter | RepoFrontmatter[]; -} - -export interface GithubRepo { - file: string; - sha: string; -} - -export interface TextCleaner { - entry: string; - replace: string; - after: boolean; - flags?: string; - inCodeBlocks?: boolean; -} - -export interface Path { - type: FolderSettings; - defaultName: string; - rootFolder: string; - category?: { - key: string; - value: string; - }; - override?: string; - smartkey?: string; - attachment?: { - send: boolean; - folder: string; - }; -} - -export interface FrontmatterConvert { - links: boolean; - attachment: boolean; - embed: boolean; - attachmentLinks?: string; - convertWiki: boolean; - removeEmbed: "keep" | "remove" | "links" | "bake"; - charEmbedLinks: string; - dataview: boolean; - hardbreak: boolean; - unshared: boolean; - convertInternalLinks: boolean; - includeLinks: boolean; -} - -export interface RepoFrontmatter { - branch: string; - repo: string; - owner: string; - autoclean: boolean; - workflowName: string; - commitMsg: string; - automaticallyMergePR: boolean; - verifiedRepo?: boolean; - path?: Path; - rateLimit?: number; - dryRun: { - enable: boolean; - folderName: string; - autoclean: boolean; - } -} - -export interface ListEditedFiles { - edited: string[]; - deleted: string[]; - added: string[]; - unpublished: string[]; - notDeleted: string[]; -} - -export interface UploadedFiles { - isUpdated: boolean; - file: string; -} - -export interface Deleted { - success: boolean; - deleted: string[]; - undeleted: string[]; -} - -export interface Preset { - name: string; - settings: GitHubPublisherSettings; -} - -export interface OverrideAttachments { - path: string; - destination: string; - forcePush: boolean; -} - -export const FIND_REGEX = /^\/(.*)\/[igmsuy]*$/; \ No newline at end of file diff --git a/src/settings/migrate.ts b/src/settings/migrate.ts index 1335a868..e6f33eea 100644 --- a/src/settings/migrate.ts +++ b/src/settings/migrate.ts @@ -1,9 +1,9 @@ import i18next from "i18next"; import { normalizePath } from "obsidian"; +import { FolderSettings, GithubTiersVersion, TextCleaner, TOKEN_PATH, TypeOfEditRegex } from "../interfaces"; import GithubPublisher from "../main"; import { createTokenPath, logs } from "../utils"; -import { FolderSettings, GithubTiersVersion, TextCleaner, TOKEN_PATH, TypeOfEditRegex } from "./interface"; export interface OldSettings { githubRepo: string; diff --git a/src/settings/modals/import_export.ts b/src/settings/modals/import_export.ts index 8f2be4fd..505072df 100644 --- a/src/settings/modals/import_export.ts +++ b/src/settings/modals/import_export.ts @@ -10,10 +10,10 @@ import { Setting, TextAreaComponent} from "obsidian"; +import {GitHubPublisherSettings, Preset} from "../../interfaces/main"; import GithubPublisher from "../../main"; import {GithubPublisherSettingsTab} from "../../settings"; import {logs, notif} from "../../utils"; -import {GitHubPublisherSettings, Preset} from "../interface"; import { migrateSettings,OldSettings } from "../migrate"; @@ -351,29 +351,33 @@ export class ImportLoadPreset extends FuzzySuggestModal { export async function loadAllPresets(octokit: Octokit, plugin: GithubPublisher): Promise { //load from gitHub repository + try { + const githubPreset = await octokit.request("GET /repos/{owner}/{repo}/contents/{path}", { + owner: "ObsidianPublisher", + repo: "plugin-presets", + path: "presets", + }); - const githubPreset = await octokit.request("GET /repos/{owner}/{repo}/contents/{path}", { - owner: "ObsidianPublisher", - repo: "plugin-presets", - path: "presets", - }); - - //create a list - const presetList: Preset[] = []; - if (!Array.isArray(githubPreset.data)) { - return presetList; - } - logs({settings: plugin.settings}, "LoadAllPreset", githubPreset); - for (const preset of githubPreset.data) { - if (preset.name.endsWith(".json")) { - const presetName = preset.name.replace(".json", ""); - presetList.push({ - name: presetName, - settings: await loadPresetContent(preset.path, octokit, plugin), - }); + //create a list + const presetList: Preset[] = []; + if (!Array.isArray(githubPreset.data)) { + return presetList; + } + logs({settings: plugin.settings}, "LoadAllPreset", githubPreset); + for (const preset of githubPreset.data) { + if (preset.name.endsWith(".json")) { + const presetName = preset.name.replace(".json", ""); + presetList.push({ + name: presetName, + settings: await loadPresetContent(preset.path, octokit, plugin), + }); + } } + return presetList; + } catch (e) { + notif({settings: plugin.settings, e: true}, "Couldn't load preset. Error:", e); + return []; } - return presetList; } export async function loadPresetContent(path: string, octokit: Octokit, plugin: GithubPublisher): Promise { diff --git a/src/settings/modals/list_changed.ts b/src/settings/modals/list_changed.ts index c45f9f4d..5b5eaeb6 100644 --- a/src/settings/modals/list_changed.ts +++ b/src/settings/modals/list_changed.ts @@ -1,7 +1,7 @@ import i18next from "i18next"; import { App,Modal } from "obsidian"; -import { Deleted, ListEditedFiles } from "../interface"; +import { Deleted, ListEditedFiles } from "../../interfaces"; export class ListChangedFiles extends Modal { diff --git a/src/settings/modals/manage_repo.ts b/src/settings/modals/manage_repo.ts index 0346cfe6..3a365aa2 100644 --- a/src/settings/modals/manage_repo.ts +++ b/src/settings/modals/manage_repo.ts @@ -1,38 +1,37 @@ import i18next from "i18next"; -import {AbstractInputSuggest, App, Modal, Notice, Setting} from "obsidian"; +import {AbstractInputSuggest, App, Modal, Notice, Setting, TFile} from "obsidian"; +import {GitHubPublisherSettings, GithubTiersVersion, Repository} from "../../interfaces"; import GithubPublisher from "../../main"; import {checkRepositoryValidity, verifyRateLimitAPI} from "../../utils/data_validation_test"; -import {GitHubPublisherSettings, GithubTiersVersion, Repository} from "../interface"; import { migrateToken } from "../migrate"; -class SetClassSuggester extends AbstractInputSuggest { +class SetClassSuggester extends AbstractInputSuggest { plugin: GithubPublisher; - constructor(private inputEl: HTMLInputElement, plugin: GithubPublisher, private onSubmit: (value: string) => void) { + constructor(private inputEl: HTMLInputElement, plugin: GithubPublisher, private onSubmit: (value: TFile) => void) { super(plugin.app, inputEl); this.plugin = plugin; } - renderSuggestion(value: string, el: HTMLElement): void { - el.setText(value); + renderSuggestion(value: TFile, el: HTMLElement): void { + el.setText(value.path); } - getSuggestions(query: string): string[] { - const markdownFile = this.plugin.app.vault.getFiles().filter((file) => { + getSuggestions(query: string): TFile[] { + return this.plugin.app.vault.getFiles().filter((file) => { if (file.extension === "md" && file.path.toLowerCase().contains(query.toLowerCase())) { const frontmatter = this.plugin.app.metadataCache.getFileCache(file)?.frontmatter; if (frontmatter) return true; } return false; }); - return markdownFile.map((file) => file.path); } //eslint-disable-next-line @typescript-eslint/no-unused-vars - selectSuggestion(value: string, evt: MouseEvent | KeyboardEvent): void { + selectSuggestion(value: TFile, evt: MouseEvent | KeyboardEvent): void { this.onSubmit(value); - this.inputEl.value = value; + this.inputEl.value = value.path; this.inputEl.focus(); this.inputEl.trigger("input"); this.close(); @@ -108,7 +107,7 @@ export class ModalAddingNewRepository extends Modal { applyRegex: this.settings.plugin.copyLink.transform.applyRegex } }, - set: "" + set: null }; new Setting(contentEl) @@ -367,7 +366,6 @@ class ModalEditingRepository extends Modal { .setValue(decryptedToken) .onChange(async (value) => { await migrateToken(this.plugin, value.trim(), this.repository.smartKey); - await this.plugin.saveSettings(); }); }); new Setting(contentEl) @@ -448,10 +446,12 @@ class ModalEditingRepository extends Modal { .setDesc(i18next.t("settings.plugin.setImport.desc")) .addSearch((search) => { search - .setValue("") + .setValue(this.repository.set ?? "") .setPlaceholder("path/to/file.md"); new SetClassSuggester(search.inputEl, this.plugin, (result) => { - this.repository.set = result; + this.repository.set = result.path; + const frontmatter = this.plugin.app.metadataCache.getFileCache(result)?.frontmatter; + this.plugin.repositoryFrontmatter[this.repository.smartKey] = frontmatter; }); }); @@ -479,7 +479,7 @@ class ModalEditingRepository extends Modal { .setValue(this.repository.shareKey) .onChange(async (value) => { this.repository.shareKey = value.trim(); - await this.plugin.saveSettings(); + }) ); } else { @@ -518,7 +518,7 @@ class ModalEditingRepository extends Modal { .setValue(this.repository.copyLink.removePart.join(", ")) .onChange(async (value) => { this.repository.copyLink.removePart = value.split(/[,\n]\s*/).map((item) => item.trim()).filter((item) => item.length > 0); - await this.plugin.saveSettings(); + }); }); @@ -530,7 +530,7 @@ class ModalEditingRepository extends Modal { .setValue(this.repository.copyLink.transform.toUri) .onChange(async (value) => { this.repository.copyLink.transform.toUri = value; - await this.plugin.saveSettings(); + }) ); @@ -546,7 +546,7 @@ class ModalEditingRepository extends Modal { .setValue(this.repository.copyLink.transform.slugify as "disable" | "strict" | "lower") .onChange(async (value) => { this.repository.copyLink.transform.slugify = value as "disable" | "strict" | "lower"; - await this.plugin.saveSettings(); + }); }); @@ -562,7 +562,7 @@ class ModalEditingRepository extends Modal { regex: "", replacement: "" }); - await this.plugin.saveSettings(); + this.onOpen(); }); }); @@ -579,7 +579,7 @@ class ModalEditingRepository extends Modal { .setValue(regex) .onChange(async (value) => { apply.regex = value; - await this.plugin.saveSettings(); + }); }) .setClass("max-width") @@ -589,7 +589,7 @@ class ModalEditingRepository extends Modal { .setValue(replacement) .onChange(async (value) => { apply.replacement = value; - await this.plugin.saveSettings(); + }); }) .setClass("max-width") @@ -597,7 +597,7 @@ class ModalEditingRepository extends Modal { button.setIcon("trash") .onClick(async () => { this.repository.copyLink.transform.applyRegex = this.repository.copyLink.transform.applyRegex.filter((item) => item !== apply); - await this.plugin.saveSettings(); + this.onOpen(); }); }); diff --git a/src/settings/modals/popup.ts b/src/settings/modals/popup.ts index b202e594..f849237c 100644 --- a/src/settings/modals/popup.ts +++ b/src/settings/modals/popup.ts @@ -1,7 +1,7 @@ import i18next from "i18next"; import { App, Modal, Setting } from "obsidian"; -import { GitHubPublisherSettings } from "../interface"; +import { GitHubPublisherSettings } from "../../interfaces/main"; export class AutoCleanPopup extends Modal { diff --git a/src/settings/modals/regex_edition.ts b/src/settings/modals/regex_edition.ts index bd0427f1..75404abc 100644 --- a/src/settings/modals/regex_edition.ts +++ b/src/settings/modals/regex_edition.ts @@ -2,7 +2,7 @@ import i18next from "i18next"; import {App, Modal, Notice, Setting} from "obsidian"; import { escapeRegex } from "src/conversion/links"; -import {FolderSettings, GitHubPublisherSettings, OverrideAttachments, RegexReplace, TextCleaner, TypeOfEditRegex} from "../interface"; +import {FolderSettings, GitHubPublisherSettings, OverrideAttachments, RegexReplace, TextCleaner, TypeOfEditRegex} from "../../interfaces"; function isRegexValid(regexString: string) { try { diff --git a/src/settings/modals/token_path.ts b/src/settings/modals/token_path.ts index 511559d7..490bd15d 100644 --- a/src/settings/modals/token_path.ts +++ b/src/settings/modals/token_path.ts @@ -3,7 +3,7 @@ import { App, Modal, Notice,Setting } from "obsidian"; import GithubPublisher from "src/main"; import { createTokenPath, logs } from "src/utils"; -import { TOKEN_PATH } from "../interface"; +import { TOKEN_PATH } from "../../interfaces"; import { migrateToken } from "../migrate"; export class TokenEditPath extends Modal { diff --git a/src/settings/style.ts b/src/settings/style.ts index ddbfec6d..d6ada973 100644 --- a/src/settings/style.ts +++ b/src/settings/style.ts @@ -2,8 +2,8 @@ import i18next from "i18next"; import { Notice, Setting } from "obsidian"; import { GithubPublisherSettingsTab } from "src/settings"; +import {EnumbSettingsTabId, FolderSettings, GitHubPublisherSettings} from "../interfaces"; import GithubPublisher from "../main"; -import {EnumbSettingsTabId, FolderSettings, GitHubPublisherSettings} from "./interface"; /** * show a settings * @param {Setting} containerEl setting to show diff --git a/src/utils/data_validation_test.ts b/src/utils/data_validation_test.ts index 5719d281..c6ae4a71 100644 --- a/src/utils/data_validation_test.ts +++ b/src/utils/data_validation_test.ts @@ -6,8 +6,8 @@ import GithubPublisher from "src/main"; import merge from "ts-deepmerge"; import {GithubBranch} from "../GitHub/branch"; -import {FIND_REGEX, FrontmatterConvert, GitHubPublisherSettings, GithubTiersVersion, MultiProperties, RepoFrontmatter, Repository} from "../settings/interface"; -import {logs, notif} from "."; +import {FIND_REGEX, FrontmatterConvert, GitHubPublisherSettings, GithubTiersVersion, MultiProperties, RepoFrontmatter, Repository} from "../interfaces"; +import { notif} from "."; import { frontmatterFromFile, getLinkedFrontmatter, getRepoFrontmatter } from "./parse_frontmatter"; /** @@ -57,13 +57,8 @@ export function getRepoSharedKey(plugin: GithubPublisher, frontmatter?: FrontMat } else if (!frontmatter) return null; const linkedFrontmatter = getLinkedFrontmatter(frontmatter, file, plugin); frontmatter = linkedFrontmatter ? merge(linkedFrontmatter, frontmatter) : frontmatter; - for (const repo of allOtherRepo) { - if (frontmatter[repo.shareKey]) { - return repo; - } - } - logs({settings}, "No other repo found, using default repo"); - return defaultRepo(settings); + return allOtherRepo.find(repo => frontmatter?.[repo.shareKey]) ?? defaultRepo(settings); + } /** @@ -87,7 +82,7 @@ export function isShared( return false; } const otherRepoWithShareAll = settings.github.otherRepo.filter((repo) => repo.shareAll?.enable); - if (!settings.plugin.shareAll?.enable && otherRepoWithShareAll.length === 0) { + if (!settings.plugin.shareAll?.enable && !otherRepoWithShareAll.length) { const shareKey = otherRepo ? otherRepo.shareKey : settings.plugin.shareKey; if ( meta == null || !meta[shareKey] || meta[shareKey] == null || isExcludedPath(settings, file, otherRepo) || meta[shareKey] === undefined || ["false", "0", "no"].includes(meta[shareKey].toString().toLowerCase())) { return false; @@ -409,7 +404,7 @@ export function defaultRepo(settings: GitHubPublisherSettings): Repository { applyRegex: settings.plugin.copyLink.transform.applyRegex, }, }, - set: "" + set: null }; } diff --git a/src/utils/index.ts b/src/utils/index.ts index d0eaa746..461b3320 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -14,7 +14,7 @@ import { MetadataExtractor, MultiRepoProperties, RepoFrontmatter, TOKEN_PATH, - UploadedFiles} from "../settings/interface"; + UploadedFiles} from "../interfaces"; import { ERROR_ICONS, HOURGLASS_ICON, SUCCESS_ICON } from "./icons"; import { frontmatterFromFile } from "./parse_frontmatter"; @@ -419,7 +419,7 @@ export function trimObject(obj: { [p: string]: string }) { * @param {string} tokenPath - The path of the token as entered by the user * @return {string} - The final path of the token */ -export function createTokenPath(plugin: GithubPublisher, tokenPath?: string) { +export function createTokenPath(plugin: GithubPublisher, tokenPath?: string): string { const vault = plugin.app.vault; if (!tokenPath) { tokenPath = TOKEN_PATH; diff --git a/src/utils/parse_frontmatter.ts b/src/utils/parse_frontmatter.ts index 0d9aacb0..49d8d6ad 100644 --- a/src/utils/parse_frontmatter.ts +++ b/src/utils/parse_frontmatter.ts @@ -7,15 +7,13 @@ import { FrontMatterCache, normalizePath, TFile } from "obsidian"; import GithubPublisher from "src/main"; import merge from "ts-deepmerge"; -import { FolderSettings, FrontmatterConvert, GitHubPublisherSettings, Path, RepoFrontmatter, Repository } from "../settings/interface"; +import { FolderSettings, FrontmatterConvert, GitHubPublisherSettings, Path, RepoFrontmatter, Repository } from "../interfaces"; export function frontmatterSettingsRepository(plugin: GithubPublisher, repo: Repository | null) { const defaultConvert = getFrontmatterSettings(null, plugin.settings, repo); - if (!repo?.set) return defaultConvert; - const fileAsTFile = plugin.app.vault.getFileByPath(repo.set); - if (!fileAsTFile) return defaultConvert; + if (!repo?.set || !plugin.repositoryFrontmatter[repo.smartKey]) return defaultConvert; return getFrontmatterSettings( - plugin.app.metadataCache.getFileCache(fileAsTFile)?.frontmatter, + plugin.repositoryFrontmatter[repo.smartKey], plugin.settings, repo ); @@ -23,10 +21,8 @@ export function frontmatterSettingsRepository(plugin: GithubPublisher, repo: Rep export function getDefaultRepoFrontmatter(repository: Repository | null, plugin: GithubPublisher) { const defaultSettings = getRepoFrontmatter(plugin, repository); - if (!repository) return defaultSettings; - const fileAsTFile = plugin.app.vault.getFileByPath(repository.set); - if (!fileAsTFile) return defaultSettings; - return getRepoFrontmatter(plugin, repository, plugin.app.metadataCache.getFileCache(fileAsTFile)?.frontmatter); + if (!repository?.set || (repository && !plugin.repositoryFrontmatter[repository.smartKey])) return defaultSettings; + return getRepoFrontmatter(plugin, repository, plugin.repositoryFrontmatter[repository.smartKey]); } @@ -113,12 +109,10 @@ export function getRepoFrontmatter( ): RepoFrontmatter[] | RepoFrontmatter { const settings = plugin.settings; let github = repository ?? settings.github; - if (checkSet && repository?.set && repository.set.length > 0) { - const file = plugin.app.vault.getAbstractFileByPath(repository.set) instanceof TFile ? plugin.app.vault.getAbstractFileByPath(repository.set) : null; - if (file) { - const setFrontmatter = plugin.app.metadataCache.getFileCache(file as TFile)?.frontmatter; - frontmatter = frontmatter && setFrontmatter ? merge(frontmatter, setFrontmatter) : setFrontmatter ?? frontmatter ; - } + if (checkSet && repository && plugin.repositoryFrontmatter[repository.smartKey]) { + const setFrontmatter = plugin.repositoryFrontmatter[repository.smartKey]; + frontmatter = frontmatter && setFrontmatter ? merge(frontmatter, setFrontmatter) : setFrontmatter ?? frontmatter ; + } if (frontmatter && typeof frontmatter["shortRepo"] === "string" && frontmatter["shortRepo"] !== "default") { const smartKey = frontmatter.shortRepo.toLowerCase(); @@ -488,12 +482,9 @@ export function frontmatterFromFile(file: TFile | null, plugin: GithubPublisher, const linkedFrontmatter = getLinkedFrontmatter(frontmatter, file, plugin); frontmatter = merge(linkedFrontmatter ?? {}, frontmatter ?? {}); } - if (repo && repo.set.length > 0) { - const fileAsTFile = plugin.app.vault.getFileByPath(repo.set); - if (fileAsTFile) { - const setFrontmatter = plugin.app.metadataCache.getFileCache(fileAsTFile)?.frontmatter; - frontmatter = frontmatter && setFrontmatter ? merge(frontmatter, setFrontmatter) : setFrontmatter ?? frontmatter; - } + if (repo?.set && plugin.repositoryFrontmatter[repo.smartKey]) { + const setFrontmatter = plugin.repositoryFrontmatter[repo.smartKey]; + frontmatter = frontmatter && setFrontmatter ? merge(frontmatter, setFrontmatter) : setFrontmatter ?? frontmatter; } return frontmatter; } diff --git a/src/utils/status_bar.ts b/src/utils/status_bar.ts index 713936ad..6f86d037 100644 --- a/src/utils/status_bar.ts +++ b/src/utils/status_bar.ts @@ -1,7 +1,7 @@ import i18next from "i18next"; import { Notice } from "obsidian"; -import { RepoFrontmatter } from "../settings/interface"; +import { RepoFrontmatter } from "../interfaces/main"; import { noticeMobile } from "."; import { ERROR_ICONS, FOUND_ATTACHMENTS, HOURGLASS_ICON, SUCCESS_ICON } from "./icons";