Commit 54fcc372 authored by Dave Lane's avatar Dave Lane
Browse files

added proper hash creation, and array variant of WEnotes per-page ID variables

parent 596d23da
......@@ -15,6 +15,7 @@ var jsdom = require("jsdom"),
path = require("path"),
wordpress = require("wordpress"),
uri = require("uri-js"),
md5 = require("crypto-js/md5"),
iframes, h5p, timestamp, generator, theme;
var pages = [], // list of page URLs to be processed
......@@ -183,7 +184,7 @@ if (opt["--wpurl"]) {
getOutline();
}
function setMetaName(head, name, content) {
function setMetaName(head, name, content) {
var meta = '<meta name="' + name + '" content="' + content + '">';
console.log('setting new meta: ', meta);
head.append(meta);
......@@ -276,6 +277,26 @@ function getNext(pi, pages) {
return l;
}
// create a unique-but-reproducable hash for any given string
// source: https://www.geeksforgeeks.org/how-to-create-hash-from-string-in-javascript/
function stringToHash(string) {
/*var hash = 0;
var i = 0;
var char = '';
if (string.length == 0) return hash;
for (i = 0; i < string.length; i++) {
char = string.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash;
}
return hash; */
var hash = md5(string).toString();
console.log('hash for '+string+' = '+hash+'...');
return hash;
}
function scanPage() {
var sp;
if (!opt["--scan"]) {
......@@ -454,21 +475,21 @@ function processPage(pi) {
console.log("******* Checking for video! ********");
var wrapper = $(this),
wrapper_classes = wrapper.attr("class"),
align = 'none',
align = 'none',
style, url,
yttitle = "",
ytinvocation;
yttitle = "",
ytinvocation;
// find the alignment
if (wrapper.hasClass('floatright')) {
align = 'right';
} else if (wrapper.hasClass('floatleft')) {
align = 'left';
align = 'left';
} else if (wrapper.hasClass('center')) {
align = 'center';
} else {
align = 'none';
}
console.log('align ', align);
console.log('align ', align);
// get the title if any
if (wrapper.find('.weYouTubeTitleContainer')) {
yttitle = wrapper.find('.weYouTubeTitleContainer').text();
......@@ -482,7 +503,7 @@ function processPage(pi) {
height = $this.css("height") || 315,
start = 0,
list = $this.attr("data-list"),
index = $this.attr("data-index");
index = $this.attr("data-index");
// get video details
if (wrapper.find("a").attr("href").includes("youtube.com")) {
url = wrapper.find("a").attr("href");
......@@ -497,23 +518,23 @@ function processPage(pi) {
start = qparam[1];
console.log('found start! = ', start);
}
}
}
console.log('qstring = ', qstring);
} else {
} else {
url = 'https://youtube.com/watch?v=' + id;
}
console.log('url = ', url);
console.log('url = ', url);
var opts = ' class="weYouTube-responsive" controls="yes" disable_links="true" allowfullscreen="yes"';
opts += ' url="' + url + '"';
opts += ' url="' + url + '"';
opts += ' maxwidth=' + width;
if (start != 0) { opts += ' parameters="start=' + start + '"'; }
if (yttitle != "") { opts += ' title="' + yttitle + '"'; }
if (align != "none") { opts += ' align="' + align + '"'; }
ytinvocation = '[arve' + opts + ']';
console.log('initial ytinvocation = ', ytinvocation);
});
console.log('initial ytinvocation = ', ytinvocation);
});
// assign the new content...
//ytinvocation = '<div class="' + wrapper_classes + '"' + style + '>' + ytinvocation + '</div>';
//ytinvocation = '<div class="' + wrapper_classes + '"' + style + '>' + ytinvocation + '</div>';
wrapper.replaceWith(ytinvocation); //Testing YouTube
});
// embed SoundCloud clips
......@@ -607,7 +628,7 @@ function processPage(pi) {
theme.header($, opt);
var iconsrc = $("#footer-copyrightico img").attr("src").replace("/icons/", "/buttons/");
var iconsrc = $("#footer-copyrightico img").attr("src").replace("/icons/", "/buttons/");
var notices = getNotices(outline[pi], iconsrc);
theme.footer($, opt, pages, pi, outline[pi], notices, iconsrc);
......@@ -748,6 +769,22 @@ function processPage(pi) {
});
$("script").remove();
// add per page identifier
console.log('|||||||||||| setting page IDs for '+base_url+' - '+url+'...');
var site_id = stringToHash(base_url);
var path_id = stringToHash(url);
console.log('|||||||||||| hashes: base_id = '+site_id+', path_id = '+path_id);
$('footer').append(`
<script id="wenotes-ids">
var WEnotesSite = '`+base_url+`';
var WEnotesPath = '`+url+`';
var WEnotesSiteID = '`+site_id+`';
var WEnotesPathID = '`+path_id+`';
var WEnotesIDs = { site: '`+base_url+`', path: '`+url+`', site_id: '`+site_id+`', path_id: '`+path_id+`' };
</script>
`);
page = $('<div id="weinwp"/>')
.append($("#content"))
.append($("footer"))
......
......@@ -18,13 +18,14 @@
"jsdom": "9.12.0",
"docopt": "0.6.2",
"mkdirp": "0.5.1",
"wordpress": "1.4.0"
"wordpress": "1.4.0",
"crypto-js": "*"
},
"license": "MIT",
"bin": {
"course": "course.js"
},
"scripts":{
"scripts": {
"format": "./node_modules/.bin/prettier --write *.js themes/*.js",
"lint": "./node_modules/.bin/eslint *.js themes/*.js"
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment