diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-08-26 17:02:43 -0700 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-08-26 17:02:43 -0700 |
commit | 573fa4b98cd650d1e2417fd34f11744da0cea911 (patch) | |
tree | 113659a61118a06f6cd0384c1223c57902880a5b | |
parent | 5f0557786b04a8802109ea99b734d32638d7ea6c (diff) | |
download | patchfoo-573fa4b98cd650d1e2417fd34f11744da0cea911.tar.gz patchfoo-573fa4b98cd650d1e2417fd34f11744da0cea911.zip |
Linkify ids in git branch names
-rw-r--r-- | lib/render-msg.js | 7 | ||||
-rw-r--r-- | lib/render.js | 7 |
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js index 316709e..99c4ddf 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -32,8 +32,8 @@ RenderMsg.prototype.toUrl = function (href) { return this.render.toUrl(href) } -RenderMsg.prototype.linkify = function (text) { - return this.render.linkify(text) +RenderMsg.prototype.linkify = function (text, opts) { + return this.render.linkify(text, opts) } RenderMsg.prototype.raw = function (cb) { @@ -749,8 +749,9 @@ RenderMsg.prototype.gitUpdate = function (cb) { var path = id && ('/git/' + type + '/' + encodeURIComponent(id) + '?msg=' + encodeURIComponent(self.msg.key)) + '&search=1' + var name = ref.replace(/^refs\/(heads|tags)\//, '') return h('li', - ref.replace(/^refs\/(heads|tags)\//, ''), ': ', + self.linkify(name, {ellipsis: true}), ': ', id ? h('a', {href: self.render.toUrl(path)}, h('code', id)) : h('em', 'deleted')) })) : '', diff --git a/lib/render.js b/lib/render.js index e6da13c..32085e4 100644 --- a/lib/render.js +++ b/lib/render.js @@ -192,10 +192,13 @@ Render.prototype.formatSize = function (size) { return size.toFixed(2) + ' MB' } -Render.prototype.linkify = function (text) { +Render.prototype.linkify = function (text, opts) { + var ellipsis = opts && opts.ellipsis var arr = text.split(u.ssbRefEncRegex) for (var i = 1; i < arr.length; i += 2) { - arr[i] = h('a', {href: this.toUrlEnc(arr[i])}, arr[i]) + var id = arr[i] + var text = ellipsis && id.length > 8 ? id.substr(0, 8) + '…' : id + arr[i] = h('a', {href: this.toUrlEnc(id)}, text) } return arr } |