8000 Rewrite `master` to `HEAD` in GH links · ixartz/unifiedjs.github.io@3ce7ac6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ce7ac6

Browse files
committed
Rewrite master to HEAD in GH links
1 parent 2ebfc25 commit 3ce7ac6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

generate/plugin/rehype-rewrite-urls.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ function urls(options) {
113113
if (host === 'github.com') {
114114
rest = url.pathname.slice(1).split('/')
115115

116+
// Tree goes to directories, blob to files.
117+
if (rest[3] === 'master' && (rest[2] === 'tree' || rest[2] === 'blob')) {
118+
rest[3] = 'HEAD'
119+
}
120+
116121
repo = rest.slice(0, 2).join('/')
117122

118123
if (own.call(data.projectByRepo, repo)) {
@@ -160,6 +165,8 @@ function urls(options) {
160165
if (!url.hash && rest.length === 0) {
161166
return new URL('/explore/project/' + repo + '/', origin)
162167
}
168+
} else {
169+
return new URL('/' + rest.join('/'), 'https://github.com')
163170
}
164171
}
165172
}

0 commit comments

Comments
 (0)
0