Save Post Draft

Posted by nahumck, Last update 9 months ago - Unlisted

Saves a post to the /Drafts 5/Draft Posts/ folder in iCloud Drive. Use this in conjunction with the Load Post Draft action for a file management system for posts. Requires Drafts 5.6.

Steps

  • script

    /* ------Functions------ */
    
    // Title Case Function
    
    String.prototype.toTitleCase = function(){
      var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;
     
      return this.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, index, title){
        if (index > 0 && index + match.length !== title.length &&
          match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
          (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &&
          title.charAt(index - 1).search(/[^\s-]/) < 0) {
          return match.toLowerCase();
        }
        if (match.substr(1).search(/[A-Z]|\../) > -1) {
          return match;
        }
        return match.charAt(0).toUpperCase() + match.substr(1);
      });
    };
    
    /* --- Title --- */
    var t = draft.title;
    // need to search for matches within brackets somehow.
    t = t.replace(/# /g, "");
    var titleRegex = new RegExp(/\[(.*?)\]/);
    var check = t.match(titleRegex);
    if (check) {
    	t = check[1]
    }
    var postTitle = t.toTitleCase();
    draft.setTemplateTag("postTitle",postTitle)
    
    
  • file

    fileNameTemplate
    [[postTitle]].md
    folderTemplate
    /Draft Posts/
    template
    [[draft]]
    local
    false
    writeType
    replace

Options

  • After Success Trash
    Notification Info
    Log Level Error
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.