New Note Inheriting Tags

name

New Note Inheriting Tags

Description

Creates a new note tagged with the tags from the note you currently have selected.

Each new note created can include a link back to the source note from which it came.

The link back can be contained in a task or as regular text.

2024-07-31 Updates:
Added options to ignore date tags and daily-jots tags.
Hard-coded ignoring "auto-archived" tag because that is a system generated tag and should not be applied manually.

Keywords: Inherit, auto tag

Icon

🟢

Setting

Link back (YES/no)

Setting

Link as TASK or text

Setting

Link prefix

Setting

Include dates (yes/NO)

Setting

Include daily-jots (yes/NO)

{
async noteOption(app, noteUUID) {
const note = await app.notes.find(noteUUID);
const title = note.name;
const tags = note.tags;
 
/*REMOVE AUTO-ARCHIVED TAG*/
for(let i = 0; i < tags.length; i++){
if(tags[i] == 'auto-archived'){
tags.splice(i,1);
}
}
/*GET INCLUDE DAILY-JOTS SETTING*/
var include_dailyjots = app.settings['Include daily-jots (yes/NO)'] || 'no';
var include_dailyjots = include_dailyjots.trim().toLowerCase() || 'no';
/*IF NOT INCLUDING DAILY-JOTS THEN REMOVE IT FROM THE TAGS ARRAY*/
if(include_dailyjots == 'no'){
for(let i = 0; i < tags.length; i++){
if(tags[i] == 'daily-jots'){
tags.splice(i,1);
}
}
}
 
/*GET IGNORE DATES SETTING*/
var include_dates = app.settings['Include dates (yes/NO)'] || 'no';
var include_dates = include_dates.trim().toLowerCase() || 'no';
/*IF NOT INCLUDING DATES THEN REMOVE IT FROM THE TAGS ARRAY*/
for(let i = 0; i < tags.length; i++){
if(include_dates == 'no'){
var today = new Date();
var tag = new Date(tags[i]);
var diff = (today.getTime() - tag.getTime()) / (24*60*60*1000);
//console.log(diff + " is: " + typeof(diff));
if(!isNaN(diff)){
tags.splice(i,1);
}
}
}
 
const new_uuid = await app.createNote("", tags);
const newnote = await app.notes.find(new_uuid);
 
var include_source = app.settings['Link back (YES/no)'] || 'yes';
var include_source = include_source.trim().toLowerCase() || 'yes';
 
var link_prefix = app.settings['Link prefix'] || '';
 
/* Boil down choice to a yes */
var yes_list = ['yes', 'y', '1', 'true', 't'];
if(yes_list.includes(include_source)){
include_source = true;
}else{
include_source = false;
}
 
 
/* Create link back to original note */
if(include_source){
/* Assemble markdown link */
const link_text = link_prefix + "[" + title + "](https://www.amplenote.com/notes/" + noteUUID + ")";
 
/* User can choose to have link back placed in a task or as regular text */
var link_task_or_text = app.settings['Link as TASK or text'] || 'task';
link_task_or_text = link_task_or_text.trim().toLowerCase();
 
if(link_task_or_text == "text"){
newnote.insertContent(link_text);
}else if(link_task_or_text == "task"){
const taskUUID = await newnote.insertTask({ content: link_text });
}else{
/* Give feedback to user to correct settings. */
app.alert('When "Link back (yes/no)" is true, "Link as task or text" must be set to "task" or "text".');
}
}
 
/* Bring user to the new note */
app.navigate("https://www.amplenote.com/notes/" + new_uuid);
}
}