mirror of
https://github.com/mara-li/obsidian-my-thesaurus.git
synced 2026-07-22 05:38:22 +00:00
style(lint): run biome
This commit is contained in:
parent
dc2e2853e0
commit
61e0159615
6 changed files with 190 additions and 175 deletions
|
|
@ -1,77 +1,77 @@
|
|||
{
|
||||
"command": {
|
||||
"active": "Add thesaurus tags to active file",
|
||||
"all": "Parse all"
|
||||
},
|
||||
"error": {
|
||||
"csv": {
|
||||
"columns": "The columns doesn't correspond with the settings.",
|
||||
"header": "You can have only two column in your thesaurus. You have: {{- len}} columns.",
|
||||
"malformed": "Your CSV is malformed: {{- len}} columns found.",
|
||||
"separator": "The specified separator is invalid. You seems to use \"{{- sep}}\" as separator."
|
||||
},
|
||||
"file": {
|
||||
"empty": "The file {{- file}} is empty!"
|
||||
},
|
||||
"noFiles": "No files to parse found!",
|
||||
"noPath": "The path to the thesaurus is empty!",
|
||||
"noPaths": "No file paths have been included in the parameters.",
|
||||
"notFound": "The thesaurus is not found at the provided path ({{- path}})."
|
||||
},
|
||||
"modal": {
|
||||
"errors": "Errors",
|
||||
"skips": "Skipped",
|
||||
"success": "Success",
|
||||
"title": "MyThesaurus - Results"
|
||||
},
|
||||
"notice": {
|
||||
"done": "Done !",
|
||||
"loading": "Loading...",
|
||||
"start": "Start treatment..."
|
||||
},
|
||||
"settings": {
|
||||
"columns": {
|
||||
"synonyms": {
|
||||
"desc": "This value is the name of the column of words to be searched in the thesaurus.",
|
||||
"title": "Synonym"
|
||||
},
|
||||
"term": {
|
||||
"desc": "This value is the name of the tag column to be added.",
|
||||
"title": "Term"
|
||||
},
|
||||
"title": "Column title"
|
||||
},
|
||||
"includedPaths": {
|
||||
"desc": "Includes files from its paths when using the global command.",
|
||||
"regex": "Regex are supported.",
|
||||
"separate": "Separate paths with coma, semicolon, spaces or newlines.",
|
||||
"title": "Included paths"
|
||||
},
|
||||
"removeAccents": {
|
||||
"by": "like",
|
||||
"cafe": "cafe",
|
||||
"café": "café",
|
||||
"desc": "Ignores accents during recognition: helps identify",
|
||||
"title": "Remove accents",
|
||||
"viceversa": "(and vice versa)"
|
||||
},
|
||||
"separator": {
|
||||
"desc": "CSV column separator.",
|
||||
"md": "Markdown table",
|
||||
"tab": "Tabulation",
|
||||
"title": "Separator"
|
||||
},
|
||||
"thesaurusPath": {
|
||||
"desc": "Path to your CSV thesaurus (in your vault).",
|
||||
"error": "The provided file is not valide.",
|
||||
"placeholder": "mon_thesaurus.csv",
|
||||
"success": "The provided file is correct!",
|
||||
"title": "Thesaurus",
|
||||
"verify": "Verify validity of the file"
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"none": "No tag to add!",
|
||||
"title": "The tags has been added:"
|
||||
}
|
||||
}
|
||||
"command": {
|
||||
"active": "Add thesaurus tags to active file",
|
||||
"all": "Parse all"
|
||||
},
|
||||
"error": {
|
||||
"csv": {
|
||||
"columns": "The columns doesn't correspond with the settings.",
|
||||
"header": "You can have only two column in your thesaurus. You have: {{- len}} columns.",
|
||||
"malformed": "Your CSV is malformed: {{- len}} columns found.",
|
||||
"separator": "The specified separator is invalid. You seems to use \"{{- sep}}\" as separator."
|
||||
},
|
||||
"file": {
|
||||
"empty": "The file {{- file}} is empty!"
|
||||
},
|
||||
"noFiles": "No files to parse found!",
|
||||
"noPath": "The path to the thesaurus is empty!",
|
||||
"noPaths": "No file paths have been included in the parameters.",
|
||||
"notFound": "The thesaurus is not found at the provided path ({{- path}})."
|
||||
},
|
||||
"modal": {
|
||||
"errors": "Errors",
|
||||
"skips": "Skipped",
|
||||
"success": "Success",
|
||||
"title": "MyThesaurus - Results"
|
||||
},
|
||||
"notice": {
|
||||
"done": "Done !",
|
||||
"loading": "Loading...",
|
||||
"start": "Start treatment..."
|
||||
},
|
||||
"settings": {
|
||||
"columns": {
|
||||
"synonyms": {
|
||||
"desc": "This value is the name of the column of words to be searched in the thesaurus.",
|
||||
"title": "Synonym"
|
||||
},
|
||||
"term": {
|
||||
"desc": "This value is the name of the tag column to be added.",
|
||||
"title": "Term"
|
||||
},
|
||||
"title": "Column title"
|
||||
},
|
||||
"includedPaths": {
|
||||
"desc": "Includes files from its paths when using the global command.",
|
||||
"regex": "Regex are supported.",
|
||||
"separate": "Separate paths with coma, semicolon, spaces or newlines.",
|
||||
"title": "Included paths"
|
||||
},
|
||||
"removeAccents": {
|
||||
"by": "like",
|
||||
"cafe": "cafe",
|
||||
"café": "café",
|
||||
"desc": "Ignores accents during recognition: helps identify",
|
||||
"title": "Remove accents",
|
||||
"viceversa": "(and vice versa)"
|
||||
},
|
||||
"separator": {
|
||||
"desc": "CSV column separator.",
|
||||
"md": "Markdown table",
|
||||
"tab": "Tabulation",
|
||||
"title": "Separator"
|
||||
},
|
||||
"thesaurusPath": {
|
||||
"desc": "Path to your CSV thesaurus (in your vault).",
|
||||
"error": "The provided file is not valide.",
|
||||
"placeholder": "mon_thesaurus.csv",
|
||||
"success": "The provided file is correct!",
|
||||
"title": "Thesaurus",
|
||||
"verify": "Verify validity of the file"
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"none": "No tag to add!",
|
||||
"title": "The tags has been added:"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,77 +1,77 @@
|
|||
{
|
||||
"command": {
|
||||
"active": "Ajouter les tags du thésaurus au fichier actif",
|
||||
"all": "Analyser tous les fichiers"
|
||||
},
|
||||
"error": {
|
||||
"csv": {
|
||||
"columns": "Les colonnes du CSV fourni ne correspondent pas avec les colonnes des paramètres.",
|
||||
"header": "Vous ne pouvez avoir que deux colonnes dans votre thésaurus. Vous avez {{- len}} colonnes.",
|
||||
"malformed": "Votre CSV est mal formé : {{- len}} colonnes trouvées.",
|
||||
"separator": "Le séparateur spécifié n'est pas le bon. Vous semblez utiliser \"{{- sep}}\" comme séparateur."
|
||||
},
|
||||
"file": {
|
||||
"empty": "Le fichier {{- file}} est vide !"
|
||||
},
|
||||
"noFiles": "Aucun fichier n'a été trouvé !",
|
||||
"noPath": "Le chemin vers le thésaurus est vide !",
|
||||
"noPaths": "Aucun chemins de fichiers n'a été inclus dans les paramètres.",
|
||||
"notFound": "Le thésaurus est introuvable au chemin fourni ({{-path}})."
|
||||
},
|
||||
"modal": {
|
||||
"errors": "Erreurs",
|
||||
"skips": "Passés",
|
||||
"success": "Succès",
|
||||
"title": "Mon Thésaurus - Résultat"
|
||||
},
|
||||
"notice": {
|
||||
"done": "Fini !",
|
||||
"loading": "Chargement...",
|
||||
"start": "Début du traitement..."
|
||||
},
|
||||
"settings": {
|
||||
"columns": {
|
||||
"synonyms": {
|
||||
"desc": "Cette valeur est le nom de la colonne des mots à chercher dans le thésaurus.",
|
||||
"title": "Synonymes"
|
||||
},
|
||||
"term": {
|
||||
"desc": "Cette valeur est le nom de la colonne des tags à ajouter.",
|
||||
"title": "Terme"
|
||||
},
|
||||
"title": "Colonne cible"
|
||||
},
|
||||
"includedPaths": {
|
||||
"desc": "Inclus les fichiers depuis ses chemins lors d'utilisation de la commande globale.",
|
||||
"regex": "Les expressions régulières sont supportées.",
|
||||
"separate": "Séparer les chemins par une virgule, point virgule ou un retour à la ligne.",
|
||||
"title": "Chemins inclus"
|
||||
},
|
||||
"removeAccents": {
|
||||
"by": "comme",
|
||||
"cafe": "cafe",
|
||||
"café": "café",
|
||||
"desc": "Ignore les accents lors de la reconnaissance : permet d'identifier",
|
||||
"title": "Supprimer les accents",
|
||||
"viceversa": "(et inversement)"
|
||||
},
|
||||
"separator": {
|
||||
"desc": "Séparateur des colonnes du fichier CSV.",
|
||||
"md": "Markdown table",
|
||||
"tab": "Tabulation",
|
||||
"title": "Séparateur"
|
||||
},
|
||||
"thesaurusPath": {
|
||||
"desc": "Chemin vers votre thésaurus CSV (dans votre coffre).",
|
||||
"error": "Le chemin fourni n'est pas un fichier valide.",
|
||||
"placeholder": "mon_thésaurus.csv",
|
||||
"success": "Le fichier fourni est correct !",
|
||||
"title": "Thésaurus",
|
||||
"verify": "Verifier la validité du fichier"
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"none": "Aucun tag à ajouter !",
|
||||
"title": "Les tags suivants ont bien été ajoutés :"
|
||||
}
|
||||
}
|
||||
"command": {
|
||||
"active": "Ajouter les tags du thésaurus au fichier actif",
|
||||
"all": "Analyser tous les fichiers"
|
||||
},
|
||||
"error": {
|
||||
"csv": {
|
||||
"columns": "Les colonnes du CSV fourni ne correspondent pas avec les colonnes des paramètres.",
|
||||
"header": "Vous ne pouvez avoir que deux colonnes dans votre thésaurus. Vous avez {{- len}} colonnes.",
|
||||
"malformed": "Votre CSV est mal formé : {{- len}} colonnes trouvées.",
|
||||
"separator": "Le séparateur spécifié n'est pas le bon. Vous semblez utiliser \"{{- sep}}\" comme séparateur."
|
||||
},
|
||||
"file": {
|
||||
"empty": "Le fichier {{- file}} est vide !"
|
||||
},
|
||||
"noFiles": "Aucun fichier n'a été trouvé !",
|
||||
"noPath": "Le chemin vers le thésaurus est vide !",
|
||||
"noPaths": "Aucun chemins de fichiers n'a été inclus dans les paramètres.",
|
||||
"notFound": "Le thésaurus est introuvable au chemin fourni ({{-path}})."
|
||||
},
|
||||
"modal": {
|
||||
"errors": "Erreurs",
|
||||
"skips": "Passés",
|
||||
"success": "Succès",
|
||||
"title": "Mon Thésaurus - Résultat"
|
||||
},
|
||||
"notice": {
|
||||
"done": "Fini !",
|
||||
"loading": "Chargement...",
|
||||
"start": "Début du traitement..."
|
||||
},
|
||||
"settings": {
|
||||
"columns": {
|
||||
"synonyms": {
|
||||
"desc": "Cette valeur est le nom de la colonne des mots à chercher dans le thésaurus.",
|
||||
"title": "Synonymes"
|
||||
},
|
||||
"term": {
|
||||
"desc": "Cette valeur est le nom de la colonne des tags à ajouter.",
|
||||
"title": "Terme"
|
||||
},
|
||||
"title": "Colonne cible"
|
||||
},
|
||||
"includedPaths": {
|
||||
"desc": "Inclus les fichiers depuis ses chemins lors d'utilisation de la commande globale.",
|
||||
"regex": "Les expressions régulières sont supportées.",
|
||||
"separate": "Séparer les chemins par une virgule, point virgule ou un retour à la ligne.",
|
||||
"title": "Chemins inclus"
|
||||
},
|
||||
"removeAccents": {
|
||||
"by": "comme",
|
||||
"cafe": "cafe",
|
||||
"café": "café",
|
||||
"desc": "Ignore les accents lors de la reconnaissance : permet d'identifier",
|
||||
"title": "Supprimer les accents",
|
||||
"viceversa": "(et inversement)"
|
||||
},
|
||||
"separator": {
|
||||
"desc": "Séparateur des colonnes du fichier CSV.",
|
||||
"md": "Markdown table",
|
||||
"tab": "Tabulation",
|
||||
"title": "Séparateur"
|
||||
},
|
||||
"thesaurusPath": {
|
||||
"desc": "Chemin vers votre thésaurus CSV (dans votre coffre).",
|
||||
"error": "Le chemin fourni n'est pas un fichier valide.",
|
||||
"placeholder": "mon_thésaurus.csv",
|
||||
"success": "Le fichier fourni est correct !",
|
||||
"title": "Thésaurus",
|
||||
"verify": "Verifier la validité du fichier"
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"none": "Aucun tag à ajouter !",
|
||||
"title": "Les tags suivants ont bien été ajoutés :"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
src/main.ts
23
src/main.ts
|
|
@ -1,5 +1,12 @@
|
|||
import i18next from "i18next";
|
||||
import {Notice, Plugin, TFile, getFrontMatterInfo, sanitizeHTMLToDom, type FrontMatterCache} from "obsidian";
|
||||
import {
|
||||
Notice,
|
||||
Plugin,
|
||||
TFile,
|
||||
getFrontMatterInfo,
|
||||
sanitizeHTMLToDom,
|
||||
type FrontMatterCache,
|
||||
} from "obsidian";
|
||||
import { resources, translationLanguage } from "./i18n";
|
||||
import {
|
||||
DEFAULT_SETTINGS,
|
||||
|
|
@ -15,18 +22,16 @@ import { getTags, getThesaurus } from "./utils";
|
|||
|
||||
export default class MyThesaurus extends Plugin {
|
||||
settings!: MyThesaurusSettings;
|
||||
|
||||
|
||||
getTagAsArray(tag: string | string[]) {
|
||||
if (!Array.isArray(tag)) return [tag];
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
getFileTags(frontmatter: FrontMatterCache) {
|
||||
const tags = [];
|
||||
if (frontmatter.tags)
|
||||
tags.push(...this.getTagAsArray(frontmatter.tags));
|
||||
if (frontmatter.tag)
|
||||
tags.push(...this.getTagAsArray(frontmatter.tag));
|
||||
if (frontmatter.tags) tags.push(...this.getTagAsArray(frontmatter.tags));
|
||||
if (frontmatter.tag) tags.push(...this.getTagAsArray(frontmatter.tag));
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +69,9 @@ export default class MyThesaurus extends Plugin {
|
|||
};
|
||||
}
|
||||
try {
|
||||
const tags = getTags(contents, thesaurus, this.settings.removeAccents).concat(...getTags(file.basename, thesaurus, this.settings.removeAccents));
|
||||
const tags = getTags(contents, thesaurus, this.settings.removeAccents).concat(
|
||||
...getTags(file.basename, thesaurus, this.settings.removeAccents)
|
||||
);
|
||||
if (tags.length > 0) {
|
||||
await this.addTagsToNote(tags, file);
|
||||
const successMsg = sanitizeHTMLToDom(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export class MyThesaurusSettingTab extends PluginSettingTab {
|
|||
|
||||
containerEl.empty();
|
||||
|
||||
const thesaurusSetting = new Setting(containerEl)
|
||||
const thesaurusSetting = new Setting(containerEl)
|
||||
.setHeading()
|
||||
.setName(i18next.t("settings.thesaurusPath.title"))
|
||||
.setDesc(i18next.t("settings.thesaurusPath.desc"))
|
||||
|
|
@ -89,7 +89,7 @@ export class MyThesaurusSettingTab extends PluginSettingTab {
|
|||
});
|
||||
});
|
||||
if (this.isInvalid) thesaurusSetting.setClass("is-invalid");
|
||||
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.separator.title"))
|
||||
.setDesc(i18next.t("settings.separator.desc"))
|
||||
|
|
@ -141,23 +141,28 @@ export class MyThesaurusSettingTab extends PluginSettingTab {
|
|||
.addTextArea((text) => {
|
||||
text
|
||||
.setPlaceholder(".*")
|
||||
.setValue(this.settings.includedPaths.join("\n")).onChange(async (value) => {
|
||||
this.settings.includedPaths = value
|
||||
.split(/[\n,;]+/)
|
||||
.map((path) => path.trim())
|
||||
.filter((path) => path.length > 0);
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
.setValue(this.settings.includedPaths.join("\n"))
|
||||
.onChange(async (value) => {
|
||||
this.settings.includedPaths = value
|
||||
.split(/[\n,;]+/)
|
||||
.map((path) => path.trim())
|
||||
.filter((path) => path.length > 0);
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18next.t("settings.removeAccents.title"))
|
||||
.setDesc(sanitizeHTMLToDom(`${i18next.t("settings.removeAccents.desc")}<code>"${i18next.t("settings.removeAccents.café")}"</code>${i18next.t("settings.removeAccents.by")}<code>"${i18next.t("settings.removeAccents.cafe")}"</code>${i18next.t("settings.removeAccents.viceversa")}.`))
|
||||
.setDesc(
|
||||
sanitizeHTMLToDom(
|
||||
`${i18next.t("settings.removeAccents.desc")}<code>"${i18next.t("settings.removeAccents.café")}"</code>${i18next.t("settings.removeAccents.by")}<code>"${i18next.t("settings.removeAccents.cafe")}"</code>${i18next.t("settings.removeAccents.viceversa")}.`
|
||||
)
|
||||
)
|
||||
.addToggle((toggle) => {
|
||||
toggle.setValue(this.settings.removeAccents).onChange(async (value) => {
|
||||
this.settings.removeAccents = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,8 +75,7 @@ export function getThesaurus(
|
|||
let synonyms = columns[indexSynonyms].trim();
|
||||
if (standardize) synonyms = synonyms.standardize();
|
||||
if (key !== "" && synonyms !== "") {
|
||||
if (thesaurus[key] === undefined)
|
||||
thesaurus[key] = new Set();
|
||||
if (thesaurus[key] === undefined) thesaurus[key] = new Set();
|
||||
thesaurus[key].add(synonyms);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
import type { Thesaurus } from "../interfaces";
|
||||
|
||||
export function getTags(content: string, thesaurus: Thesaurus, standardize?: boolean): string[] {
|
||||
export function getTags(
|
||||
content: string,
|
||||
thesaurus: Thesaurus,
|
||||
standardize?: boolean
|
||||
): string[] {
|
||||
const tagsToAdd: string[] = [];
|
||||
if (standardize) content = content.standardize();
|
||||
for (const tags of Object.keys(thesaurus)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue