Tag Suggest

name

Tag Suggest

Icon

🏷

Instructions

Description:

Uses tags on current note to find other tags on other notes with those tags and suggests adding them.

To accept the suggestion, simply check the box and hit submit.

Example:

NoteX is tagged with tag1.

NoteY is tagged with tag1, tag2, tag3, tag4.

Running Tag Suggest on NoteX will suggest adding to NoteX the tags tag2, tag3, and tag4.

Select any tags to add and press submit.

Excluding Tags

You can exclude tags using the "Exclude list csv". For example, if you have evernote imports you might have thousands of notes with that tag, which would make the recommended list of tags so large it would be of no value, so you should add the path to the exclude list.






Notice: Unchecking the boxes does NOT remove the tag from the source note. They are displayed for informational purposes only.

Setting

Exclude list csv

{
async noteOption(app, noteUUID) {
/*----====----====----====----====
Get handle on current note
----====----====----====----====*/
const note = await app.notes.find(noteUUID);
/*----====----====----====----====
Get tags on current note
----====----====----====----====*/
const source_tags = note.tags;
/*----====----====----====----====
Create arrays needed
----====----====----====----====*/
var sibling_notes = [];
var tags_to_suggest = [];
var exclude_matches = [];
var exclude_list = [];
 
/*----====----====----====----====
Generate Exclude List
----====----====----====----====*/
if(app.settings["Exclude list csv"] !== undefined){
exclude_list = (app.settings["Exclude list csv"]).split(",");
/* Clean up spaces */
for(var i = 0; i < exclude_list.length; i++){
exclude_list[i] = new RegExp(exclude_list[i].trim());
}
}
 
/*----====----====----====----====
Loop through source tags on current note
----====----====----====----====*/
for(var i = 0; i < source_tags.length; i++){
/* Compare this tag to the Exclude List */
for(var m = 0; m < exclude_list.length; m++){
/* If in Exclude List then add it to the exclude array */
if(exclude_list[m].test(source_tags[i])){
exclude_matches.push(source_tags[i]);
}
}
/*----====----====----====----====
If tag is not being excluded (is included) then find all other notes with that tag
----====----====----====----====*/
if(!exclude_matches.includes(source_tags[i])){
sibling_notes = await app.filterNotes({ tag: source_tags[i] });
 
/* Loop through array of matching notes */
for(var j = 0; j < sibling_notes.length; j++){
/* Loop through tags on each note */
for(var t = 0; t < sibling_notes[j].tags.length; t++){
/* "some" function checks all objects. This returns true if there's a match. */
if(!exclude_list.some((regex) => regex.test(sibling_notes[j].tags[t]))){
/* Verify that this tag is not already in the array before adding it */
if(!tags_to_suggest.includes(sibling_notes[j].tags[t])){
tags_to_suggest.push(sibling_notes[j].tags[t]);
}
}
}
}
}
}
 
tags_to_suggest.sort();
 
/*----====----====----====----====
Call function that builds checkbox list
----====----====----====----====*/
this._getOptions(tags_to_suggest, source_tags, exclude_list).then((options)=>{
app.prompt("Tag suggestions:",{inputs: options})
.then((tags_to_add)=>{
if(tags_to_add){
for(var i = 0; i < tags_to_add.length; i++){
if(tags_to_add[i]){
note.addTag(tags_to_suggest[i]);
}
}
}
})
}).catch(err =>{
console.log(err);
})
},
 
/*----====----====----====----====
Function: Generate option checkbox list
----====----====----====----====*/
async _getOptions(tags_to_suggest, source_tags, exclude_list){
/* Returns promise */
return new Promise((resolve, reject) => {
var options = [];
var exclude_matches = [];
/* Loop through tags list */
for(var i = 0; i < tags_to_suggest.length; i++){
/* Check if tag is in exclude list */
for(var m = 0; m < exclude_list.length; m++){
/* If in exclude list then add to exclude array */
if(tags_to_suggest[i].match(exclude_list[m])){
exclude_matches.push(tags_to_suggest[i]);
}
}
/* Only enter block if tag is not in exclude list */
if(!exclude_matches.includes(tags_to_suggest[i])){
/* If tag already exists on note then checkbox must be checked already */
if(source_tags.includes(tags_to_suggest[i])){
options.push({label: tags_to_suggest[i], type: "checkbox", value: "checked"});
}else{
options.push({label: tags_to_suggest[i], type: "checkbox" });
}
}
 
}
resolve(options);
});
}
}