mirror of
https://github.com/antokeinanen/obsidian-advanced-merger.git
synced 2026-07-22 07:40:24 +00:00
feat(#15): add toggle to remove YAML properties in settings
This commit is contained in:
parent
47ae3e112a
commit
f89926d69c
6 changed files with 84 additions and 57 deletions
26
src/main.ts
26
src/main.ts
|
|
@ -149,6 +149,12 @@ export default class AdvancedMerge extends Plugin {
|
||||||
`Adding folder "${folderOrFile.name}" as section "${sectionContents}" into file "${outputFileName}"..`,
|
`Adding folder "${folderOrFile.name}" as section "${sectionContents}" into file "${outputFileName}"..`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sectionContents = sectionContents.replace(
|
||||||
|
/^---\n(\w*:\s.*\n)*---/,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
|
||||||
vault.append(outputFile, sectionContents);
|
vault.append(outputFile, sectionContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -281,6 +287,26 @@ class AdvancedMergeSettingTab extends PluginSettingTab {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Add "remove yaml properties" toggle in settings
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName(this.plugin.translation.get().SettingRemoveYamlProperties)
|
||||||
|
.setDesc(
|
||||||
|
this.plugin.translation.get()
|
||||||
|
.SettingRemoveYamlPropertiesDescription,
|
||||||
|
)
|
||||||
|
.addToggle((toggle) =>
|
||||||
|
toggle
|
||||||
|
.setValue(this.plugin.settings.removeYamlProperties)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.removeYamlProperties = value;
|
||||||
|
this.plugin.settings.removeYamlProperties =
|
||||||
|
value === false
|
||||||
|
? value
|
||||||
|
: this.plugin.settings.removeYamlProperties;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
this.showIncludeFolderAsSectionSetting(containerEl);
|
this.showIncludeFolderAsSectionSetting(containerEl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,12 @@ export interface AdvancedMergePluginSettings {
|
||||||
sortMode: "alphabetical" | "creationDate" | "logical";
|
sortMode: "alphabetical" | "creationDate" | "logical";
|
||||||
includeNestedFolders: boolean;
|
includeNestedFolders: boolean;
|
||||||
includeFoldersAsSections: boolean;
|
includeFoldersAsSections: boolean;
|
||||||
|
removeYamlProperties: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: AdvancedMergePluginSettings = {
|
export const DEFAULT_SETTINGS: AdvancedMergePluginSettings = {
|
||||||
sortMode: "logical",
|
sortMode: "logical",
|
||||||
includeNestedFolders: false,
|
includeNestedFolders: false,
|
||||||
includeFoldersAsSections: false,
|
includeFoldersAsSections: false,
|
||||||
|
removeYamlProperties: false,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,13 @@ export interface Translation {
|
||||||
SettingIncludeNestedFoldersDescription: string;
|
SettingIncludeNestedFoldersDescription: string;
|
||||||
SettingIncludeFoldersAsSections: string;
|
SettingIncludeFoldersAsSections: string;
|
||||||
SettingIncludeFoldersAsSectionsDescription: string;
|
SettingIncludeFoldersAsSectionsDescription: string;
|
||||||
|
SettingRemoveYamlProperties: string;
|
||||||
|
SettingRemoveYamlPropertiesDescription: string;
|
||||||
Yes: string;
|
Yes: string;
|
||||||
No: string;
|
No: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TRANSLATIONS: { [name: string]: Translation } = {
|
export const TRANSLATIONS: Record<string, Translation> = {
|
||||||
de: {
|
de: {
|
||||||
MergeFolder: "Ordner zusammenführen",
|
MergeFolder: "Ordner zusammenführen",
|
||||||
MergedFilesuffix: "zusammengeführt",
|
MergedFilesuffix: "zusammengeführt",
|
||||||
|
|
@ -38,25 +40,32 @@ export const TRANSLATIONS: { [name: string]: Translation } = {
|
||||||
SettingSortDateCreated: "Erstellungsdatum",
|
SettingSortDateCreated: "Erstellungsdatum",
|
||||||
SettingSortLogical: "Logisch",
|
SettingSortLogical: "Logisch",
|
||||||
SettingSortAlphabetically: "Alphabetisch",
|
SettingSortAlphabetically: "Alphabetisch",
|
||||||
|
SettingRemoveYamlProperties: "YAML-Eigenschaften entfernen",
|
||||||
|
SettingRemoveYamlPropertiesDescription:
|
||||||
|
"Entfernt YAML-Eigenschaften vom Anfang der Datei während des Zusammenführens. WARNUNG: Dies könnte unbeabsichtigt nicht-YAML-Teile entfernen.",
|
||||||
},
|
},
|
||||||
en: {
|
en: {
|
||||||
MergeFolder: "Merge folder",
|
MergeFolder: "Merge folder",
|
||||||
MergedFilesuffix: "merged",
|
MergedFilesuffix: "merged",
|
||||||
OverwriteFileQuestion: "Overwite exising file",
|
OverwriteFileQuestion: "Overwrite existing file",
|
||||||
Settings: "Settings",
|
Settings: "Settings",
|
||||||
SettingIncludeNestedFolders: "Include nested folders",
|
SettingIncludeNestedFolders: "Include nested folders",
|
||||||
SettingIncludeNestedFoldersDescription:
|
SettingIncludeNestedFoldersDescription:
|
||||||
"If enabled, files in nested folders will be included in merge. Otherwise, only files in selected folder will be merged (default behaviour).",
|
"If enabled, files in nested folders will be included in the merge. Otherwise, only files in the selected folder will be merged (default behavior).",
|
||||||
SettingIncludeFoldersAsSections: "Include folders as sections",
|
SettingIncludeFoldersAsSections: "Include folders as sections",
|
||||||
SettingIncludeFoldersAsSectionsDescription:
|
SettingIncludeFoldersAsSectionsDescription:
|
||||||
"Folders will be included as named sections into output file.",
|
"Folders will be included as named sections in the output file.",
|
||||||
Yes: "Yes",
|
Yes: "Yes",
|
||||||
No: "No",
|
No: "No",
|
||||||
SettingSortMode: "Sort mode",
|
SettingSortMode: "Sort mode",
|
||||||
SettingSortModeDescription: "Pick the sorting mode for merging notes.",
|
SettingSortModeDescription:
|
||||||
|
"Choose the sorting mode for merging notes.",
|
||||||
SettingSortDateCreated: "Date created",
|
SettingSortDateCreated: "Date created",
|
||||||
SettingSortLogical: "Logical",
|
SettingSortLogical: "Logical",
|
||||||
SettingSortAlphabetically: "Alphabetical",
|
SettingSortAlphabetically: "Alphabetical",
|
||||||
|
SettingRemoveYamlProperties: "Remove YAML properties",
|
||||||
|
SettingRemoveYamlPropertiesDescription:
|
||||||
|
"Removes YAML properties from the top of the file during the merge. WARNING: This might unintentionally remove non yaml parts.",
|
||||||
},
|
},
|
||||||
fi: {
|
fi: {
|
||||||
MergeFolder: "Yhdistä kansio",
|
MergeFolder: "Yhdistä kansio",
|
||||||
|
|
@ -71,12 +80,15 @@ export const TRANSLATIONS: { [name: string]: Translation } = {
|
||||||
"Kansiot sisällytetään nimettyinä osina tulostiedostoon.",
|
"Kansiot sisällytetään nimettyinä osina tulostiedostoon.",
|
||||||
Yes: "Kyllä",
|
Yes: "Kyllä",
|
||||||
No: "Ei",
|
No: "Ei",
|
||||||
SettingSortMode: "Lajittelu järjestys",
|
SettingSortMode: "Lajittelujärjestys",
|
||||||
SettingSortModeDescription:
|
SettingSortModeDescription:
|
||||||
"Valitse lajittelutapa muistiinpanojen yhdistämistä varten.",
|
"Valitse lajittelutapa muistiinpanojen yhdistämistä varten.",
|
||||||
SettingSortDateCreated: "Luontipäivämäärä",
|
SettingSortDateCreated: "Luontipäivämäärä",
|
||||||
SettingSortLogical: "Looginen",
|
SettingSortLogical: "Looginen",
|
||||||
SettingSortAlphabetically: "Aakkosjärjestys",
|
SettingSortAlphabetically: "Aakkosjärjestys",
|
||||||
|
SettingRemoveYamlProperties: "Poista YAML-osio",
|
||||||
|
SettingRemoveYamlPropertiesDescription:
|
||||||
|
"Poistaa YAML-osio tiedoston yläosasta yhdistämisen aikana. VAROITUS: Tämä voi vahingossa poistaa ei-YAML-osia.",
|
||||||
},
|
},
|
||||||
fr: {
|
fr: {
|
||||||
MergeFolder: "Fusionner le dossier",
|
MergeFolder: "Fusionner le dossier",
|
||||||
|
|
@ -98,6 +110,9 @@ export const TRANSLATIONS: { [name: string]: Translation } = {
|
||||||
SettingSortDateCreated: "Date de création",
|
SettingSortDateCreated: "Date de création",
|
||||||
SettingSortLogical: "Logique",
|
SettingSortLogical: "Logique",
|
||||||
SettingSortAlphabetically: "Alphabétique",
|
SettingSortAlphabetically: "Alphabétique",
|
||||||
|
SettingRemoveYamlProperties: "Supprimer les propriétés YAML",
|
||||||
|
SettingRemoveYamlPropertiesDescription:
|
||||||
|
"Supprime les propriétés YAML du haut du fichier lors de la fusion. ATTENTION : Cela pourrait supprimer accidentellement des parties non YAML.",
|
||||||
},
|
},
|
||||||
ru: {
|
ru: {
|
||||||
MergeFolder: "Объединить папку",
|
MergeFolder: "Объединить папку",
|
||||||
|
|
@ -118,6 +133,9 @@ export const TRANSLATIONS: { [name: string]: Translation } = {
|
||||||
SettingSortDateCreated: "Дата создания",
|
SettingSortDateCreated: "Дата создания",
|
||||||
SettingSortLogical: "Логический",
|
SettingSortLogical: "Логический",
|
||||||
SettingSortAlphabetically: "Алфавитный указатель",
|
SettingSortAlphabetically: "Алфавитный указатель",
|
||||||
|
SettingRemoveYamlProperties: "Удалить свойства YAML",
|
||||||
|
SettingRemoveYamlPropertiesDescription:
|
||||||
|
"Удаляет свойства YAML из верхней части файла во время объединения. ВНИМАНИЕ: Это может случайно удалить не-YAML части.",
|
||||||
},
|
},
|
||||||
ua: {
|
ua: {
|
||||||
MergeFolder: "Об'єднати папку",
|
MergeFolder: "Об'єднати папку",
|
||||||
|
|
@ -138,27 +156,8 @@ export const TRANSLATIONS: { [name: string]: Translation } = {
|
||||||
SettingSortDateCreated: "Дата створення",
|
SettingSortDateCreated: "Дата створення",
|
||||||
SettingSortLogical: "Логічний",
|
SettingSortLogical: "Логічний",
|
||||||
SettingSortAlphabetically: "За алфавітом",
|
SettingSortAlphabetically: "За алфавітом",
|
||||||
|
SettingRemoveYamlProperties: "Видалити властивості YAML",
|
||||||
|
SettingRemoveYamlPropertiesDescription:
|
||||||
|
"Видаляє властивості YAML із верхньої частини файлу під час об'єднання. УВАГА: Це може випадково видалити не-YAML частини.",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
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