git ssb

30+

cel / git-ssb-web



Commit 0280bd8f7e0ed8a70224173c93b930022fb02225

Add repo digs page

Charles Lehner committed on 3/23/2016, 2:42:30 AM
Parent: 171bb8a2c96096c302ba35950277404010f2ddf5

Files changed

index.jschanged
index.jsView
@@ -36,9 +36,9 @@
3636 }
3737
3838 function link(parts, html) {
3939 var href = '/' + parts.map(encodeURIComponent).join('/')
40- var innerHTML = html || escapeHTML(parts[parts.length-1])
40+ var innerHTML = html == null ? escapeHTML(parts[parts.length-1]) : html
4141 return '<a href="' + escapeHTML(href) + '">' + innerHTML + '</a>'
4242 }
4343
4444 function timestamp(time) {
@@ -85,8 +85,23 @@
8585 ])
8686 }
8787 }
8888
89+function ul(props) {
90+ return function (read) {
91+ return cat([
92+ pull.once('<ul' + (props ? ' ' + props : '') + '>'),
93+ pull(
94+ read,
95+ pull.map(function (li) {
96+ return '<li>' + li + '</li>'
97+ })
98+ ),
99+ pull.once('</ul>')
100+ ])
101+ }
102+}
103+
89104 function readNext(fn) {
90105 var next
91106 return function (end, cb) {
92107 if (next) return next(end, cb)
@@ -481,8 +496,10 @@
481496 case 'blob':
482497 return serveRepoBlob(repo, branch, filePath)
483498 case 'raw':
484499 return serveRepoRaw(repo, branch, filePath)
500+ case 'digs':
501+ return serveRepoDigs(repo)
485502 default:
486503 return serve404(req)
487504 }
488505 }
@@ -499,8 +516,9 @@
499516 var gitUrl = 'ssb://' + repo.id
500517 var gitLink = '<input class="clone-url" readonly="readonly" ' +
501518 'value="' + gitUrl + '" size="' + (2 + gitUrl.length) + '" ' +
502519 'onclick="this.select()"/>'
520+ var digsPath = [repo.id, 'digs']
503521
504522 var done = multicb({ pluck: 1, spread: true })
505523 getRepoName(repo.id, done())
506524 about.getName(repo.feed, done())
@@ -519,10 +537,10 @@
519537 : '<input type="hidden" name="vote" value="' +
520538 (upvoted ? '0' : '1') + '">' +
521539 '<button type="submit"><i>✌</i> ' +
522540 (upvoted ? 'Undig' : 'Dig') +
523- '</button>') +
524- '<strong>' + votes.upvotes + '</strong>' +
541+ '</button>') + ' ' +
542+ '<strong>' + link(digsPath, votes.upvotes) + '</strong>' +
525543 '</form>' +
526544 '<h2>' + link([repo.feed], authorName) + ' / ' +
527545 link([repo.id], repoName) + '</h2>' +
528546 '</div><div class="repo-nav">' + link([repo.id], 'Code') +
@@ -905,5 +923,29 @@
905923 else cb(null, serveRaw()(ssb.blobs.get(key)))
906924 })
907925 })
908926 }
927+
928+ /* Digs */
929+
930+ function serveRepoDigs(repo) {
931+ return readNext(function (cb) {
932+ getVotes(repo.id, function (err, votes) {
933+ cb(null, renderRepoPage(repo, '', cat([
934+ pull.once('<section><h3>Digs</h3>' +
935+ '<div>Total: ' + votes.upvotes + '</div>'),
936+ pull(
937+ pull.values(Object.keys(votes.upvoters)),
938+ pull.asyncMap(function (feedId, cb) {
939+ about.getName(feedId, function (err, name) {
940+ if (err) return cb(err)
941+ cb(null, link([feedId], name))
942+ })
943+ }),
944+ ul()
945+ ),
946+ pull.once('</section>')
947+ ])))
948+ })
949+ })
950+ }
909951 }

Built with git-ssb-web