Skip to content

Commit

Permalink
feat: export & import settings
Browse files Browse the repository at this point in the history
cf #94
  • Loading branch information
Mara-Li committed Jan 26, 2023
1 parent baa4ce9 commit 90a6f9f
Show file tree
Hide file tree
Showing 9 changed files with 477 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ styles.css

# obsidian
data.json
._*

# Exclude macOS Finder (System Explorer) View States
.DS_Store
Expand Down
23 changes: 23 additions & 0 deletions plugin/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default {
noFileDeleted: "No files have been deleted.",
},
settings: {
exportSettings: "Export settings",
importSettings: "Import settings",
github: {
githubConfiguration: "Github Configuration",
repoName: "Repo Name",
Expand All @@ -51,6 +53,8 @@ export default {
"If you use a different main branch than \"main\", you can specify it here.",
automaticallyMergePR: "Automatically merge pull requests",
testConnection: "Test connection",


},
uploadConfig: {
uploadConfig: "Upload configuration",
Expand Down Expand Up @@ -290,5 +294,24 @@ export default {
ghToken: "GitHub Token",
},
},
modals: {
import: {
title: "Import",
desc: "Import settings from text or a file.",
importFromFile: "Import from file",
save: "Save",
paste: "Paste configuration here...",
error : {
span: "Error importing configuration: ",
isEmpty: "the configuration is empty.",
}
},
export: {
title: "Export",
desc: "Export settings to clipboard or a file.",
copy: "Copy to clipboard",
download: "Download",
}
}

};
21 changes: 21 additions & 0 deletions plugin/i18n/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default {
noFileDeleted: "Aucun fichier n'a été supprimé",
},
settings: {
exportSettings: "Exporter les paramètres",
importSettings: "Importer des paramètres",
github: {
githubConfiguration: "Configuration GitHub",
repoName: "Nom du dépôt",
Expand Down Expand Up @@ -304,4 +306,23 @@ export default {
ghToken: "Le token GitHub",
},
},
modals: {
import: {
title: "Importer",
desc: "Importer des paramètres depuis un fichier ou un texte.",
importFromFile: "Importer depuis un fichier",
save: "Sauvegarder",
paste: "Coller la configuration ici...",
error : {
span: "Erreur lors de l'importation de la configuration : ",
isEmpty: "la configuration est vide",
}
},
export: {
title: "Exporter",
desc: "Exporter les paramètres vers un fichier ou dans le presse-papier.",
copy: "Copier dans le presse-papier",
download: "Télécharger",
}
}
};
21 changes: 21 additions & 0 deletions plugin/i18n/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default {
noFileDeleted: "Файлы не были удалены.",
},
settings: {
exportSettings: "Export settings",
importSettings: "Import settings",
github: {
githubConfiguration: "Настройки интеграции с Github",
repoName: "Repo Name",
Expand Down Expand Up @@ -297,4 +299,23 @@ export default {
ghToken: "GitHub Token",
},
},
modals: {
import: {
title: "Import",
desc: "Import settings from text or a file.",
importFromFile: "Import from file",
save: "Save",
paste: "Paste configuration here...",
error : {
span: "Error importing configuration: ",
isEmpty: "the configuration is empty.",
}
},
export: {
title: "Export",
desc: "Export settings to clipboard or a file.",
copy: "Copy to clipboard",
download: "Download",
}
}
};
21 changes: 21 additions & 0 deletions plugin/i18n/locales/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export default {
noFileDeleted: "No files have been deleted.",
},
settings: {
exportSettings: "Export settings",
importSettings: "Import settings",
github: {
githubConfiguration: "Github设置",
repoName: "仓库名",
Expand Down Expand Up @@ -278,4 +280,23 @@ export default {
ghToken: "GitHub Token",
},
},
modals: {
import: {
title: "Import",
desc: "Import settings from text or a file.",
importFromFile: "Import from file",
save: "Save",
paste: "Paste configuration here...",
error : {
span: "Error importing configuration: ",
isEmpty: "the configuration is empty.",
}
},
export: {
title: "Export",
desc: "Export settings to clipboard or a file.",
copy: "Copy to clipboard",
download: "Download",
}
},
};
14 changes: 14 additions & 0 deletions plugin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "./commands";
import {commands, StringFunc, t, translationLanguage} from "./i18n";
import {getTitleField, regexOnFileName} from "./contents_conversion/filePathConvertor";
import {SettingValue} from "./src/modals";

/**
* Main class of the plugin
Expand All @@ -34,6 +35,15 @@ export default class GithubPublisher extends Plugin {
return regexOnFileName(getTitleField(frontmatter, file, this.settings), this.settings);
}

setSettings(settings: Record<string, SettingValue>) {
Object.keys(settings).forEach((id) => {
// @ts-ignore
this.plugin.settings[id] = settings[id];
});

this.saveSettings();
}

/**
* Create a new instance of Octokit to load a new instance of GithubBranch
*/
Expand Down Expand Up @@ -65,6 +75,8 @@ export default class GithubPublisher extends Plugin {
await convertOldSettings("ExcludedFolder", this);
await convertOldSettings("autoCleanUpExcluded", this);



this.registerEvent(
this.app.workspace.on("file-menu", (menu: Menu, file: TFile) => {
if (
Expand Down Expand Up @@ -149,6 +161,8 @@ export default class GithubPublisher extends Plugin {
);
}



this.addCommand({
id: "publisher-one",
name: commands("shareActiveFile") as string,
Expand Down
Loading

0 comments on commit 90a6f9f

Please sign in to comment.