git ssb

30+

cel / git-ssb-web



Commit f856a88ddc79a7ba60cbc42fa9ea382d5c05efbb

Consolidate link functions

Charles Lehner committed on 3/27/2016, 4:36:44 PM
Parent: 1610838e2f74772cb14e43fe47ee593084a17c3c

Files changed

index.jschanged
index.jsView
@@ -23,9 +23,9 @@
2323 blockRenderer.urltransform = function (url) {
2424 if (ref.isLink(url))
2525 return encodeLink(url)
2626 if (/^[0-9a-f]{40}$/.test(url) && this.options.repo)
27- return flattenPath([this.options.repo.id, 'tree', url])
27+ return encodeLink([this.options.repo.id, 'tree', url])
2828 return url
2929 }
3030
3131 marked.setOptions({
@@ -57,21 +57,21 @@
5757 if (isNaN(str)) return {host: str, port: def.port}
5858 return {host: def.host, port: str}
5959 }
6060
61-function flattenPath(parts) {
62- return '/' + parts.map(encodeURIComponent).join('/')
61+function isArray(arr) {
62+ return Object.prototype.toString.call(arr) == '[object Array]'
6363 }
6464
6565 function encodeLink(url) {
66- return '/' + encodeURIComponent(url)
66+ if (!isArray(url)) url = [url]
67+ return '/' + url.map(encodeURIComponent).join('/')
6768 }
6869
6970 function link(parts, text, raw, props) {
70- var href = flattenPath(parts)
7171 if (text == null) text = parts[parts.length-1]
7272 if (!raw) text = escapeHTML(text)
73- return '<a href="' + escapeHTML(href) + '"' +
73+ return '<a href="' + encodeLink(parts) + '"' +
7474 (props ? ' ' + props : '') +
7575 '>' + text + '</a>'
7676 }
7777
@@ -742,9 +742,9 @@
742742 // Allow navigating revs using GET query param.
743743 // Replace the branch in the path with the rev query value
744744 path[0] = path[0] || 'tree'
745745 path[1] = query.rev
746- req._u.pathname = flattenPath([repo.id].concat(path))
746+ req._u.pathname = encodeLink([repo.id].concat(path))
747747 delete req._u.query.rev
748748 delete req._u.search
749749 return serveRedirect(url.format(req._u))
750750 }
@@ -1153,9 +1153,9 @@
11531153 '<span class="raw-link">' + link(rawFilePath, 'Raw') + '</span>' +
11541154 '</div></section>' +
11551155 '<section>'),
11561156 extension in imgMimes
1157- ? pull.once('<img src="' + escapeHTML(flattenPath(rawFilePath)) +
1157+ ? pull.once('<img src="' + encodeLink(rawFilePath) +
11581158 '" alt="' + escapeHTML(filename) + '" />')
11591159 : markdownFilenameRegex.test(filename)
11601160 ? readOnce(function (cb) {
11611161 pull(object.read, pull.collect(function (err, bufs) {

Built with git-ssb-web