Skip to content

Commit 909287e

Browse files
committed
Merge pull request graphql#17 from vjeux/search
Introduce search
2 parents 648d5b6 + 9b62327 commit 909287e

File tree

4 files changed

+113
-16
lines changed

4 files changed

+113
-16
lines changed

site/_core/HeaderLinks.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,46 @@
99
var React = require('react');
1010

1111
var HeaderLinks = React.createClass({
12-
links: [
12+
linksInternal: [
1313
{section: 'docs', text: 'Docs', href: '/docs/getting-started/' },
1414
{section: 'blog', text: 'Blog', href: '/blog/' },
1515
{section: 'help', text: 'Help', href: '/help/' },
1616
{section: 'code', text: 'Code', href: '/code/' },
17+
],
18+
linksExternal: [
1719
{section: 'spec', text: 'Spec', href: 'http://facebook.github.io/graphql/' },
1820
],
1921

22+
renderLinks: function(links) {
23+
return links.map(function(link) {
24+
return (
25+
<li key={link.section}>
26+
<a
27+
href={link.href}
28+
target={link.href.slice(0, 4) === 'http' ? '_blank' : null}
29+
className={link.section === this.props.section ? 'active' : ''}>
30+
{link.text}
31+
</a>
32+
</li>
33+
);
34+
}, this);
35+
},
36+
2037
render: function() {
2138
return (
22-
<ul className="nav-site">
23-
{this.links.map(function(link) {
24-
return (
25-
<li key={link.section}>
26-
<a
27-
href={link.href}
28-
target={link.href.slice(0, 4) === 'http' ? '_blank' : null}
29-
className={link.section === this.props.section ? 'active' : ''}>
30-
{link.text}
31-
</a>
32-
</li>
33-
);
34-
}, this)}
35-
</ul>
39+
<div className="nav-site-wrapper">
40+
<ul className="nav-site nav-site-internal">
41+
{this.renderLinks(this.linksInternal)}
42+
</ul>
43+
44+
<div className="algolia-search-wrapper">
45+
<input id="algolia-doc-search" type="text" placeholder="Search docs..." />
46+
</div>
47+
48+
<ul className="nav-site nav-site-external">
49+
{this.renderLinks(this.linksExternal)}
50+
</ul>
51+
</div>
3652
);
3753
}
3854
});

site/_core/Site.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var Site = React.createClass({
2525
<meta property="og:url" content="http://graphql.org/" />
2626
<meta property="og:description" content={SiteData.description} />
2727

28+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css" />
2829
<link rel="shortcut icon" href={'/img/favicon.png'} />
2930
<link rel="stylesheet" href={'/css/graphql.css'} />
3031

@@ -53,8 +54,14 @@ var Site = React.createClass({
5354

5455
<div id="fb-root" />
5556

57+
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
5658
<script dangerouslySetInnerHTML={{__html: `
5759
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
60+
docsearch({
61+
apiKey: 'd103541f3e6041148aade2e746ed4d61',
62+
indexName: 'graphql',
63+
inputSelector: '#algolia-doc-search'
64+
});
5865
`}} />
5966
</body>
6067
</html>

site/css/graphql.css

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,15 @@ h1:hover .hash-link, h2:hover .hash-link, h3:hover .hash-link, h4:hover .hash-li
219219
text-decoration: none;
220220
}
221221

222-
.nav-main .nav-site {
222+
.nav-main .nav-site-wrapper {
223+
display: inline;
224+
}
225+
226+
.nav-main .nav-site-internal {
227+
margin: 0 0 0 20px;
228+
}
229+
230+
.nav-main .nav-site-external {
223231
float: right;
224232
margin: 0;
225233
}
@@ -1970,3 +1978,69 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {
19701978
-webkit-box-sizing: border-box;
19711979
box-sizing: border-box;
19721980
}
1981+
1982+
/** Algolia Doc Search **/
1983+
1984+
div.algolia-search-wrapper {
1985+
display: inline-block;
1986+
vertical-align: top;
1987+
margin-left: 15px;
1988+
}
1989+
1990+
.algolia-autocomplete .aa-dropdown-menu {
1991+
margin-left: -110px;
1992+
margin-top: -4px;
1993+
}
1994+
1995+
@media screen and (max-width: 960px) {
1996+
div.algolia-search-wrapper {
1997+
display: none;
1998+
}
1999+
}
2000+
2001+
input#algolia-doc-search {
2002+
background: transparent url('../img/search.png') no-repeat 10px center;
2003+
background-size: 16px 16px;
2004+
2005+
padding: 0 10px;
2006+
padding-left: 35px;
2007+
margin-top: 12px;
2008+
height: 30px;
2009+
font-size: 16px;
2010+
line-height: 20px;
2011+
background-color: #555;
2012+
border-radius: 4px;
2013+
color: white;
2014+
outline: none;
2015+
border: none;
2016+
width: 170px;
2017+
}
2018+
2019+
.algolia-autocomplete {
2020+
vertical-align: top;
2021+
height: 53px;
2022+
}
2023+
2024+
.algolia-docsearch-suggestion--category-header {
2025+
background-color: #B51780;
2026+
}
2027+
.algolia-docsearch-suggestion--highlight {
2028+
color: #E535AB;
2029+
}
2030+
.algolia-docsearch-suggestion--category-header .algolia-docsearch-suggestion--highlight {
2031+
background-color: #E535AB;
2032+
}
2033+
.aa-cursor .algolia-docsearch-suggestion--content {
2034+
color: #E535AB;
2035+
}
2036+
.aa-cursor .algolia-docsearch-suggestion {
2037+
background: #FEF6FB;
2038+
}
2039+
.algolia-docsearch-suggestion {
2040+
border-bottom-color: #FEF6FB;
2041+
}
2042+
.algolia-docsearch-suggestion--subcategory-column {
2043+
border-right-color: #FEF6FB;
2044+
background-color: #FEF6FB;
2045+
color: #E535AB;
2046+
}

site/img/search.png

1.35 KB
Loading

0 commit comments

Comments
 (0)