Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSarah German <sgerman@gitlab.com>2022-07-28 01:07:20 +0300
committerSarah German <sgerman@gitlab.com>2022-08-20 00:34:59 +0300
commit94e214de7150a5c0b04a6bb12e0f496248568c39 (patch)
tree85aa3f7e4e75517c7fe8ee72b2756be8331acba7
parent9e545e18ed5dbab19a7c3048ecf19e16d2015054 (diff)
Consolidate Algolia configurationalgolia-shared-config
-rw-r--r--content/frontend/search/components/search_page.vue10
-rw-r--r--content/frontend/search/docsearch.js9
-rw-r--r--content/frontend/search/instantsearch.js4
-rw-r--r--content/frontend/search/search.js23
-rw-r--r--spec/frontend/search/search_spec.js2
5 files changed, 39 insertions, 9 deletions
diff --git a/content/frontend/search/components/search_page.vue b/content/frontend/search/components/search_page.vue
index ad194185..7c16a2e6 100644
--- a/content/frontend/search/components/search_page.vue
+++ b/content/frontend/search/components/search_page.vue
@@ -10,6 +10,10 @@ export default {
GlIcon,
},
props: {
+ algoliaCredentials: {
+ type: Object,
+ required: true,
+ },
docsVersion: {
type: String,
required: true,
@@ -17,10 +21,10 @@ export default {
},
data() {
return {
- searchClient: algoliasearch('3PNCFOU757', '89b85ffae982a7f1adeeed4a90bb0ab1'),
+ searchClient: algoliasearch(this.algoliaCredentials.appId, this.algoliaCredentials.apiKey),
routing: {
router: historyRouter(),
- stateMapping: singleIndexMapping('gitlab'),
+ stateMapping: singleIndexMapping(this.algoliaCredentials.index),
},
};
},
@@ -30,7 +34,7 @@ export default {
<template>
<ais-instant-search
:search-client="searchClient"
- index-name="gitlab"
+ :index-name="algoliaCredentials.index"
:routing="routing"
:stalled-search-delay="500"
class="gl-pb-8"
diff --git a/content/frontend/search/docsearch.js b/content/frontend/search/docsearch.js
index e01ab696..97601cf9 100644
--- a/content/frontend/search/docsearch.js
+++ b/content/frontend/search/docsearch.js
@@ -1,16 +1,17 @@
import docsearch from '@docsearch/js';
import '@docsearch/css';
-import { getDocsVersion } from './search';
+import { getAlgoliaCredentials, getDocsVersion } from './search';
document.addEventListener('DOMContentLoaded', () => {
const docsVersion = getDocsVersion();
+ const algoliaCredentials = getAlgoliaCredentials();
// eslint-disable-next-line no-undef
docsearch({
- apiKey: '89b85ffae982a7f1adeeed4a90bb0ab1',
- indexName: 'gitlab',
+ apiKey: algoliaCredentials.apiKey,
+ indexName: algoliaCredentials.index,
container: '#docsearch',
- appId: '3PNCFOU757',
+ appId: algoliaCredentials.appId,
placeholder: 'Search the docs',
searchParameters: {
facetFilters: [`version:${docsVersion}`],
diff --git a/content/frontend/search/instantsearch.js b/content/frontend/search/instantsearch.js
index 64bd9f9a..1f26ad11 100644
--- a/content/frontend/search/instantsearch.js
+++ b/content/frontend/search/instantsearch.js
@@ -9,7 +9,7 @@ import {
AisConfigure,
} from 'vue-instantsearch';
import SearchPage from './components/search_page.vue';
-import { getDocsVersion } from './search';
+import { getAlgoliaCredentials, getDocsVersion } from './search';
Vue.component(AisInstantSearch.name, AisInstantSearch);
Vue.component(AisSearchBox.name, AisSearchBox);
@@ -19,6 +19,7 @@ Vue.component(AisPoweredBy.name, AisPoweredBy);
Vue.component(AisInfiniteHits.name, AisInfiniteHits);
Vue.component(AisConfigure.name, AisConfigure);
+const algoliaCredentials = getAlgoliaCredentials();
const docsVersion = getDocsVersion();
document.addEventListener('DOMContentLoaded', () => {
@@ -27,6 +28,7 @@ document.addEventListener('DOMContentLoaded', () => {
render(createElement) {
return createElement(SearchPage, {
props: {
+ algoliaCredentials,
docsVersion,
},
});
diff --git a/content/frontend/search/search.js b/content/frontend/search/search.js
index 5ea8a87a..ab202445 100644
--- a/content/frontend/search/search.js
+++ b/content/frontend/search/search.js
@@ -2,6 +2,29 @@
* Functions used by both DocSearch and InstantSearch.
*/
+export const algoliaAccounts = {
+ production: {
+ apiKey: '89b85ffae982a7f1adeeed4a90bb0ab1',
+ appId: '3PNCFOU757',
+ index: 'gitlab',
+ },
+ testing: {
+ apiKey: '181a86cec565045e1851b68cd9b4a7d3',
+ appId: '3PNCFOU757',
+ index: 'gitlab_testing',
+ },
+};
+
+/**
+ * Loads Algolia connection info for a given Crawler.
+ *
+ * Set the crawler default to 'testing' in order to use
+ * the gitlab_testing index. (Don't forget to change it back!)
+ */
+export const getAlgoliaCredentials = (crawler = 'production') => {
+ return algoliaAccounts[crawler];
+};
+
export const getDocsVersion = () => {
let docsVersion = 'main';
if (document.querySelector('meta[name="docsearch:version"]').content.length > 0) {
diff --git a/spec/frontend/search/search_spec.js b/spec/frontend/search/search_spec.js
index e009fdf4..2d80473d 100644
--- a/spec/frontend/search/search_spec.js
+++ b/spec/frontend/search/search_spec.js
@@ -5,7 +5,7 @@
import { mount } from '@vue/test-utils';
import SearchPage from '../../../content/frontend/search/components/search_page.vue';
-const propsData = { docsVersion: 'main' };
+const propsData = { docsVersion: 'main', algoliaCredentials: {} };
const searchFormSelector = '[data-testid="docs-search"]';
describe('component: Search page', () => {