diff --git a/handlebars/helpers/index.js b/handlebars/helpers/index.js index fa568d2..1d116a2 100644 --- a/handlebars/helpers/index.js +++ b/handlebars/helpers/index.js @@ -383,12 +383,12 @@ function transformTree (object, fn) { function github (filePath) { // Build url to correct version and file in githubs const packageJson = findPackage(path.resolve(filePath), true) - const url = packageJson && packageJson.repository && packageJson.repository.url + const url = repoWebUrl(packageJson && packageJson.repository && packageJson.repository.url) if (url && url.match(/github.com/)) { const version = packageJson.version // path within the package const relativePath = path.relative(path.dirname(packageJson.paths.absolute), filePath) - return url.replace(/^git\+/, '').replace(/\.git$/, '') + '/blob/v' + version + '/' + relativePath + return `${url}/blob/v${version}/${relativePath}` } } diff --git a/test/fixtures/github-ssh-repo-url/package.json b/test/fixtures/github-ssh-repo-url/package.json new file mode 100644 index 0000000..45a7fda --- /dev/null +++ b/test/fixtures/github-ssh-repo-url/package.json @@ -0,0 +1,16 @@ +{ + "name": "github-ssh-repo-url", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/nknapp/thought-plugin-jsdoc.git" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/test/fixtures/include/withPackageOf.ssh.md b/test/fixtures/include/withPackageOf.ssh.md new file mode 100644 index 0000000..cb7e632 --- /dev/null +++ b/test/fixtures/include/withPackageOf.ssh.md @@ -0,0 +1 @@ +https://github.com/nknapp/thought-plugin-jsdoc/blob/v1.0.0/package.json - github-ssh-repo-url \ No newline at end of file diff --git a/test/helper-spec.js b/test/helper-spec.js index 0f86c25..72b0a38 100644 --- a/test/helper-spec.js +++ b/test/helper-spec.js @@ -290,6 +290,14 @@ describe('thought-helpers:', function () { .to.eventually.equal(versions(fixture('include/withPackageOf.default.md'))) }) + it('should create a url and package.json for file on github (with a git-ssh-url)', function () { + return expectHbs( + '{{#withPackageOf file}} {{@url}} - {{@package.name}} {{/withPackageOf}}', + {file: 'test/fixtures/github-ssh-repo-url/package.json'} + ) + .to.eventually.equal(versions(fixture('include/withPackageOf.ssh.md'))) + }) + it('should create a url and package.json for files in dependency projects (based on the their current package version)', function () { return expectHbs( '{{#withPackageOf file}} {{@url}} - {{@package.name}} {{/withPackageOf}}',