mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
34 lines
882 B
JavaScript
34 lines
882 B
JavaScript
'use strict';
|
|
|
|
var path = require('path');
|
|
var findGit = require('../lib/git/find_git');
|
|
var getGithubURLPrefix = require('../lib/git/url_prefix');
|
|
|
|
function getFileRoot(file) {
|
|
return path.dirname(findGit(file));
|
|
}
|
|
|
|
/**
|
|
* Attempts to link code to its place on GitHub.
|
|
*
|
|
* @name linkGitHub
|
|
* @param {Object} comment parsed comment
|
|
* @return {Object} comment with github inferred
|
|
*/
|
|
module.exports = function (comment) {
|
|
var root = getFileRoot(comment.context.file);
|
|
var urlPrefix = getGithubURLPrefix(root);
|
|
var fileRelativePath = comment.context.file.replace(root + path.sep, '')
|
|
.split(path.sep)
|
|
.join('/');
|
|
|
|
if (urlPrefix) {
|
|
comment.context.path = fileRelativePath;
|
|
comment.context.github = urlPrefix +
|
|
fileRelativePath +
|
|
'#L' + comment.context.loc.start.line + '-' +
|
|
'L' + comment.context.loc.end.line;
|
|
}
|
|
return comment;
|
|
};
|