Skip to content

Instantly share code, notes, and snippets.

@andrewshell
Last active August 29, 2015 14:18
Show Gist options
  • Save andrewshell/501f8b4af614eddd2958 to your computer and use it in GitHub Desktop.
Save andrewshell/501f8b4af614eddd2958 to your computer and use it in GitHub Desktop.
{
"urlTwitterServer": "https://storage.geekity.com/",
"urlDefaultImage": "http://scripting.com/2015/03/21/gratefulDead.png",
"googleAnalyticsAccount": "",
"templates": {
"Default": "http://myword.geekity.com/templates/default.html",
"Handlebars": {"urlTemplate": "http://myword.geekity.com/templates/handlebars.html", "templateEngine": "renderHandlebars"},
"Plain": "http://myword.io/templates/plain/template.html"
}
}
<html>
<head>
<title>{{ twtitle }}</title>
</head>
<body>
<h1>{{ twtitle }}</h1>
<h2>{{ twdescription }}</h2>
<div class="body">{{{ renderedtext }}}</div>
<ul>
{{#each appPrefs.rssHistory }}
<li><a href="{{ link }}">{{ title }}</a></li>
{{/each}}
</ul>
</body>
</html>
// This file is included along with any dependencies in index.html
function renderHandlebars(templatetext, pagetable) {
var template = Handlebars.compile(templatetext);
return template(pagetable);
}
diff --git a/scripts.js b/scripts.js
index 2357cbb..61307d3 100644
--- a/scripts.js
+++ b/scripts.js
@@ -363,16 +363,22 @@ function publishButtonClick (flInteract, callback) {
//New optional param, flInteract. If false, we don't put up a dialog asking if the user wants to see the rendered file.
//3/21/15; 5:31:07 PM by DW
//There is one specific circumstance where we have to upload twice. If appPrefs.lastPublishedUrl is the empty string, we upload the first time to set the value, then upload again, so that it can be correct in the pagetable. The Facebook metadata needs the canonical URL for the page to be correct.
- var now = new Date (), urlTemplate;
+ var now = new Date (), urlTemplate, templateEngine;
if (flInteract === undefined) {
flInteract = true;
}
fieldsToData ();
//set urlTemplate, unicase search
+ // This is identitifying the template config, setting urlTemplate
var lowername = stringLower (theData.nameTemplate);
for (var x in config.templates) {
if (stringLower (x) == lowername) {
+ if (typeof config.templates [x] === 'string') {
urlTemplate = config.templates [x];
+ } else {
+ urlTemplate = config.templates [x]['urlTemplate'];
+ templateEngine = config.templates [x]['templateEngine'];
+ }
break;
}
}
@@ -430,7 +436,12 @@ function publishButtonClick (flInteract, callback) {
pagetable.commenttext = commentstext; //4/1/15 by DW -- grandfathered, first version of default template used this name
pagetable.renderedtext = new Markdown.Converter ().makeHtml (pagetable.body); //for substitution in the template -- 3/26/15 by DW
+ if (undefined === templateEngine) {
var renderedtext = multipleReplaceAll (templatetext, pagetable, false, "[%", "%]");
+ } else {
+ pagetable.appPrefs = appPrefs; // I want all the raw data
+ var renderedtext = window[templateEngine] (templatetext, pagetable);
+ }
twUploadFile (theData.filePath, pagetable.pagetableinjson, "application/json", false, function (data) {
theData.linkJson = data.url;
twUploadFile (filepath, renderedtext, "text/html", false, function (data) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment