Commit 72406e44 authored by Dave Lane's avatar Dave Lane
Browse files

shifted to shortcode option for wenotes-ids, improved comments

parent 89755d98
......@@ -33,11 +33,11 @@ var pages = [], // list of page URLs to be processed
urls = {}, // map of original URLs to course URLs
parent_ids = {}, // map from URL to wp page id
pi = 0, // process index
wp,
base_url = "",
wp, // the wordpress interaction instance
base_url = "", // the base URL (schema, site, port) of the Outline source site extracted from the Outline parameter
numstr = '/[^\d.]/g',
opt,
options = {};
opt, // user supplied options, i.e. via the command line
options = {}; // script control options....
const doc = `Usage:
course [options] OUTLINE PAGEPREFIX
......@@ -100,7 +100,7 @@ console.log(opt);
// work out the base_url for Wiki pages
base_url = getBaseURL(opt);
//
// deal with other options
// deal with other command line options
if (opt["--theme"]) {
theme = require("./themes/" + opt["--theme"]);
}
......@@ -281,84 +281,11 @@ function getNext(pi, pages) {
// 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"]) {
return "";
}
sp = `<div id="scanpage" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<img alt="OERu logo" src="' + opt['--urlprefix'] + '/img/OERu-46x46.png" width="46" height="46" border="0" style="float: left; margin-right: 10px;">
<h4 class="modal-title">' + opt['--brand'] + '</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<a href="' + opt['--urlprefix'] + '/About/" class="btn btn-large btn-primary center-block">Open Content Licensing for Educators<br>Course overview</a>
</div>
</div>
<div class="row">
<div class="col-md-4">
<a href="' + opt['--urlprefix'] + '/Course_guide/Aims/" class="btn btn-large btn-primary center-block">Course aims</a>
</div>
<div class="col-md-4">
<a href="' + opt['--urlprefix'] + '/Course_guide/" class="btn btn-large btn-primary center-block">Course guide</a>
</div>
<div class="col-md-4">
<a href="' + opt['--urlprefix'] + '/Assessment/" class="btn btn-large btn-primary center-block">Assessment</a>
</div>
</div>
<div class="row">
<div class="col-md-6">
<a href="' + opt['--urlprefix'] + '/Start_here/" class="btn btn-large btn-info center-block">Start here</a>
</div>
<div class="col-md-6">
<a href="' + opt['--urlprefix'] + '/Registration/" class="btn btn-large btn-info center-block">Log in</a>
</div>
</div>
<div class="row">
<div class="col-md-4">
<a href="' + opt['--urlprefix'] + '/Console/" class="btn btn-large btn-primary center-block">Learning console</a>
</div>
<div class="col-md-4">
<a href="' + opt['--urlprefix'] + '/Console/#Announcements" class="btn btn-large btn-primary center-block">Announcements</a>
</div>
<div class="col-md-4">
<a href="' + opt['--urlprefix'] + '/Support/" class="btn btn-large btn-primary center-block">Support</a>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a href="' + opt['--urlprefix'] + '/Console/#Course_schedule" class="btn btn-large btn-primary center-block">Recommended course schedule</a>
</div>
</div>
</div>
</div>
</div>
</div>`;
return sp;
}
/* build navBar for current page */
function navBar(pi) {}
......@@ -427,11 +354,9 @@ function processPage(pi) {
if (cl.indexOf("weci-") === 0) {
$(this)
.find("a:first")
.prepend(
'<span class="glyphicon glyphicon-' +
.prepend('<span class="glyphicon glyphicon-' +
cl.slice(5) +
'"></span>&nbsp;'
)
'"></span>&nbsp;')
.addClass("list-group-item")
.unwrap();
}
......@@ -626,11 +551,12 @@ function processPage(pi) {
// add our header stuff
var page_header = $("head");
//setAppMeta(page_header);
setAppMeta(page_header);
// make stylesheet & Javascript references point to WikiEducator
page_header.find('link[rel="stylesheet"]').each(function() {
var href = $(this).attr("href");
console.log('************updating link stylesheet href: ', href);
if (
href &&
href.length >= 2 &&
......@@ -638,6 +564,7 @@ function processPage(pi) {
href.charAt(1) !== "/"
) {
//$(this).attr("href", "https://wikieducator.org" + href);
console.log('************updating link stylesheet href: '+href+' with: '+base_url + href);
$(this).attr("href", base_url + href);
}
});
......@@ -654,7 +581,7 @@ function processPage(pi) {
}
});
// add user fetch
$('meta[charset="UTF-8"]').after(`
/* $('meta[charset="UTF-8"]').after(`
<meta http-equiv="X-UA-Compatible-TEST!" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
......@@ -683,14 +610,28 @@ function processPage(pi) {
req.open("get", "`+base_url+`/api.php?action=query&meta=userinfo&uiprop=realname&format=json");
req.send();
}());
</script>`);
</script>`); */
/* if (opt['--h5p']) {
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!! adding H5P Resize script!!!!');
page_header.append(getH5PResizer());
}*/
theme.header($, opt);
// compile the WEnotes IDs
/* 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);
var wenotes_ids = "<script type='text/javascript' 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>";
console.log('|||||||||||||<<<<<<<<<<<<<< wenotes-ids ', wenotes_ids); */
//theme.header($, opt, wenotes_ids);
var iconsrc = $("#footer-copyrightico img").attr("src").replace("/icons/", "/buttons/");
var notices = getNotices(outline[pi], iconsrc);
......@@ -806,18 +747,31 @@ function processPage(pi) {
theme.process($, opt);
// if using analytics, install at the bottom of the page
// add the Matomo short code
if (options.siteid) {
options.tracker = options.tracker || "https://stats.oeru.org";
$("#content").append(
`[oeru_analytics type="piwik" url="${options.tracker}" id="${options.siteid}"]`
);
}
// add google analytics short code
if (options.google_analytics) {
$("#content").append(
`[oeru_analytics type="google" id="${options.google_analytics}"]`
);
}
// 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);
// create a shortcode to insert...
var shortcode = '[WEnotesIds WEnotesSite="'+base_url+'" WEnotesPath="'+url+'" WEnotesSiteID="'+site_id+'" WEnotesPathID="'+path_id+'"]';
// insert the WEnotesIds short code
$('#content').append('<div id="wenote-ids" style="display: none">'+shortcode+'</div>');
console.log('|||||||||||| shortcode: '+shortcode);
// save the page: to Wordpress or to filesystem
if (opt["--wpurl"]) {
// hotlink to the images on WikiEducator
......@@ -834,22 +788,6 @@ 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"))
......
......@@ -12,7 +12,7 @@ module.exports = {
version: "0.2.0",
// emit headers
header: function($, opt) {
header: function($, opt, wenotes_ids = "") {
var p = opt["--urlprefix"] + "/";
$('head link[href*="wikieducator.org/load.php"]').remove();
$('head link[rel="shortcut icon"]').attr("href", p + "img/favicon.png");
......@@ -37,6 +37,9 @@ module.exports = {
<script src="' + p + 'js/we.js"></script>
`);
// add the WEnotesID values here...
// if (wenotes_ids != "") $("head").append(wenotes_ids);
$("head").append(wenotes_ids);
},
footer: function($, opt, pages, pi, outlineItem, notices, iconsrc) {
......@@ -487,6 +490,7 @@ ${idbody}
// override Bootstrap's img block in Template:Pdf
$('.pdfdown img[alt="PDF down.png"]').css("display", "inline-block");
// use WEnotes plugin
// insert WEnotes feed shortcode
$(".WEnotes").each(function() {
var tag = $(this).data("tag"),
context = 'tag',
......@@ -496,6 +500,7 @@ ${idbody}
}
$(this).replaceWith(`[WEnotes tag="${tag}" count="${count}" context="${context}"]`);
});
// insert WEnotesPost shortcode
$(".WEnotesPost").each(function() {
var tag = $.trim($(this).data("tag")),
context = 'tag',
......@@ -503,13 +508,13 @@ ${idbody}
buttonAttr = button ? ` button="${button}"` : "",
leftmargin = $.trim($(this).data("leftmargin")),
leftmarginAttr = leftmargin ? ` leftmargin="${leftmargin}"` : "";
/*if ($(this).data("context") != undefined) {
if ($(this).data("context") != undefined) {
context = $(this).data("context");
}*/
$(this).replaceWith(
`[WEnotesPost tag="${tag}"${buttonAttr}${leftmarginAttr}]`
}
/*$(this).replaceWith(
`[WEnotesPost tag="${tag}"${buttonAttr}${leftmarginAttr} context="${context}"]`*/
`[WEnotesPost tag="${tag}"${buttonAttr}${leftmarginAttr}]`*/
$(this).replaceWith(
`[WEnotesPost tag="${tag}"${buttonAttr}${leftmarginAttr} context="${context}"]`
);
});
}
......
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