Commit 428ced89 authored by Dave Lane's avatar Dave Lane
Browse files

fixing botched rebase, updating content of courseWP.js, bumping to version...

fixing botched rebase, updating content of courseWP.js, bumping to version 1.2.0, fixing default paths in watch.py
parent 5a8236a8
......@@ -2,7 +2,7 @@
/* jshint node: true, multistr: true, trailing: true, esnext: true */
"use strict";
const VERSION = "1.1.1",
const VERSION = "1.2.0",
JQUERY = "http://code.jquery.com/jquery-2.1.1.min.js",
FILEPATH = "/home/www/www";
......@@ -12,6 +12,7 @@ var jsdom = require("jsdom"),
mkdirp = require("mkdirp"),
path = require("path"),
wordpress = require("wordpress"),
uri = require("uri-js"),
iframes, h5p,
theme;
......@@ -30,22 +31,42 @@ 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
base_url = "https://wikieducator.org", // no trailing slash
wp,
base_url = "",
opt,
options = {};
const doc = `Usage:
course [options] OUTLINE PAGEPREFIX
course -h | --help
course --version
Options:
Note: you may need to enclose argument values (e.g. BRAND, LOGO and PASS) in ''!
Options:
-b BRAND, --brand=BRAND Menubar brand [default: OCL4Ed].
-n NAME, --name=NAME Institution name/label.
-l LOGO, --logo=LOGO Institution logo.
-k LOGOLINK, --link=LOGOLINK Institution link.
--nameN=NAMEN --logoN=LOGON --linkN=LOGOLINKN Additional Institutions for cobranding, where N = 2-5.
--previous=PREVTEXT --next=NEXTTEXT Alternative text (e.g. translation).
--caption=CAPTION Caption for logo, e.g. Partner, Sponsor, etc.
-n NAME, --name=NAME Institution Name string.
--name2=NAME_2
--caption2=CAPTION_2
--logo2=LOGO_2
--link2=LOGOLINK_2 Additional Institution for cobranding.
--name3=NAME_3
--caption3=CAPTION_3
--logo3=LOGO_3
--link3=LOGOLINK_3 Additional Institution for cobranding.
--name4=NAME_4
--caption4=CAPTION_4
--logo4=LOGO_4
--link4=LOGOLINK_4 Additional Institution for cobranding.
--name5=NAME_5
--caption5=CAPTION_5
--logo5=LOGO_5
--link5=LOGOLINK_5 Additional Institution for cobranding.
--previous=PREVTEXT
--next=NEXTTEXT Alternative text (e.g. language translation).
--disclaimer=DISCLAIMERLINK Link to disclaimer info.
-t THEME, --theme=THEME Desired theme [default: default].
-u URLPREFIX, --urlprefix=URLPREFIX Filesystem URL component.
......@@ -65,13 +86,21 @@ Options:
--debugout Show content to be written.
-h, --help Show this help.
--version Display version.
`;
opt = docopt(doc, { version: VERSION });
console.log('one...');
opt = docopt(doc, {exit: false});
console.log(
`========================= ${new Date().toJSON()} =========================`
);
console.log(opt);
// work out the base_url for Wiki pages
console.log('Outline = ', opt['OUTLINE']);
base_url = getBaseURL(opt);
console.log('base_url: ', base_url);
//
// deal with other options
if (opt["--theme"]) {
theme = require("./themes/" + opt["--theme"]);
}
......@@ -83,9 +112,35 @@ if (opt["--h5p"]) {
}
if (opt["--link"] && opt["--link"].indexOf("//") === -1) {
opt["--link"] = "https://" + opt["--link"];
// work with other links, too, if present.
if (opt["--link2"] && opt["--link2"].indexOf("//") === -1) {
opt["--link2"] = "https://" + opt["--link2"];
if (opt["--link3"] && opt["--link3"].indexOf("//") === -1) {
opt["--link3"] = "https://" + opt["--link3"];
if (opt["--link4"] && opt["--link4"].indexOf("//") === -1) {
opt["--link4"] = "https://" + opt["--link4"];
if (opt["--link5"] && opt["--link5"].indexOf("//") === -1) {
opt["--link5"] = "https://" + opt["--link5"];
}
}
}
}
}
if (opt["--logo"] && opt["--logo"].indexOf("//") === -1) {
opt["--logo"] = opt["--urlprefix"] + "/img/" + opt["--logo"];
// work with other logos, too, if present.
if (opt["--logo2"] && opt["--logo2"].indexOf("//") === -1) {
opt["--logo2"] = opt["--urlprefix"] + "/img/" + opt["--logo2"];
if (opt["--logo3"] && opt["--logo3"].indexOf("//") === -1) {
opt["--logo3"] = opt["--urlprefix"] + "/img/" + opt["--logo3"];
if (opt["--logo4"] && opt["--logo4"].indexOf("//") === -1) {
opt["--logo4"] = opt["--urlprefix"] + "/img/" + opt["--logo4"];
if (opt["--logo5"] && opt["--logo5"].indexOf("//") === -1) {
opt["--logo5"] = opt["--urlprefix"] + "/img/" + opt["--logo5"];
}
}
}
}
}
if (opt["--options"]) {
opt["--options"].split(";").forEach(x => {
......@@ -130,6 +185,17 @@ if (opt["--wpurl"]) {
getOutline();
}
function getBaseURL(opt) {
let u = uri.parse(opt['OUTLINE']);
console.log('u: ', u);
base_url = u.scheme + '://' + u.host;
if (u.port) {
console.log("adding port: ", u.port);
base_url += ':' + u.port;
}
return base_url;
}
function pageToURL(p) {
val = opt["--urlprefix"] +
p.replace(opt.PAGEPREFIX, "").replace("?", "").replace("%3F", "");
......@@ -486,9 +552,9 @@ function processPage(pi) {
nl = urls[pages[np]];
}
if (opt["--previous"] && opt["--next"]) {
pt = opt["--previous"];
nt = opt["--next"];
}
pt = opt["--previous"];
nt = opt["--next"];
}
theme.prevnext($, pl, nl, pt, nt);
}
......@@ -566,7 +632,6 @@ function processPage(pi) {
}
});
console.log("opt: "+opt);
theme.process($, opt);
// if using analytics, install at the bottom of the page
......@@ -630,22 +695,30 @@ function processPage(pi) {
console.log("######");
}
try {
//console.log("---- data1 ----");
//console.log(data);
//console.log("---- data2 ----");
wp.newPost(page_desc, function(err, data) {
if (err) {
console.log(pi, pages[pi], err);
console.log('...error...')
console.log(page_desc, pi, pages[pi], err);
process.exit(9);
} else {
console.log('...no error, saving in WP...')
console.log(pi, "wp saved:", data);
outline[pi].wpID = data;
}
console.log("processing page...")
console.log( arguments );
setImmediate(processPages);
});
} catch (e) {
console.log(pi, "!!!error writing to wp");
console.log("------");
console.log( arguments );
console.log("------1");
console.log(outline[pi]);
console.log("------");
console.log("page_desc", page_desc);
console.log("------2");
//console.log("page_desc", page_desc);
setImmediate(processPages);
}
} else {
......@@ -664,20 +737,24 @@ function processPage(pi) {
}
function oeruMenuCreate() {
console.log('*********** start oeruMenuCreate **************');
// find out the methods this WordPress install supports
wp.listMethods(function(err, methods) {
if (err) {
console.log(`Unable to retrieve list of XMLRPC methods ${err}`);
process.exit(10);
} else {
// if oeru_theme.menu_create is supported, invoke it
if (methods.indexOf("oeru_theme.menu_create") > -1) {
wp.authenticatedCall("oeru_theme.menu_create", function(error, data) {
console.log('got XMLRPC Methods');
// if oeru_course.menu_create is supported, invoke it
if (methods.indexOf("oeru_course.menu_create") > -1) {
console.log('trying to create a menu... ');
wp.authenticatedCall("oeru_course.menu_create", function(error, data) {
console.log('completed XMLRPC call... ');
if (error) {
console.log(`Menu creation failed: ${error}`);
process.exit(11);
} else {
console.log("Menu created", data);
console.log("Menu created");
}
});
}
......@@ -687,13 +764,14 @@ function oeruMenuCreate() {
function processPages() {
console.log(`---- processPages(pi=${pi}) ----`);
console.log('outline[0]: ', outline[0]);
if (pi >= pages.length) {
wp.authenticatedCall(
"wp.setOptions",
{
show_on_front: "page",
page_on_front: outline[0].wpID,
oeru_theme_menu_create: 1
oeru_course_menu_create: 1
},
function(err, a) {
if (err) {
......@@ -783,6 +861,7 @@ function getOutline() {
}
$sub = $(this).children("ul");
info.base_url = base_url;
info.text = text;
info.wkpage = wkpage;
info.url = url;
......
......@@ -9,10 +9,10 @@ import MySQLdb
#node = '/home/ubuntu/.nvm/versions/node/v4.2.1/bin/node'
node = '/usr/bin/nodejs'
#weurl = 'https://wikieducator.org'
weurl = 'https://c.wikieducator.org'
#osdir = '/home/data/wikieducator.org/course-snapshot/src'
osdir = '/home/data/c.wikieducator.org/course-snapshot/src'
weurl = 'https://wikieducator.org'
osdir = '/home/data/wikieducator.org/course-snapshot/src'
#weurl = 'https://c.wikieducator.org'
#osdir = '/home/data/c.wikieducator.org/course-snapshot/src'
debug = 0;
def send_mail(name, email, subject, message):
......
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