Commit 0280bd8f7e0ed8a70224173c93b930022fb02225
Add repo digs page
Charles Lehner committed on 3/23/2016, 2:42:30 AMParent: 171bb8a2c96096c302ba35950277404010f2ddf5
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -36,9 +36,9 @@ | ||
36 | 36 | } |
37 | 37 | |
38 | 38 | function link(parts, html) { |
39 | 39 | 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 | |
41 | 41 | return '<a href="' + escapeHTML(href) + '">' + innerHTML + '</a>' |
42 | 42 | } |
43 | 43 | |
44 | 44 | function timestamp(time) { |
@@ -85,8 +85,23 @@ | ||
85 | 85 | ]) |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
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 | + | |
89 | 104 | function readNext(fn) { |
90 | 105 | var next |
91 | 106 | return function (end, cb) { |
92 | 107 | if (next) return next(end, cb) |
@@ -481,8 +496,10 @@ | ||
481 | 496 | case 'blob': |
482 | 497 | return serveRepoBlob(repo, branch, filePath) |
483 | 498 | case 'raw': |
484 | 499 | return serveRepoRaw(repo, branch, filePath) |
500 | + case 'digs': | |
501 | + return serveRepoDigs(repo) | |
485 | 502 | default: |
486 | 503 | return serve404(req) |
487 | 504 | } |
488 | 505 | } |
@@ -499,8 +516,9 @@ | ||
499 | 516 | var gitUrl = 'ssb://' + repo.id |
500 | 517 | var gitLink = '<input class="clone-url" readonly="readonly" ' + |
501 | 518 | 'value="' + gitUrl + '" size="' + (2 + gitUrl.length) + '" ' + |
502 | 519 | 'onclick="this.select()"/>' |
520 | + var digsPath = [repo.id, 'digs'] | |
503 | 521 | |
504 | 522 | var done = multicb({ pluck: 1, spread: true }) |
505 | 523 | getRepoName(repo.id, done()) |
506 | 524 | about.getName(repo.feed, done()) |
@@ -519,10 +537,10 @@ | ||
519 | 537 | : '<input type="hidden" name="vote" value="' + |
520 | 538 | (upvoted ? '0' : '1') + '">' + |
521 | 539 | '<button type="submit"><i>✌</i> ' + |
522 | 540 | (upvoted ? 'Undig' : 'Dig') + |
523 | - '</button>') + | |
524 | - '<strong>' + votes.upvotes + '</strong>' + | |
541 | + '</button>') + ' ' + | |
542 | + '<strong>' + link(digsPath, votes.upvotes) + '</strong>' + | |
525 | 543 | '</form>' + |
526 | 544 | '<h2>' + link([repo.feed], authorName) + ' / ' + |
527 | 545 | link([repo.id], repoName) + '</h2>' + |
528 | 546 | '</div><div class="repo-nav">' + link([repo.id], 'Code') + |
@@ -905,5 +923,29 @@ | ||
905 | 923 | else cb(null, serveRaw()(ssb.blobs.get(key))) |
906 | 924 | }) |
907 | 925 | }) |
908 | 926 | } |
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 | + } | |
909 | 951 | } |
Built with git-ssb-web