Action

Quick Drafts

Posted by ernstwi, Last update over 1 year ago

Create a set of drafts using the current draft as input. Syntax is optimized for creating multiple tagged drafts quickly. Tag line is optional.

Example:

                                          Output
                                 ┌────────────────────────┐
          Input                  │ orange                 │
┌─────────────────────────┐      └────────────────────────┘
│ tag food, fruits        │      ┌────────────────────────┐
│                         │      │ pear                   │
│ orange                  │      └────────────────────────┘
│ pear                    │ ───► ┌────────────────────────┐
│ apple                   │      │ apple                  │
│ > some text             │      │ some text              │
│ > across multiple lines │      │ across multiple lines  │
│ banana                  │      └────────────────────────┘
└─────────────────────────┘      ┌────────────────────────┐
                                 │ banana                 │
                                 └────────────────────────┘

github.com/ernstwi/drafts-actions

Steps

  • script

    let lines = draft.lines.filter(x => x !== "");
    
    let tags = [];
    if (draft.title.startsWith('tag ')) {
        tags = draft.title.slice(4).split(',').map(x => x.trim());
        lines = lines.slice(1);
    }
    
    let items = [];
    for (let line of lines) {
        if (!line.startsWith('> ')) {
            items.push([line]);
            continue;
        }
        line = line.slice(2);
        items[items.length - 1].push(line);
    }
    
    for (let item of items) {
        let d = new Draft();
        for (let tag of tags)
            d.addTag(tag);
        d.content = item.join('\n');
        d.update();
    }

Options

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