diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-06 15:15:56 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-06 15:15:56 -1000 |
commit | d81825f4b4da83bd0376ac916107f425872eee7b (patch) | |
tree | 7219b91fcbb3a7f72536ef0e23442ee978f28241 /lib | |
parent | a06789afcc5b53c34d19d2d9d35c3b91c705d91c (diff) | |
download | patchfoo-d81825f4b4da83bd0376ac916107f425872eee7b.tar.gz patchfoo-d81825f4b4da83bd0376ac916107f425872eee7b.zip |
Serve channels under /channel/ instead of /%23
Diffstat (limited to 'lib')
-rw-r--r-- | lib/render.js | 3 | ||||
-rw-r--r-- | 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, |