-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
config.js
54 lines (41 loc) · 1.11 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
var hostedGitInfo = require('hosted-git-info')
module.exports = config
var viewPaths = {github: 'blob', gitlab: 'blob', bitbucket: 'src'}
var headingPrefixes = {github: '#', gitlab: '#', bitbucket: '#markdown-header-'}
var topAnchors = {github: '#readme', gitlab: '#readme'}
var lineLinks = {github: true, gitlab: true}
function config(ctx) {
var repo = ctx.repository
var urlConfig = ctx.urlConfig
var info = {}
if (urlConfig) {
return
}
urlConfig = {
prefix: '',
headingPrefix: '#',
lines: false,
hostname: null,
topAnchor: null
}
if (repo) {
info = hostedGitInfo.fromUrl(repo)
}
if (info) {
if (info.type in viewPaths) {
urlConfig.prefix = '/' + info.path() + '/' + viewPaths[info.type] + '/'
}
if (info.type in headingPrefixes) {
urlConfig.headingPrefix = headingPrefixes[info.type]
}
if (info.type in lineLinks) {
urlConfig.lines = lineLinks[info.type]
}
if (info.type in topAnchors) {
urlConfig.topAnchor = topAnchors[info.type]
}
urlConfig.hostname = info.domain
}
ctx.urlConfig = urlConfig
}