Action

Pelican Markdown Header

Posted by @MyGeekDaddy, Last update over 2 years ago

Insert a Markdown metadate header (title, category, tags, and date/time stamp) used by Markdown files for Pelican static site generator.

Steps

  • script

    // 4 script actions to generate the 4 lines of the MD title block for Pelican
    // Created by: @MyGeekDaddy
    //	Revision: 2022-08-10
    
    
    let p1 = new Prompt();
    p1.title = "Enter Blog Title"
    p1.addTextField("mdtitle", "Title", "", {
    	"autocorrect": false,
    	"keyboard":  "default",
    	"wantsFocus": true
    });
    p1.addButton("Insert");
    if(p1.show() && p1.buttonPressed == "Insert") {
    	let [st, len] = editor.getSelectedRange();
    	let s = "Title: " + p1.fieldValues["mdtitle"] + "\n";
    	editor.setSelectedText(s);
    	editor.setSelectedRange(st+s.length, 0);
    }
  • script

    let p2 = new Prompt();
    p2.title = "Enter Blog Category"
    p2.addTextField("mdcat", "Category", "", {
    	"autocorrect": false,
    	"keyboard":  "default",
    	"wantsFocus": true
    });
    p2.addButton("Insert");
    if(p2.show() && p2.buttonPressed == "Insert") {
    	let [st1, len] = editor.getSelectedRange();
    	let s1 = "Category: " + p2.fieldValues["mdcat"] + "\n";
    	editor.setSelectedText(s1);
    	editor.setSelectedRange(st1+s1.length, 0);
    }
    
  • script

    let p3 = new Prompt();
    p3.title = "Enter Blog Tags"
    p3.addTextField("mdtag", "Tags", "", {
    	"autocorrect": false,
    	"keyboard":  "default",
    	"wantsFocus": true
    });
    p3.addButton("Insert");
    if(p3.show() && p3.buttonPressed == "Insert") {
    	let [st2, len] = editor.getSelectedRange();
    	let s2 = "Tags: " + p3.fieldValues["mdtag"] + "\n";
    	editor.setSelectedText(s2);
    	editor.setSelectedRange(st2+s2.length, 0);
    }
    
  • script

    // Scripted version to insert current date/time in ISO 8601
    // 2022-04-01 16:15:45
    
    var curDate = new Date();
    var curDay = curDate.getDate();
    var curMonth = curDate.getMonth()+1;
    var curYear = curDate.getFullYear();
    var curHour = curDate.getHours();
    var curMinute = curDate.getMinutes();
    var curSecond = curDate.getSeconds();
    
    if (curDay < 10) {
    	curDay = "0" + curDay;
    }
    if (curMonth < 10) {
    	curMonth = "0" + curMonth;
    }
    if (curHour < 10) {
    	curHour = "0" + curHour;
    }
    if (curMinute < 10) {
    	curMinute = "0" + curMinute;
    }
    if (curSecond < 10) {
    	curSecond = "0" + curSecond;
    }
    
    
    txtFinal = "Date: " + curYear + "-" + curMonth + "-" + curDay + " " + curHour + ":" + curMinute + ":" + curSecond + "\n\n";
    
    var selRange = editor.getSelectedRange();
    editor.setSelectedText(txtFinal);
    editor.setSelectedRange(selRange[0]+txtFinal.length,0);
    editor.activate();

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.