From afabd2eacb34221e1b60ed77cce59a621e8c8022 Mon Sep 17 00:00:00 2001 From: cel Date: Wed, 22 Aug 2018 14:38:52 -0700 Subject: [PATCH] Handle channels/hashtags in form --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 38b7f37..ae7b2c9 100644 --- a/index.js +++ b/index.js @@ -529,15 +529,22 @@ function serveFile(req, res, file) { }) } +function asChannelLink(id) { + var channel = refs.normalizeChannel(id) + if (channel) return '#' + channel +} + function asLink(id) { if (!id || typeof id !== 'string') return null id = id.trim() + if (id[0] === '#') return asChannelLink(id) if (refs.isLink(id)) return id try { id = decodeURIComponent(id) } catch(e) { return null } + if (id[0] === '#') return asChannelLink(id) if (refs.isLink(id)) return id } @@ -546,7 +553,9 @@ function serveHome(req, res, query, conf) { var id = asLink(q.id) if (id) { res.writeHead(303, { - Location: '/' + (refs.isMsgId(id) ? encodeURIComponent(id) : id) + Location: '/' + ( + id[0] === '#' ? 'channel/' + id.substr(1) : + refs.isMsgId(id) ? encodeURIComponent(id) : id) }) return res.end() }