Drafts Action Directory

New From Template

Posted by @hinnerkhaardt, Last update 3 months ago

Creates a new document based on the selected one and opens it in the editor.

Replaces all build-in template tags in the process. Has the additional template tag „[[date]]“ that gets replaced by an iso formatted date string. Copies all tags except one „template“ and adds a new tag „generated“.

Example:

[[date]] daily journal

becomes

2018-09-15 daily journal

Install

Steps

  • script

    var dte = new Date();
    var ds = dte.toISOString().slice(0,10);
    var d = Draft.create();
    d.addTag('generated')
    d.setTemplateTag('date', ds)
    d.content = d.processTemplate(draft.content);
    d.title = d.processTemplate(draft.title);
    
    var tl = draft.tags.length;
    for (var i = 0; i < tl; i++) {
        if (draft.tags[i] !== 'template') {
            d.addTag(draft.tags[i]);
        }
    }
    
    d.update();
    editor.load(d);
    
    

Options

  • After Success Default
    Notification Info
    Log Level Info

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.