|
13 | 13 | <script src="/js/smooth-scroll.js"></script>
|
14 | 14 | <link href="/css/doc-theme.css?" rel="stylesheet">
|
15 | 15 | <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" /> |
16 | 18 | </head>
|
17 | 19 | <body>
|
18 | 20 | </script>
|
|
32 | 34 | <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
|
33 | 35 | <script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.13/vuetify.min.js"></script>
|
34 | 36 | <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> |
35 | 38 | <script>
|
36 | 39 | var app = new Vue({
|
37 | 40 | el: '#app',
|
38 | 41 | data: {
|
39 | 42 | page: 1,
|
40 | 43 | pageCount: 0,
|
41 |
| - q: null, |
42 | 44 | error: null,
|
43 | 45 | results: null,
|
44 | 46 | drawer: true,
|
|
67 | 69 |
|
68 | 70 | }, 3500);
|
69 | 71 | }
|
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 |
| - } |
76 | 72 | var elem2 = document.getElementById("vuetify-theme-stylesheet");
|
77 | 73 | elem2.parentNode.removeChild(elem2);
|
78 | 74 |
|
79 | 75 | },
|
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 |
| - }, |
126 | 76 | watch: {
|
127 | 77 | // whenever question changes, this function will run
|
128 | 78 | branch: function (newb, old) {
|
129 | 79 | if (newb.value != this.branches[0].value) {
|
130 | 80 | window.location = newb + window.location.pathname
|
131 | 81 | }
|
132 | 82 | },
|
133 |
| - |
134 | 83 | },
|
135 | 84 | });
|
136 | 85 |
|
| 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 | + }); |
137 | 93 | </script>
|
138 | 94 |
|
139 | 95 | {{- partial "alexia.html" . -}}
|
|
0 commit comments