Skip to content

Commit ab90848

Browse files
committed
feat: google search replaced with algolia search
- removed google search code from vuejs - added algolia docs search scripts
1 parent c8beeb9 commit ab90848

File tree

2 files changed

+11
-61
lines changed

2 files changed

+11
-61
lines changed

layouts/_default/baseof.html

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<script src="/js/smooth-scroll.js"></script>
1414
<link href="/css/doc-theme.css?" rel="stylesheet">
1515
<link rel="icon" href="/favicon.ico">
16+
<!-- Algolia Docs Search -->
17+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
1618
</head>
1719
<body>
1820
</script>
@@ -32,13 +34,13 @@
3234
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
3335
<script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.13/vuetify.min.js"></script>
3436
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/1.5.1/vue-resource.min.js"></script>
37+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
3538
<script>
3639
var app = new Vue({
3740
el: '#app',
3841
data: {
3942
page: 1,
4043
pageCount: 0,
41-
q: null,
4244
error: null,
4345
results: null,
4446
drawer: true,
@@ -67,73 +69,27 @@
6769

6870
}, 3500);
6971
}
70-
// we use a /search/ page essentially to generate/store a browser
71-
// history, if in search page, query results
72-
if (document.location.pathname === "/search/") {
73-
this.q = decodeURI(window.location.search.split("=")[1])
74-
this.fetchResults (this.q)
75-
}
7672
var elem2 = document.getElementById("vuetify-theme-stylesheet");
7773
elem2.parentNode.removeChild(elem2);
7874

7975
},
80-
methods: {
81-
handleGoogleError() {
82-
const q = 'site:docs.pycom.io ' + this.q;
83-
const loc = encodeURI('https://bing.com?q=' + q)
84-
window.location = loc
85-
},
86-
navResult (url) {
87-
window.location = url;
88-
},
89-
fetchResults (kw, start) {
90-
if (!start) { start = 1 }
91-
let key = "AIzaSyCDyOKwSjrgE_tkSbO0kbI8Omc6VZMwqA8";
92-
let cx = "000185904715529159933:pfyw5o4foii";
93-
let url = "https://www.googleapis.com/customsearch/v1";
94-
url = url + "?cx=" + cx + "&key=" + key + "&q=" + encodeURI(kw) + "&start=" + start
95-
96-
this.$http.get(url).then((res) => {
97-
if (res.data) {
98-
this.results = res.data
99-
this.page = Math.trunc(res.data.queries.request[0].startIndex /10) + 1
100-
// Mmm ... Google result number is varying accross page ....
101-
this.pageCount = Math.min(10, Math.trunc(res.data.searchInformation.totalResults/10) + 1)
102-
} else {
103-
this.handleGoogleError();
104-
this.results = null;
105-
}
106-
}, response => {
107-
this.results = null;
108-
console.log(response)
109-
this.handleGoogleError();
110-
this.error = { status: response.error, message: response.text }
111-
// ====
112-
})
113-
},
114-
search(p) {
115-
window.location = '/search/?q=' + encodeURI(this.q)
116-
},
117-
pageClicked(p) {
118-
event.stopPropagation()
119-
event.preventDefault()
120-
this.$nextTick(() => {
121-
const start = ((this.page - 1) * 10) + 1
122-
this.fetchResults(this.q, start)
123-
})
124-
},
125-
},
12676
watch: {
12777
// whenever question changes, this function will run
12878
branch: function (newb, old) {
12979
if (newb.value != this.branches[0].value) {
13080
window.location = newb + window.location.pathname
13181
}
13282
},
133-
13483
},
13584
});
13685

86+
// initialize Algolia doc search
87+
docsearch({
88+
apiKey: 'a99fde9999fbec81c1772eb9ffcca488',
89+
indexName: 'pycom',
90+
inputSelector: '.algolia-search-field input',
91+
debug: false // Set debug to true if you want to inspect the dropdown
92+
});
13793
</script>
13894

13995
{{- partial "alexia.html" . -}}

themes/doc-theme/layouts/partials/menu.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@
55
class="lighten-4 pt-0"
66
style="overflow-y: hidden; overflow-x: hidden;margin-top:70px;"
77
>
8-
<!--<v-container style="height: 68px; background-color: rgb(23, 23, 48);" class="dark mb-0 pb-1 pt-3 elevation-5 " >
9-
<v-img class="ml-4" height=48 width=190 src="/logo.svg">
10-
</v-container>-->
118

129
<v-container class="ma-0 pa-0 elevation-1">
1310

1411
<v-text-field
15-
v-model="q"
1612
style="width: 100%;"
17-
@change="search"
18-
@click:append="search"
19-
class="grey lighten-5 mt-0 mr-2 pa-3 ma-0 mono"
13+
class="grey lighten-5 mt-0 mr-2 pa-3 ma-0 mono algolia-search-field"
2014
light
2115
hide-details
2216
append-icon="search"

0 commit comments

Comments
 (0)