git ssb

30+

cel / git-ssb-web



Commit dbf91fcb6b08833648216861b54b1bfea551ee35

Find css dep even if it is not in ./node_modules/

Charles Lehner committed on 4/2/2016, 3:33:24 AM
Parent: 4cd0e7ebc99a154fda9b7d201aaf74a5dd9ba62f

Files changed

index.jschanged
index.jsView
@@ -21,8 +21,10 @@
2121 var Mentions = require('ssb-mentions')
2222 var Highlight = require('highlight.js')
2323 var JsDiff = require('diff')
2424
25+var hlCssPath = path.resolve(require.resolve('highlight.js'), '../../styles')
26+
2527 // render links to git objects and ssb objects
2628 var blockRenderer = new marked.Renderer()
2729 blockRenderer.urltransform = function (url) {
2830 if (ref.isLink(url))
@@ -599,16 +601,20 @@
599601 else if (ref.isMsgId(dir))
600602 return serveMessage(req, dir, dirs.slice(1))
601603 else if (ref.isFeedId(dir))
602604 return serveUserPage(req, dir, dirs.slice(1))
605+ else if (dir == 'static')
606+ return serveFile(req, dirs)
607+ else if (dir == 'highlight')
608+ return serveFile(req, [hlCssPath].concat(dirs.slice(1)), true)
603609 else
604- return serveFile(req, dirs)
610+ return serve404(req)
605611 }
606612
607- function serveFile(req, dirs) {
608- var filename = path.join.apply(path, [__dirname].concat(dirs))
613+ function serveFile(req, dirs, outside) {
614+ var filename = path.resolve.apply(path, [__dirname].concat(dirs))
609615 // prevent escaping base dir
610- if (filename.indexOf('../') === 0)
616+ if (!outside && filename.indexOf('../') === 0)
611617 return servePlainError(403, '403 Forbidden')
612618
613619 return readNext(function (cb) {
614620 fs.stat(filename, function (err, stats) {
@@ -698,9 +704,9 @@
698704 }],
699705 '<!doctype html><html><head><meta charset=utf-8>',
700706 '<title>' + escapeHTML(title || 'git ssb') + '</title>',
701707 '<link rel=stylesheet href="/static/styles.css"/>',
702- '<link rel=stylesheet href="/node_modules/highlight.js/styles/github.css"/>',
708+ '<link rel=stylesheet href="/highlight/github.css"/>',
703709 '</head>\n',
704710 '<body>',
705711 '<header>',
706712 '<h1><a href="/">git ssb' +

Built with git-ssb-web