mirror of
https://github.com/antokeinanen/obsidian-advanced-merger.git
synced 2026-07-22 07:40:24 +00:00
ref: split the code into nice chunks
This commit is contained in:
parent
98fc18ffcc
commit
d7f370945a
5 changed files with 200 additions and 223 deletions
|
|
@ -14,7 +14,7 @@ const context = await esbuild.context({
|
|||
banner: {
|
||||
js: banner,
|
||||
},
|
||||
entryPoints: ["main.ts"],
|
||||
entryPoints: ["src/main.ts"],
|
||||
bundle: true,
|
||||
external: [
|
||||
"obsidian",
|
||||
|
|
@ -38,7 +38,7 @@ const context = await esbuild.context({
|
|||
sourcemap: prod ? false : "inline",
|
||||
treeShaking: true,
|
||||
minify: true,
|
||||
outfile: "main.js",
|
||||
outfile: prod ? "main.js" : "../advanced-merger.js",
|
||||
});
|
||||
|
||||
if (prod) {
|
||||
|
|
|
|||
8
src/constants.ts
Normal file
8
src/constants.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
export const ICON_NAME = "git-merge";
|
||||
export const PLUGIN_NAME = "Advanced Merger";
|
||||
export const DEFAULT_LANGUAGE = "en";
|
||||
export const HANDLER_LOCATION = "file-menu";
|
||||
export const NEW_LINE_CHAR = "\n";
|
||||
export const DOUBLE_NEW_LINE_CHAR = "\n\n";
|
||||
export const SECTION_CHAR = "#";
|
||||
export const MARKDOWN_FILE_EXTENSION = "md";
|
||||
|
|
@ -9,205 +9,17 @@ import {
|
|||
TFolder,
|
||||
Vault,
|
||||
} from "obsidian";
|
||||
|
||||
interface Translation {
|
||||
MergeFolder: string;
|
||||
MergedFilesuffix: string;
|
||||
OverwriteFileQuestion: string;
|
||||
Settings: string;
|
||||
SettingSortMode: string;
|
||||
SettingSortModeDescription: string;
|
||||
SettingSortAlphabetically: string;
|
||||
SettingSortDateCreated: string;
|
||||
SettingSortLogical: string;
|
||||
SettingIncludeNestedFolders: string;
|
||||
SettingIncludeNestedFoldersDescription: string;
|
||||
SettingIncludeFoldersAsSections: string;
|
||||
SettingIncludeFoldersAsSectionsDescription: string;
|
||||
Yes: string;
|
||||
No: string;
|
||||
}
|
||||
|
||||
const TRANSLATIONS: { [name: string]: Translation } = {
|
||||
de: {
|
||||
MergeFolder: "Ordner zusammenführen",
|
||||
MergedFilesuffix: "zusammengeführt",
|
||||
OverwriteFileQuestion: "Vorhandene Datei überschreiben",
|
||||
Settings: "Einstellungen",
|
||||
SettingIncludeNestedFolders: "Verschachtelte Ordner einbeziehen",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Wenn aktiviert, werden Dateien in verschachtelten Ordnern zusammengeführt. Andernfalls werden nur Dateien im ausgewählten Ordner zusammengeführt (Standardverhalten).",
|
||||
SettingIncludeFoldersAsSections: "Ordner als Abschnitte einbeziehen",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Ordner werden als benannte Abschnitte in die Ausgabedatei eingefügt.",
|
||||
Yes: "Ja",
|
||||
No: "Nein",
|
||||
SettingSortMode: "Sortiermodus",
|
||||
SettingSortModeDescription:
|
||||
"Wählen Sie den Sortiermodus für das Zusammenführen von Notizen.",
|
||||
SettingSortDateCreated: "Erstellungsdatum",
|
||||
SettingSortLogical: "Logisch",
|
||||
SettingSortAlphabetically: "Alphabetisch",
|
||||
},
|
||||
en: {
|
||||
MergeFolder: "Merge folder",
|
||||
MergedFilesuffix: "merged",
|
||||
OverwriteFileQuestion: "Overwite exising file",
|
||||
Settings: "Settings",
|
||||
SettingIncludeNestedFolders: "Include nested folders",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"If enabled, files in nested folders will be included in merge. Otherwise, only files in selected folder will be merged (default behaviour).",
|
||||
SettingIncludeFoldersAsSections: "Include folders as sections",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Folders will be included as named sections into output file.",
|
||||
Yes: "Yes",
|
||||
No: "No",
|
||||
SettingSortMode: "Sort mode",
|
||||
SettingSortModeDescription: "Pick the sorting mode for merging notes.",
|
||||
SettingSortDateCreated: "Date created",
|
||||
SettingSortLogical: "Logical",
|
||||
SettingSortAlphabetically: "Alphabetical",
|
||||
},
|
||||
fi: {
|
||||
MergeFolder: "Yhdistä kansio",
|
||||
MergedFilesuffix: "yhdistetty",
|
||||
OverwriteFileQuestion: "Korvaa olemassa oleva tiedosto",
|
||||
Settings: "Asetukset",
|
||||
SettingIncludeNestedFolders: "Sisällytä sisäkkäiset kansiot",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Jos käytössä, sisäkkäisten kansioiden tiedostot yhdistetään. Muussa tapauksessa vain valitun kansion tiedostot yhdistetään (oletustoiminto).",
|
||||
SettingIncludeFoldersAsSections: "Sisällytä kansiot osioihin",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Kansiot sisällytetään nimettyinä osina tulostiedostoon.",
|
||||
Yes: "Kyllä",
|
||||
No: "Ei",
|
||||
SettingSortMode: "Lajittelu järjestys",
|
||||
SettingSortModeDescription:
|
||||
"Valitse lajittelutapa muistiinpanojen yhdistämistä varten.",
|
||||
SettingSortDateCreated: "Luontipäivämäärä",
|
||||
SettingSortLogical: "Looginen",
|
||||
SettingSortAlphabetically: "Aakkosjärjestys",
|
||||
},
|
||||
fr: {
|
||||
MergeFolder: "Fusionner le dossier",
|
||||
MergedFilesuffix: "fusionné",
|
||||
OverwriteFileQuestion: "Remplacer le fichier existant",
|
||||
Settings: "Paramètres",
|
||||
SettingIncludeNestedFolders: "Inclure les dossiers imbriqués",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Si activé, les fichiers des dossiers imbriqués seront inclus dans la fusion. Sinon, seuls les fichiers du dossier sélectionné seront fusionnés (comportement par défaut).",
|
||||
SettingIncludeFoldersAsSections:
|
||||
"Inclure les dossiers en tant que sections",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Les dossiers seront inclus en tant que sections nommées dans le fichier de sortie.",
|
||||
Yes: "Oui",
|
||||
No: "Non",
|
||||
SettingSortMode: "mode de tri",
|
||||
SettingSortModeDescription:
|
||||
"Choisissez le mode de tri pour la fusion des notes.",
|
||||
SettingSortDateCreated: "Date de création",
|
||||
SettingSortLogical: "Logique",
|
||||
SettingSortAlphabetically: "Alphabétique",
|
||||
},
|
||||
ru: {
|
||||
MergeFolder: "Объединить папку",
|
||||
MergedFilesuffix: "совмещенный",
|
||||
OverwriteFileQuestion: "Перезаписать существующий файл",
|
||||
Settings: "Настройки",
|
||||
SettingIncludeNestedFolders: "Влючать вложенные папки",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Если включено, файлы во вложенных папках будут включены в слияние. В противном случае будут объединены только файлы в выбранной папке (поведение по умолчанию).",
|
||||
SettingIncludeFoldersAsSections: "Включать папки как разделы",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Папки будут включены в выходной файл в качестве разделов.",
|
||||
Yes: "Да",
|
||||
No: "Нет",
|
||||
SettingSortMode: "режим сортировки",
|
||||
SettingSortModeDescription:
|
||||
"Выберите режим сортировки при объединении заметок.",
|
||||
SettingSortDateCreated: "Дата создания",
|
||||
SettingSortLogical: "Логический",
|
||||
SettingSortAlphabetically: "Алфавитный указатель",
|
||||
},
|
||||
ua: {
|
||||
MergeFolder: "Об'єднати папку",
|
||||
MergedFilesuffix: "об'єднані",
|
||||
OverwriteFileQuestion: "Перезаписати існуючий файл",
|
||||
Settings: "Налаштування",
|
||||
SettingIncludeNestedFolders: "Включити вкладені папки",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Якщо ввімкнено, файли у вкладених папках будуть включені в об’єднання. В іншому випадку буде об’єднано лише файли у вибраній папці (поведінка за замовчуванням).",
|
||||
SettingIncludeFoldersAsSections: "Включити папки як розділи",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Папки будуть включені як іменовані розділи у вихідний файл.",
|
||||
Yes: "Так",
|
||||
No: "Ні",
|
||||
SettingSortMode: "Логический",
|
||||
SettingSortModeDescription:
|
||||
"Виберіть режим сортування для об'єднання нотаток.",
|
||||
SettingSortDateCreated: "Дата створення",
|
||||
SettingSortLogical: "Логічний",
|
||||
SettingSortAlphabetically: "За алфавітом",
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Enum representing the available sorting options for merging notes.
|
||||
* If you add a new option, make sure to add it to the settings in 'AdvancedMergeSettingTab.display'.
|
||||
*/
|
||||
|
||||
interface AdvancedMergePluginSettings {
|
||||
sortMode: "alphabetical" | "creationDate" | "logical";
|
||||
includeNestedFolders: boolean;
|
||||
includeFoldersAsSections: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS: AdvancedMergePluginSettings = {
|
||||
sortMode: "logical",
|
||||
includeNestedFolders: false,
|
||||
includeFoldersAsSections: false,
|
||||
};
|
||||
|
||||
/** @constant
|
||||
@type {string}
|
||||
@default
|
||||
*/
|
||||
const ICON_NAME = "git-merge";
|
||||
/** @constant
|
||||
@type {string}
|
||||
@default
|
||||
*/
|
||||
const PLUGIN_NAME = "Advanced Merger";
|
||||
/** @constant
|
||||
@type {string}
|
||||
@default
|
||||
*/
|
||||
const DEFAULT_LANGUAGE = "en";
|
||||
/** @constant
|
||||
@type {string}
|
||||
@default
|
||||
*/
|
||||
const HANDLER_LOCATION = "file-menu";
|
||||
/** @constant
|
||||
@type {string}
|
||||
@default
|
||||
*/
|
||||
const NEW_LINE_CHAR = "\n";
|
||||
/** @constant
|
||||
@type {string}
|
||||
@default
|
||||
*/
|
||||
const DOUBLE_NEW_LINE_CHAR = "\n\n";
|
||||
/** @constant
|
||||
@type {string}
|
||||
@default
|
||||
*/
|
||||
const SECTION_CHAR = "#";
|
||||
/** @constant
|
||||
@type {string}
|
||||
@default
|
||||
*/
|
||||
const MARKDOWN_FILE_EXTENSION = "md";
|
||||
import { AdvancedMergePluginSettings, DEFAULT_SETTINGS } from "./settings";
|
||||
import {
|
||||
DOUBLE_NEW_LINE_CHAR,
|
||||
HANDLER_LOCATION,
|
||||
ICON_NAME,
|
||||
MARKDOWN_FILE_EXTENSION,
|
||||
NEW_LINE_CHAR,
|
||||
PLUGIN_NAME,
|
||||
SECTION_CHAR,
|
||||
} from "./constants";
|
||||
import { AdvancedMergeTranslation } from "./translation";
|
||||
|
||||
export default class AdvancedMerge extends Plugin {
|
||||
public translation: AdvancedMergeTranslation;
|
||||
|
|
@ -561,25 +373,3 @@ class AdvancedMergeOverwriteFileModal extends Modal {
|
|||
contentEl.empty();
|
||||
}
|
||||
}
|
||||
|
||||
class AdvancedMergeTranslation {
|
||||
private language: string;
|
||||
|
||||
/**
|
||||
* Represents a plugin translation.
|
||||
* @constructor
|
||||
*/
|
||||
constructor() {
|
||||
this.language = !Object.keys(TRANSLATIONS).contains(navigator.language)
|
||||
? DEFAULT_LANGUAGE
|
||||
: navigator.language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets translation object for current language.
|
||||
* @returns {Translation} Current translation object.
|
||||
*/
|
||||
public get(): Translation {
|
||||
return TRANSLATIONS[this.language];
|
||||
}
|
||||
}
|
||||
15
src/settings.ts
Normal file
15
src/settings.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* Enum representing the available sorting options for merging notes.
|
||||
* If you add a new option, make sure to add it to the settings in 'AdvancedMergeSettingTab.display'.
|
||||
*/
|
||||
export interface AdvancedMergePluginSettings {
|
||||
sortMode: "alphabetical" | "creationDate" | "logical";
|
||||
includeNestedFolders: boolean;
|
||||
includeFoldersAsSections: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: AdvancedMergePluginSettings = {
|
||||
sortMode: "logical",
|
||||
includeNestedFolders: false,
|
||||
includeFoldersAsSections: false,
|
||||
};
|
||||
164
src/translation.ts
Normal file
164
src/translation.ts
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
import { DEFAULT_LANGUAGE } from "./constants";
|
||||
|
||||
export interface Translation {
|
||||
MergeFolder: string;
|
||||
MergedFilesuffix: string;
|
||||
OverwriteFileQuestion: string;
|
||||
Settings: string;
|
||||
SettingSortMode: string;
|
||||
SettingSortModeDescription: string;
|
||||
SettingSortAlphabetically: string;
|
||||
SettingSortDateCreated: string;
|
||||
SettingSortLogical: string;
|
||||
SettingIncludeNestedFolders: string;
|
||||
SettingIncludeNestedFoldersDescription: string;
|
||||
SettingIncludeFoldersAsSections: string;
|
||||
SettingIncludeFoldersAsSectionsDescription: string;
|
||||
Yes: string;
|
||||
No: string;
|
||||
}
|
||||
|
||||
export const TRANSLATIONS: { [name: string]: Translation } = {
|
||||
de: {
|
||||
MergeFolder: "Ordner zusammenführen",
|
||||
MergedFilesuffix: "zusammengeführt",
|
||||
OverwriteFileQuestion: "Vorhandene Datei überschreiben",
|
||||
Settings: "Einstellungen",
|
||||
SettingIncludeNestedFolders: "Verschachtelte Ordner einbeziehen",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Wenn aktiviert, werden Dateien in verschachtelten Ordnern zusammengeführt. Andernfalls werden nur Dateien im ausgewählten Ordner zusammengeführt (Standardverhalten).",
|
||||
SettingIncludeFoldersAsSections: "Ordner als Abschnitte einbeziehen",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Ordner werden als benannte Abschnitte in die Ausgabedatei eingefügt.",
|
||||
Yes: "Ja",
|
||||
No: "Nein",
|
||||
SettingSortMode: "Sortiermodus",
|
||||
SettingSortModeDescription:
|
||||
"Wählen Sie den Sortiermodus für das Zusammenführen von Notizen.",
|
||||
SettingSortDateCreated: "Erstellungsdatum",
|
||||
SettingSortLogical: "Logisch",
|
||||
SettingSortAlphabetically: "Alphabetisch",
|
||||
},
|
||||
en: {
|
||||
MergeFolder: "Merge folder",
|
||||
MergedFilesuffix: "merged",
|
||||
OverwriteFileQuestion: "Overwite exising file",
|
||||
Settings: "Settings",
|
||||
SettingIncludeNestedFolders: "Include nested folders",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"If enabled, files in nested folders will be included in merge. Otherwise, only files in selected folder will be merged (default behaviour).",
|
||||
SettingIncludeFoldersAsSections: "Include folders as sections",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Folders will be included as named sections into output file.",
|
||||
Yes: "Yes",
|
||||
No: "No",
|
||||
SettingSortMode: "Sort mode",
|
||||
SettingSortModeDescription: "Pick the sorting mode for merging notes.",
|
||||
SettingSortDateCreated: "Date created",
|
||||
SettingSortLogical: "Logical",
|
||||
SettingSortAlphabetically: "Alphabetical",
|
||||
},
|
||||
fi: {
|
||||
MergeFolder: "Yhdistä kansio",
|
||||
MergedFilesuffix: "yhdistetty",
|
||||
OverwriteFileQuestion: "Korvaa olemassa oleva tiedosto",
|
||||
Settings: "Asetukset",
|
||||
SettingIncludeNestedFolders: "Sisällytä sisäkkäiset kansiot",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Jos käytössä, sisäkkäisten kansioiden tiedostot yhdistetään. Muussa tapauksessa vain valitun kansion tiedostot yhdistetään (oletustoiminto).",
|
||||
SettingIncludeFoldersAsSections: "Sisällytä kansiot osioihin",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Kansiot sisällytetään nimettyinä osina tulostiedostoon.",
|
||||
Yes: "Kyllä",
|
||||
No: "Ei",
|
||||
SettingSortMode: "Lajittelu järjestys",
|
||||
SettingSortModeDescription:
|
||||
"Valitse lajittelutapa muistiinpanojen yhdistämistä varten.",
|
||||
SettingSortDateCreated: "Luontipäivämäärä",
|
||||
SettingSortLogical: "Looginen",
|
||||
SettingSortAlphabetically: "Aakkosjärjestys",
|
||||
},
|
||||
fr: {
|
||||
MergeFolder: "Fusionner le dossier",
|
||||
MergedFilesuffix: "fusionné",
|
||||
OverwriteFileQuestion: "Remplacer le fichier existant",
|
||||
Settings: "Paramètres",
|
||||
SettingIncludeNestedFolders: "Inclure les dossiers imbriqués",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Si activé, les fichiers des dossiers imbriqués seront inclus dans la fusion. Sinon, seuls les fichiers du dossier sélectionné seront fusionnés (comportement par défaut).",
|
||||
SettingIncludeFoldersAsSections:
|
||||
"Inclure les dossiers en tant que sections",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Les dossiers seront inclus en tant que sections nommées dans le fichier de sortie.",
|
||||
Yes: "Oui",
|
||||
No: "Non",
|
||||
SettingSortMode: "mode de tri",
|
||||
SettingSortModeDescription:
|
||||
"Choisissez le mode de tri pour la fusion des notes.",
|
||||
SettingSortDateCreated: "Date de création",
|
||||
SettingSortLogical: "Logique",
|
||||
SettingSortAlphabetically: "Alphabétique",
|
||||
},
|
||||
ru: {
|
||||
MergeFolder: "Объединить папку",
|
||||
MergedFilesuffix: "совмещенный",
|
||||
OverwriteFileQuestion: "Перезаписать существующий файл",
|
||||
Settings: "Настройки",
|
||||
SettingIncludeNestedFolders: "Влючать вложенные папки",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Если включено, файлы во вложенных папках будут включены в слияние. В противном случае будут объединены только файлы в выбранной папке (поведение по умолчанию).",
|
||||
SettingIncludeFoldersAsSections: "Включать папки как разделы",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Папки будут включены в выходной файл в качестве разделов.",
|
||||
Yes: "Да",
|
||||
No: "Нет",
|
||||
SettingSortMode: "режим сортировки",
|
||||
SettingSortModeDescription:
|
||||
"Выберите режим сортировки при объединении заметок.",
|
||||
SettingSortDateCreated: "Дата создания",
|
||||
SettingSortLogical: "Логический",
|
||||
SettingSortAlphabetically: "Алфавитный указатель",
|
||||
},
|
||||
ua: {
|
||||
MergeFolder: "Об'єднати папку",
|
||||
MergedFilesuffix: "об'єднані",
|
||||
OverwriteFileQuestion: "Перезаписати існуючий файл",
|
||||
Settings: "Налаштування",
|
||||
SettingIncludeNestedFolders: "Включити вкладені папки",
|
||||
SettingIncludeNestedFoldersDescription:
|
||||
"Якщо ввімкнено, файли у вкладених папках будуть включені в об’єднання. В іншому випадку буде об’єднано лише файли у вибраній папці (поведінка за замовчуванням).",
|
||||
SettingIncludeFoldersAsSections: "Включити папки як розділи",
|
||||
SettingIncludeFoldersAsSectionsDescription:
|
||||
"Папки будуть включені як іменовані розділи у вихідний файл.",
|
||||
Yes: "Так",
|
||||
No: "Ні",
|
||||
SettingSortMode: "Логический",
|
||||
SettingSortModeDescription:
|
||||
"Виберіть режим сортування для об'єднання нотаток.",
|
||||
SettingSortDateCreated: "Дата створення",
|
||||
SettingSortLogical: "Логічний",
|
||||
SettingSortAlphabetically: "За алфавітом",
|
||||
},
|
||||
};
|
||||
|
||||
export class AdvancedMergeTranslation {
|
||||
private language: string;
|
||||
|
||||
/**
|
||||
* Represents a plugin translation.
|
||||
* @constructor
|
||||
*/
|
||||
constructor() {
|
||||
this.language = !Object.keys(TRANSLATIONS).contains(navigator.language)
|
||||
? DEFAULT_LANGUAGE
|
||||
: navigator.language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets translation object for current language.
|
||||
* @returns {Translation} Current translation object.
|
||||
*/
|
||||
public get(): Translation {
|
||||
return TRANSLATIONS[this.language];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue