git ssb

30+

cel / git-ssb-web



Commit d216b0353c9628c01e54c1dd05521f2708d6ba1b

Link to message ids with anchors that work

cel committed on 11/24/2017, 4:23:34 AM
Parent: c057842053e5b621b8944a045b087dd563abe19e

Files changed

lib/repos/index.jschanged
lib/repos/issues.jschanged
lib/util.jschanged
lib/repos/index.jsView
@@ -141,15 +141,16 @@
141141 }
142142
143143 R.renderLineComment = function (req, repo, msg) {
144144 var c = msg && msg.value && msg.value.content
145- return h('section', {class: 'collapse'}, [
145 + var id = u.msgIdToDomId(msg.key)
146 + return h('section', {class: 'collapse', id: id}, [
146147 h('div', [
147148 u.link([msg.value.author], msg.authorName),
148149 ' ',
149150 h('tt', {class: 'right-bar item-id'}, msg.key),
150151 ' · ',
151- h('a', {href: u.encodeLink(msg.key) + '#' + encodeURIComponent(msg.key)}, new Date(msg.value.timestamp).toLocaleString(req._locale)),
152 + h('a', {href: u.encodeLink(msg.key) + '#' + id}, new Date(msg.value.timestamp).toLocaleString(req._locale)),
152153 ]),
153154 markdown(c.text, repo)
154155 ])
155156 }
lib/repos/issues.jsView
@@ -149,10 +149,11 @@
149149 ]))
150150 }
151151
152152 I.renderIssueActivityMsg = function (req, repo, issue, type, postId, msg) {
153 + var id = msgIdToDomId(msg.key)
153154 var authorLink = u.link([msg.value.author], msg.authorName)
154- var msgHref = u.encodeLink(msg.key) + '#' + encodeURIComponent(msg.key)
155 + var msgHref = u.encodeLink(msg.key) + '#' + id
155156 var msgTimeLink = '<a href="' + msgHref + '"' +
156157 ' name="' + u.escape(msg.key) + '">' +
157158 new Date(msg.value.timestamp).toLocaleString(req._locale) + '</a>'
158159 var c = msg.value.content
@@ -161,9 +162,9 @@
161162 return ''
162163 case 'post':
163164 if (c.root == issue.id) {
164165 var changed = this.web.issues.isStatusChanged(msg, issue)
165- return '<section class="collapse">' +
166 + return '<section class="collapse" id="' + id + '">' +
166167 (msg.key == postId ? '<div class="highlight">' : '') +
167168 '<tt class="right-bar item-id">' + msg.key + '</tt> ' +
168169 (changed == null ? authorLink : req._t(
169170 changed ? 'issue.Reopened' : 'issue.Closed',
@@ -173,9 +174,9 @@
173174 markdown(c.text, repo) +
174175 '</section>'
175176 } else {
176177 var text = c.text || (c.type + ' ' + msg.key)
177- return '<section class="collapse mention-preview">' +
178 + return '<section class="collapse mention-preview" id="' + id + '">' +
178179 req._t('issue.MentionedIn', {
179180 name: authorLink,
180181 type: type,
181182 post: '<a href="/' + msg.key + '#' + msg.key + '">' +
@@ -183,16 +184,16 @@
183184 }) + '</section>'
184185 }
185186 case 'issue':
186187 case 'pull-request':
187- return '<section class="collapse mention-preview">' +
188 + return '<section class="collapse mention-preview" id="' + id + '">' +
188189 req._t('issue.MentionedIn', {
189190 name: authorLink,
190191 type: type,
191192 post: u.link([msg.key], u.messageTitle(msg))
192193 }) + '</section>'
193194 case 'issue-edit':
194- return '<section class="collapse">' +
195 + return '<section class="collapse" id="' + id + '">' +
195196 (msg.key == postId ? '<div class="highlight">' : '') +
196197 // handle deprecated rename
197198 (c.title == null ? '' : req._t('issue.Renamed', {
198199 author: authorLink,
@@ -205,9 +206,9 @@
205206 var mention = this.web.issues.getMention(msg, issue)
206207 if (mention) {
207208 var commitLink = u.link([repo.id, 'commit', mention.object],
208209 mention.label || mention.object)
209- return '<section class="collapse">' +
210 + return '<section class="collapse" id="' + id + '">' +
210211 req._t(mention.open ? 'issue.Reopened' : 'issue.Closed', {
211212 name: authorLink,
212213 type: type
213214 }) + ' &middot; ' + msgTimeLink + '<br/>' +
@@ -216,9 +217,9 @@
216217 } else if ((mention = getMention(msg, issue.id))) {
217218 var commitLink = u.link(mention.object ?
218219 [repo.id, 'commit', mention.object] : [msg.key],
219220 mention.label || mention.object || msg.key)
220- return '<section class="collapse">' +
221 + return '<section class="collapse" id="' + id + '">' +
221222 req._t('issue.Mentioned', {
222223 name: authorLink,
223224 type: type
224225 }) + ' &middot; ' + msgTimeLink + '<br/>' +
@@ -228,9 +229,9 @@
228229 // fallthrough
229230 }
230231
231232 default:
232- return '<section class="collapse">' +
233 + return '<section class="collapse" id="' + id + '">' +
233234 authorLink +
234235 ' &middot; ' + msgTimeLink +
235236 u.json(c) +
236237 '</section>'
lib/util.jsView
@@ -240,4 +240,11 @@
240240
241241 u.privateIcon = function (req) {
242242 return `<img src="/emoji/lock.png" height="16" width="16" alt="${req._t('repo.Private')}" title="${req._t('repo.RepoIsPrivate')}">`
243243 }
244 +
245 +u.msgIdToDomId = function (id) {
246 + return 'msg-' + id.replace(/^%/, '')
247 + .replace(/\+/g, '-')
248 + .replace(/\//g, '_')
249 + .replace(/=/g, '')
250 +}

Built with git-ssb-web