From d81825f4b4da83bd0376ac916107f425872eee7b Mon Sep 17 00:00:00 2001 From: cel Date: Sat, 6 May 2017 15:15:56 -1000 Subject: Serve channels under /channel/ instead of /%23 --- lib/render.js | 3 ++- lib/serve.js | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/render.js b/lib/render.js index 316ad2f..36dba2f 100644 --- a/lib/render.js +++ b/lib/render.js @@ -146,7 +146,8 @@ Render.prototype.toUrl = function (href) { case '&': if (!u.isRef(href)) return false return this.opts.blob_base + href - case '#': return this.opts.base + encodeURIComponent(href) + case '#': return this.opts.base + 'channel/' + + encodeURIComponent(href.substr(1)) case '/': return this.opts.base + href.substr(1) case '?': return this.opts.base + 'search?q=' + encodeURIComponent(href) } diff --git a/lib/serve.js b/lib/serve.js index 4fe3cd6..bce474c 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -219,6 +219,13 @@ Serve.prototype.respondSink = function (status, headers, cb) { }) } +Serve.prototype.redirect = function (dest) { + this.res.writeHead(302, { + Location: dest + }) + this.res.end() +} + Serve.prototype.path = function (url) { var m url = url.replace(/^\/+/, '/') @@ -227,7 +234,8 @@ Serve.prototype.path = function (url) { case '/robots.txt': return this.res.end('User-agent: *') } if (m = /^\/%23(.*)/.exec(url)) { - return this.channel(decodeURIComponent(m[1])) + return this.redirect(this.app.render.toUrl('/channel/' + + decodeURIComponent(m[1]))) } m = /^([^.]*)(?:\.(.*))?$/.exec(url) switch (m[1]) { @@ -245,6 +253,7 @@ Serve.prototype.path = function (url) { } m = /^(\/?[^\/]*)(\/.*)?$/.exec(url) switch (m[1]) { + case '/channel': return this.channel(m[2]) case '/type': return this.type(m[2]) case '/links': return this.links(m[2]) case '/static': return this.static(m[2]) @@ -373,10 +382,7 @@ Serve.prototype.search = function (ext) { } if (u.isRef(searchQ) || searchQ[0] === '#') { - self.res.writeHead(302, { - Location: self.app.render.toUrl(searchQ) - }) - return self.res.end() + return self.redirect(self.app.render.toUrl(searchQ)) } pull( @@ -536,7 +542,7 @@ Serve.prototype.channels = function (ext) { paramap(function (channel, cb) { var subscribed = false cb(null, [ - h('a', {href: self.app.render.toUrl('#' + channel)}, '#' + channel), + h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel), ' ' ]) }, 8), @@ -660,7 +666,8 @@ Serve.prototype.rawId = function (id) { }) } -Serve.prototype.channel = function (channel) { +Serve.prototype.channel = function (path) { + var channel = decodeURIComponent(String(path).substr(1)) var q = this.query var gt = Number(q.gt) || -Infinity var lt = Number(q.lt) || Date.now() @@ -1220,7 +1227,7 @@ Serve.prototype.wrapChannel = function (channel) { cb(null, [ h('section', h('h3.feed-name', - h('a', {href: self.app.render.toUrl('#' + channel)}, '#' + channel) + h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel) ) ), composer, -- cgit v1.2.3