Action
Save as HTML to Dropbox
This will save all drafts to Dropbox rendered as HTML.
- Gets file name from “safe_title - created date”:
- file name = “title - yyyy-mm-dd_hhmm”,
- so updated drafts overwrite old versions.
Steps
-
script
// Save as HTML to Dropbox // Updates new and modified drafts since last run. // RV 2020-04-23 at 22:33 EDT // Gets file name from "safe_title - created date": // file name = "title - yyyy-mm-dd_hhmm", // so updated drafts overwrite old versions. 'use strictl'; let box = "all"; let path = '/My Notes/Drafts_html'; let ts_file = `${path}/.save_html_time_stamp.txt`; (() => { const now = new Date(); const ts = now.toString("yyyyMMddHHmmss"); // let fm = FileManager.create(false); // let lastime = Number(fm.read(ts_file)); let db = Dropbox.create(); let lastime = Number(db.read(ts_file)); if (isNaN(lastime)) { lastime = 0; } console.log('Save as HTML: ' + box); let count = 0; let drafts = Draft.query("", box); for(let d of drafts) { let mod = Number(d.modifiedAt.toString("yyyyMMddHHmmss")); if (mod < lastime) { continue; } if (d.languageGrammar.endsWith('JavaScript')) { continue; } let title = d.processTemplate("[[safe_title]]"); let created = d.processTemplate("[[created|%Y-%m-%d_%H%M]]"); let content= d.processTemplate("[[draft]]").trim(); let tags = d.processTemplate("[[tags]]"); if (tags != '') { content += '\n\n#' + tags.replace(/,/g, ' #'); } let ext = 'html'; let file = `${path}/${title} - ${created}.${ext}`; let mmd = MultiMarkdown.create(); // To preserve blank lines: content = content.replace(/ *$/gm, ' '); content = content.replace(/(\n *\n+)/g, '<br>$1'); mmd.format = "html"; // mmd.criticMarkup = true; let body = mmd.render(content); let html = `<html> <style> body { /* Chose font and size of your own liking */ font-family:Georgia; font-size:13pt; } </style> <body> ${body} </body> </html> `; // let success = fm.write(file, html); let success = db.write(file, html, "overwrite", true); count++; } // let success = fm.write(ts_file, ts); let success = db.write(ts_file, ts, "overwrite", true); app.displayInfoMessage(count + ' files saved.'); })()
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.