Skip to content

Commit af59066

Browse files
committed
add source links to api entries
1 parent 2bccbcc commit af59066

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

themes/vue/source/js/common.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55
if (PAGE_TYPE) {
66
initVersionSelect()
77
initSubHeaders()
8+
initApiSpecLinks()
9+
}
10+
11+
function initApiSpecLinks () {
12+
var apiContent = document.querySelector('.content.api')
13+
if (apiContent) {
14+
var apiTitles = [].slice.call(apiContent.querySelectorAll('h3'))
15+
apiTitles.forEach(function (titleNode) {
16+
var ulNode = titleNode.parentNode.nextSibling
17+
if (ulNode.tagName !== 'UL') {
18+
ulNode = ulNode.nextSibling
19+
}
20+
if (ulNode.tagName === 'UL') {
21+
var specNode = document.createElement('li')
22+
var specLink = createSourceSearchPath(titleNode.textContent)
23+
specNode.innerHTML = '<a href="' + specLink + '" target="_blank">Source</a>'
24+
ulNode.appendChild(specNode)
25+
}
26+
})
27+
}
28+
29+
function createSourceSearchPath(query) {
30+
return 'https://github.com/search?utf8=%E2%9C%93&q=repo%3Avuejs%2Fvue+extension%3Ajs+' + encodeURIComponent(query) + '+&type=Code'
31+
}
832
}
933

1034
/**

0 commit comments

Comments
 (0)