Load Draft Post

Posted by nahumck, Last update 9 months ago - Unlisted

Loads a selected draft into a Writing module. Requires Drafts 5.6.

Steps

  • script

    // Import draft post
    
    let root = "Draft Posts/";
    let fmCloud = FileManager.createCloud();
    let fileNames = [];
    let files = fmCloud.listContents(root);
    for (var file of files) {
    	var f = file.replace(root,'');
    	f = f.replace('.md','');
    	fileNames.push(f)
    }
    
    /*--- Prompt ---*/
    var p = Prompt.create();
    p.title = "Select File";
    p.message = "Select the file you want to import into Drafts";
    for (var fileName of fileNames) {
      p.addButton(fileName);
    }
    var con = p.show();
    
    if (con) {
    	// Get selected path
    	let path = root + p.buttonPressed + ".md"
    	let content = fmCloud.readString(path)
    
    	let d = Draft.create();
    	d.content = content;
    	d.addTag("post");
    	d.update();
    	editor.load(d);
    	editor.activate();
    }
    else {
      context.cancel();
    }
  • includeAction

    No preview available.

Options

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