Action

Archiver @done

Posted by sylumer, Last update over 1 year ago - Unlisted

Move any lines marked as @done to an “Archive” project at the end of the draft, creating that archive if it does not already exist.

Modified to work on draft rather than editor.

Steps

  • script

    // constants
    const archiveLabel = "Archive:";
    const reLine = /^[\t| ]*?- /;
    const re = /@done(\(.*\))?/;
    
    let sections = draft.content.split(archiveLabel);
    let lines = sections[0].split("\n");
    let archivedLines = [];
    if (sections.length > 1) {
    	archivedLines = sections[1].split("\n");
    }
    let newLines = [];
    
    for (let line of lines) {
    	if (!line.match(reLine)) { // not a task
    		newLines.push(line);
    		continue;
    	}
    	if (line.match(re)) { // done, move it
    		archivedLines.push(line);
    	}
    	else { // not done, leave it
    		newLines.push(line);
    	}
    }
    
    let newText = newLines.join("\n").trim();
    if (archivedLines.length > 0) {
    	newText = newText + `\n\n${archiveLabel}\n` + archivedLines.join("\n").trim();
    }
    draft.content = newText;
    draft.update();

Options

  • After Success Default
    Notification Info
    Log Level None
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.