Skip to content

Commit

Permalink
parameterize base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Herman committed Jun 3, 2012
1 parent dd7feea commit 8b45ffc
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 49 deletions.
31 changes: 17 additions & 14 deletions bin/tc39
Expand Up @@ -15,14 +15,14 @@ var command = args.shift();

switch (command) {
case "build":
wiki.build(function(err) {
wiki.build(args[0] || "/", function(err) {
if (err) die("Build error: " + err.message);
console.log("Wiki built in " + fs.realpathSync(path.join(__dirname, "..", "out")));
});
break;

case "serve":
wiki.build(function(err) {
wiki.build("/", function(err) {
if (err) die("Build error: " + err.message);
console.log("Wiki built in " + fs.realpathSync(path.join(__dirname, "..", "out")));
wiki.serve(parseInt(args[0]) || 8888);
Expand All @@ -46,11 +46,12 @@ switch (command) {

case "webhook":
if (args.length < 1) die("Missing IP addresses", true);
if (args.length < 2) die("Missing gh-pages path", true);
if (args.length < 2) die("Missing base URL", true);
if (args.length < 3) die("Missing gh-pages path", true);
fs.stat(args[1], function(err, status) {
if (err) die("Cannot stat " + args[1] + ": " + err.message, true);
if (!status.isDirectory()) die(args[1] + " is not a directory", true);
wiki.webhook(parseInt(args[2]) || 8888, JSON.parse(args[0]), args[1]);
wiki.webhook(parseInt(args[3]) || 8888, JSON.parse(args[0]), args[1], args[2]);
});
break;

Expand All @@ -72,15 +73,17 @@ function help() {
console.error();
console.error("where <command> is one of:");
console.error();
console.error(" build build the wiki");
console.error(" push path message build and push the gh-pages branch");
console.error(" path path to gh-pages branch");
console.error(" message commit message");
console.error(" serve [port] build and serve the wiki");
console.error(" port server port [default: 8888]");
console.error(" webhook ips path [port] run the GitHub WebHook server");
console.error(" ips JSON array of GitHub IP addresses");
console.error(" path path to gh-pages branch");
console.error(" port server port [default: 8888]");
console.error(" build [base] build the wiki");
console.error(" base base URL for site-local absolute URL's [default: /]");
console.error(" push path message build and push the gh-pages branch");
console.error(" path path to gh-pages branch");
console.error(" message commit message");
console.error(" serve [port] build and serve the wiki");
console.error(" port server port [default: 8888]");
console.error(" webhook ips path base [port] run the GitHub WebHook server");
console.error(" ips JSON array of GitHub IP addresses");
console.error(" path path to gh-pages branch");
console.error(" base base URL for site-local absolute URL's");
console.error(" port server port [default: 8888]");
console.error();
}
2 changes: 1 addition & 1 deletion bin/tc39-webhook
Expand Up @@ -4,7 +4,7 @@ cd $(dirname $0)

case "$1" in
start)
forever start tc39 webhook '["207.97.227.253", "50.57.128.197", "108.171.174.178"]' $HOME/tc39-ghpages 8081
forever start tc39 webhook '["207.97.227.253", "50.57.128.197", "108.171.174.178"]' $HOME/tc39-ghpages /tc39-codex-wiki/ 8081
;;
stop)
forever stop tc39
Expand Down
4 changes: 2 additions & 2 deletions data/proposals/index.md
Expand Up @@ -8,9 +8,9 @@ These proposals are being **officially considered** for ECMAScript Edition 6, bu

## Scoping

* [block scoped bindings](block-scoped-bindings)
* [block scoping](block-scoping)
* [destructuring](destructuring)
* [parameter default values](parameter-default-values)
* [parameter defaults](parameter-defaults)
* [rest parameters](rest-parameters)
* [spread](spread)

Expand Down
19 changes: 12 additions & 7 deletions lib/build.js
Expand Up @@ -21,20 +21,25 @@ function ls(dir, cb) {
});
}

// FIXME: parameterize this out into a command-line argument
function formatURL(url) {
return url[0] === '/'
? "/tc39-codex-wiki" + url
: url;
function urlFormatter(baseURL) {
var length = baseURL.length;
if (baseURL[length - 1] === '/')
baseURL = baseURL.substring(0, length - 1);

return function(url) {
return url[0] === '/'
? baseURL + url
: url;
}
}

function build(cb) {
function build(baseURL, cb) {
var project = new Project({
inDir: rootDir,
outDir: outDir,
dataDir: dataDir,
templateDir: templateDir,
urlFormatter: formatURL
urlFormatter: urlFormatter(baseURL)
});
project.on("error", cb);
project.build(cb);
Expand Down
5 changes: 0 additions & 5 deletions lib/webhook.cjson

This file was deleted.

15 changes: 9 additions & 6 deletions lib/webhook.js
Expand Up @@ -12,8 +12,9 @@ function goaway(res) {
}

// simple queue that tracks at most one concurrent build request
function BuildQueue(ghpagesDir) {
function BuildQueue(ghpagesDir, baseURL) {
this.ghpagesDir = ghpagesDir; // gh-pages tree
this.baseURL = baseURL; // base URL for site-local absolute URL's
this.building = false; // build in progress?
this.pending = null; // most recent pending build request
}
Expand All @@ -27,7 +28,7 @@ BuildQueue.prototype.request = function request(name, url) {

this.building = true;
var self = this;
buildAndPush(name, url, this.ghpagesDir, function() {
buildAndPush(name, url, this.ghpagesDir, this.baseURL, function() {
self.building = false;

// perform the pending build
Expand All @@ -41,7 +42,7 @@ BuildQueue.prototype.request = function request(name, url) {

var rootDir = path.join(__dirname, "..");

function buildAndPush(name, url, ghpagesDir, cb) {
function buildAndPush(name, url, ghpagesDir, baseURL, cb) {
var message = "push by " + name + ": " + url;

console.log(message);
Expand All @@ -61,7 +62,9 @@ function buildAndPush(name, url, ghpagesDir, cb) {
},

// build static pages
build,
function(cb) {
build(baseURL, cb);
},

// push to gh-pages
function(cb) {
Expand All @@ -70,7 +73,7 @@ function buildAndPush(name, url, ghpagesDir, cb) {
], cb);
}

function webhook(port, github, ghpagesDir) {
function webhook(port, github, ghpagesDir, baseURL) {
var app = module.exports = express.createServer();

app.configure(function(){
Expand All @@ -87,7 +90,7 @@ function webhook(port, github, ghpagesDir) {
app.use(express.errorHandler());
});

var queue = new BuildQueue(ghpagesDir);
var queue = new BuildQueue(ghpagesDir, baseURL);

app.get('/', function(req, res) {
goaway(res);
Expand Down
10 changes: 0 additions & 10 deletions template/index.jade
Expand Up @@ -4,13 +4,3 @@ block content
block content-header
h1= file.title
article!= file.prepared
// - if (files.posts)
// .widget#recent-posts
// h3 Recent Posts
// ul
// - var len = (files.posts.length > 5) ? 5 : files.posts.length
// - for (var i = 0; i < len; i++)
// - var post = files.posts[i]
// li
// h4: a(href=post.href) #{post.title}
// .summary= post.summary
4 changes: 0 additions & 4 deletions template/layout.jade
@@ -1,7 +1,3 @@
//- file: title,template,render-file,inPath,inFile,outPath,href,prepared,project
//- files: root,about,proposals,ideas,pages,posts
//- files.pages: 0,1
//- how to print keys: #{Object.keys(x)}
!!!5
html(lang='en')
head
Expand Down

0 comments on commit 8b45ffc

Please sign in to comment.