From 8b45ffc1e5babf5c2ecc741a07d9ccaf258e0c1a Mon Sep 17 00:00:00 2001 From: Dave Herman Date: Sun, 3 Jun 2012 16:55:23 -0700 Subject: [PATCH] parameterize base URL --- bin/tc39 | 31 +++++++++++++++++-------------- bin/tc39-webhook | 2 +- data/proposals/index.md | 4 ++-- lib/build.js | 19 ++++++++++++------- lib/webhook.cjson | 5 ----- lib/webhook.js | 15 +++++++++------ template/index.jade | 10 ---------- template/layout.jade | 4 ---- 8 files changed, 41 insertions(+), 49 deletions(-) delete mode 100644 lib/webhook.cjson diff --git a/bin/tc39 b/bin/tc39 index e6f5881..22927aa 100755 --- a/bin/tc39 +++ b/bin/tc39 @@ -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); @@ -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; @@ -72,15 +73,17 @@ function help() { console.error(); console.error("where 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(); } diff --git a/bin/tc39-webhook b/bin/tc39-webhook index 68e25c2..a441ea6 100755 --- a/bin/tc39-webhook +++ b/bin/tc39-webhook @@ -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 diff --git a/data/proposals/index.md b/data/proposals/index.md index 5e942bb..2c62194 100644 --- a/data/proposals/index.md +++ b/data/proposals/index.md @@ -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) diff --git a/lib/build.js b/lib/build.js index b108f58..98490b5 100644 --- a/lib/build.js +++ b/lib/build.js @@ -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); diff --git a/lib/webhook.cjson b/lib/webhook.cjson deleted file mode 100644 index f9ae727..00000000 --- a/lib/webhook.cjson +++ /dev/null @@ -1,5 +0,0 @@ -{ - "port": 8081, - "github": ["207.97.227.253", "50.57.128.197", "108.171.174.178"], - "branch": "{{HOME}}/tc39-ghpages" -} diff --git a/lib/webhook.js b/lib/webhook.js index 7df92fe..1550a47 100644 --- a/lib/webhook.js +++ b/lib/webhook.js @@ -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 } @@ -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 @@ -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); @@ -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) { @@ -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(){ @@ -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); diff --git a/template/index.jade b/template/index.jade index 5b27718..f65d3a8 100644 --- a/template/index.jade +++ b/template/index.jade @@ -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 diff --git a/template/layout.jade b/template/layout.jade index cb2fc16..1f938a5 100644 --- a/template/layout.jade +++ b/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