Commit a32dfbce authored by Jim Tittsler's avatar Jim Tittsler

allow no WP title on landing page; options string

Add an extensible options argument that is a semicolon separated
string of op=value (or simply op, where value is true). The first
option is no_landing_page_title.

Resolves #14
parent d5385b03
......@@ -2,7 +2,7 @@
/* jshint node: true, multistr: true, trailing: true, esnext: true */
"use strict";
const VERSION = '0.11.2',
const VERSION = '0.11.3',
JQUERY = 'http://code.jquery.com/jquery-2.1.1.min.js',
FILEPATH = '/home/www/www';
......@@ -31,7 +31,8 @@ var pages = [], // list of page URLs to be processed
pi = 0, // process index
base_url = 'http://wikieducator.org', // no trailing slash
wp,
opt;
opt,
options = {};
const doc = `Usage:
course [options] OUTLINE PAGEPREFIX
course -h | --help
......@@ -43,6 +44,7 @@ Options:
-k LOGOLINK, --link=LOGOLINK Institution link
-t THEME, --theme=THEME Desired theme [default: default].
-u URLPREFIX, --urlprefix=URLPREFIX Filesystem URL component.
-o OPTIONS, --options=OPTIONS Script control options.
-p, --prevnext Include previous/next links.
-s, --scan Include SCAN page.
-r, --rthird Exclude third level navigation.
......@@ -70,6 +72,19 @@ if (opt['--link'] && ! /^http/i.test(opt['--link'])) {
if (opt['--logo'] && ! /^http/i.test(opt['--logo'])) {
opt['--logo'] = opt['--urlprefix'] + '/img/' + opt['--logo'];
}
if (opt['--options']) {
opt['--options'].split(';').forEach(x => {
let p = x.split('=', 2);
p.map(s => s.trim());
console.log(`p: ${p}`);
if (p.length === 1) {
options[p[0]] = true;
} else {
options[p[0]] = p[1];
}
});
}
console.log(JSON.stringify(options, null, 2));
if (opt['--wpurl']) {
wp = wordpress.createClient({
url: opt['--wpurl'],
......@@ -480,7 +495,7 @@ function processPage(pi) {
var pagename = path.basename(outline[pi].text).replace('Practice:OCL4Ed', '');
console.log(`pagename=${pagename}`);
console.log(outline[pi]);
if (pagename === '') {
if ((pagename === '') && !outline[pi].slug) {
setImmediate(processPages);
return;
}
......@@ -488,10 +503,12 @@ function processPage(pi) {
title: outline[pi].text,
status: 'publish',
type: 'page',
//name: 'page' + outline[pi].node,
menuOrder: outline[pi].node*100,
content: page
};
if (outline[pi].slug) {
page_desc.name = outline[pi].slug;
}
if (outline[pi].path.length >= 2) {
var myParent = outline[pi].path.slice(-2, -1);
page_desc.parent = outline[myParent].wpID;
......@@ -687,13 +704,14 @@ function getOutline() {
});
if (opt['--wpurl']) {
// make the first page the name of the course
let title = opt.PAGEPREFIX.replace(/\//g, '')
.replace(/_/g, ' ');
let newurl = `${opt['--urlprefix']}/${slugify(title)}`;
urls[pages[0]] = newurl;
outline[0].url = newurl;
outline[0].text = title;
// allow the user to make the first page have no WP title
// by giving it a slug, but seting the text to an empty string
if (options.hasOwnProperty('no_landing_page_title')) {
let newurl = `${slugify(outline[0].text)}`;
outline[0].slug = newurl;
outline[0].url = newurl;
outline[0].text = '';
}
}
if (opt['--wpdelete']) {
var posts = [];
......
Markdown is supported
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