index.jsView |
---|
65 | 65 | function encodeLink(url) { |
66 | 66 | return '/' + encodeURIComponent(url) |
67 | 67 | } |
68 | 68 | |
69 | | -function link(parts, text, raw) { |
| 69 | +function link(parts, text, raw, props) { |
70 | 70 | var href = flattenPath(parts) |
71 | 71 | if (text == null) text = parts[parts.length-1] |
72 | 72 | if (!raw) text = escapeHTML(text) |
73 | | - return '<a href="' + escapeHTML(href) + '">' + text + '</a>' |
| 73 | + return '<a href="' + escapeHTML(href) + '"' + |
| 74 | + (props ? ' ' + props : '') + |
| 75 | + '>' + text + '</a>' |
74 | 76 | } |
75 | 77 | |
76 | 78 | function timestamp(time) { |
77 | 79 | time = Number(time) |
447 | 449 | return serveBlob(req, dir) |
448 | 450 | else if (ref.isMsgId(dir)) |
449 | 451 | return serveMessage(req, dir, dirs.slice(1)) |
450 | 452 | else if (ref.isFeedId(dir)) |
451 | | - return serveUserPage(dir) |
| 453 | + return serveUserPage(dir, dirs.slice(1)) |
452 | 454 | else |
453 | 455 | return serveFile(req, dirs) |
454 | 456 | } |
455 | 457 | |
629 | 631 | function serveIndex() { |
630 | 632 | return serveTemplate('git ssb')(renderFeed()) |
631 | 633 | } |
632 | 634 | |
633 | | - function serveUserPage(feedId) { |
| 635 | + function serveUserPage(feedId, dirs) { |
| 636 | + switch (dirs[0]) { |
| 637 | + case undefined: |
| 638 | + case '': |
| 639 | + case 'activity': |
| 640 | + return serveUserActivity(feedId) |
| 641 | + case 'repos': |
| 642 | + return serveUserRepos(feedId) |
| 643 | + } |
| 644 | + } |
| 645 | + |
| 646 | + function renderUserPage(feedId, page, body) { |
634 | 647 | return serveTemplate(feedId)(cat([ |
635 | 648 | readOnce(function (cb) { |
636 | 649 | about.getName(feedId, function (err, name) { |
637 | 650 | cb(null, '<h2>' + link([feedId], name) + |
638 | | - '<code class="user-id">' + feedId + '</code></h2>') |
| 651 | + '<code class="user-id">' + feedId + '</code></h2>' + |
| 652 | + '<nav>' + |
| 653 | + link([feedId], 'Activity', true, |
| 654 | + page == 'activity' ? ' class="active"' : '') + |
| 655 | + link([feedId, 'repos'], 'Repos', true, |
| 656 | + page == 'repos' ? ' class="active"' : '') + |
| 657 | + '</nav>') |
639 | 658 | }) |
640 | 659 | }), |
641 | | - renderFeed(feedId), |
| 660 | + body, |
642 | 661 | ])) |
643 | 662 | } |
644 | 663 | |
| 664 | + function serveUserActivity(feedId) { |
| 665 | + return renderUserPage(feedId, 'activity', renderFeed(feedId)) |
| 666 | + } |
| 667 | + |
| 668 | + function serveUserRepos(feedId) { |
| 669 | + return renderUserPage(feedId, 'repos', pull( |
| 670 | + ssb.messagesByType({ |
| 671 | + type: 'git-repo', |
| 672 | + reverse: true |
| 673 | + }), |
| 674 | + pull.filter(function (msg) { |
| 675 | + return msg.value.author == feedId |
| 676 | + }), |
| 677 | + pull.take(20), |
| 678 | + paramap(function (msg, cb) { |
| 679 | + getRepoName(about, feedId, msg.key, function (err, repoName) { |
| 680 | + if (err) return cb(err) |
| 681 | + cb(null, '<section class="collapse">' + |
| 682 | + link([msg.key], repoName) + |
| 683 | + '</section>') |
| 684 | + }) |
| 685 | + }, 8) |
| 686 | + )) |
| 687 | + } |
| 688 | + |
645 | 689 | |
646 | 690 | |
647 | 691 | function serveMessage(req, id, path) { |
648 | 692 | return readNext(function (cb) { |
780 | 824 | renderNameForm(!isPublic, repo.id, repoName, 'repo-name', null, |
781 | 825 | 'Rename the repo', |
782 | 826 | '<h2>' + link([repo.feed], authorName) + ' / ' + |
783 | 827 | link([repo.id], repoName) + '</h2>') + |
784 | | - '</div><div class="repo-nav">' + link([repo.id], 'Code') + |
| 828 | + '</div><nav>' + link([repo.id], 'Code') + |
785 | 829 | link([repo.id, 'activity'], 'Activity') + |
786 | 830 | link([repo.id, 'commits', branch || ''], 'Commits') + |
787 | 831 | link([repo.id, 'issues'], 'Issues') + |
788 | 832 | gitLink + |
789 | | - '</div>'), |
| 833 | + '</nav>'), |
790 | 834 | body |
791 | 835 | ]))) |
792 | 836 | }) |
793 | 837 | }) |