46 changed files with 162 additions and 44 deletions
@ -0,0 +1,7 @@ |
|||||
|
gitbook.events.bind('start', function(e, config) { |
||||
|
anchors.options = config.anchorjs || {}; |
||||
|
}); |
||||
|
|
||||
|
gitbook.events.bind('page.change', function() { |
||||
|
anchors.add('h1,h2,h3,h4,h5'); |
||||
|
}); |
@ -0,0 +1,14 @@ |
|||||
|
require([ 'gitbook' ], function (gitbook) { |
||||
|
gitbook.events.bind('start', function (e, config) { |
||||
|
var githubURL = config.github.url; |
||||
|
|
||||
|
gitbook.toolbar.createButton({ |
||||
|
icon: 'fa fa-github', |
||||
|
label: 'GitHub', |
||||
|
position: 'right', |
||||
|
onClick: function() { |
||||
|
window.open(githubURL) |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
}); |
@ -0,0 +1,45 @@ |
|||||
|
const get = query => new Promise((resolve, reject) => { |
||||
|
const xhr = new XMLHttpRequest(); |
||||
|
|
||||
|
xhr.open('GET', `https://api.npms.io/v2/search?q=${query}`); |
||||
|
xhr.addEventListener('load', () => { |
||||
|
try { |
||||
|
resolve(JSON.parse(xhr.responseText)); |
||||
|
} catch (ex) { |
||||
|
reject(ex); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
xhr.send(); |
||||
|
}); |
||||
|
|
||||
|
require(['gitbook'], (gitbook) => { |
||||
|
gitbook.events.bind('page.change', () => { |
||||
|
[...document.querySelectorAll('.npmsearchlist')].map(el => { |
||||
|
const query = el.getAttribute('data-query'); |
||||
|
|
||||
|
get(query) |
||||
|
.then(({ results }) => ( |
||||
|
`<div>
|
||||
|
<h2>${results.length} packages found</h2> |
||||
|
<hr /> |
||||
|
<ul> |
||||
|
${results.map(({ package }) => (` |
||||
|
<li> |
||||
|
<h3> |
||||
|
<a class="package-name" href="${package.links.npm}">${package.name}</a> |
||||
|
<a class="author-name" href="https://www.npmjs.com/~${package.author.username}">${package.author.username}</a> |
||||
|
</h3> |
||||
|
<p class="description">${package.description}</p> |
||||
|
<p class="stats"> |
||||
|
<span class="version">v${package.version}</span> |
||||
|
</p> |
||||
|
</li> |
||||
|
`)).join('')}
|
||||
|
</ul> |
||||
|
</div>` |
||||
|
)) |
||||
|
.then(markup => el.innerHTML = markup); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
@ -0,0 +1,50 @@ |
|||||
|
.npmsearchlist li { |
||||
|
list-style: none; |
||||
|
position: relative; |
||||
|
font-size: 125%; |
||||
|
color: rgb(51, 51, 51); |
||||
|
padding-bottom: 1.125em; |
||||
|
padding-top: 0.25em; |
||||
|
border-bottom: 1px solid rgb(234, 234, 234); |
||||
|
} |
||||
|
|
||||
|
.npmsearchlist h3 { |
||||
|
display: block; |
||||
|
margin: 0; |
||||
|
padding: 20px 0 10px 0; |
||||
|
font-size: 20px; |
||||
|
font-weight: 400; |
||||
|
line-height: 1; |
||||
|
color: rgba(0, 0, 0, 0.8); |
||||
|
} |
||||
|
|
||||
|
.npmsearchlist h3 .package-name { |
||||
|
font-weight: 500; |
||||
|
margin-right: 0.4em; |
||||
|
color: #000; |
||||
|
} |
||||
|
|
||||
|
.npmsearchlist h3 .author-name { |
||||
|
font-size: 75%; |
||||
|
color: rgb(119, 119, 119); |
||||
|
font-family: Consolas, "Liberation Mono", Menlo, Monaco, Courier, monospace; |
||||
|
} |
||||
|
|
||||
|
.npmsearchlist p { |
||||
|
color: rgb(85, 85, 85); |
||||
|
line-height: 20px; |
||||
|
margin: 0.5em 0 0; |
||||
|
font-size: 0.75em; |
||||
|
} |
||||
|
|
||||
|
.npmsearchlist .stats { |
||||
|
color: rgba(0, 0, 0, 0.4); |
||||
|
font-size: 0.8em; |
||||
|
font-weight: 600; |
||||
|
display: block; |
||||
|
} |
||||
|
|
||||
|
.npmsearchlist .stats .version { |
||||
|
color: rgb(119, 119, 119); |
||||
|
font-size: 17px; |
||||
|
} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue