Skip to content

Commit 1f830bf

Browse files
Merge pull request circleci#3767 from tfe/i18n-search
Enable multi-language search
2 parents 332c311 + 0f61e3f commit 1f830bf

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

jekyll/_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ plugins:
1616

1717
algolia:
1818
application_id: U0RXNGRK45
19+
api_key: dd49f5b81d238d474b49645a4daed322 # search-only API Key; safe for front-end code
1920
index_name: documentation
2021
settings:
2122
highlightPreTag: '<strong>'

jekyll/_includes/js-config.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script type="text/javascript">
2+
window.circleJsConfig = {
3+
algolia: {
4+
appId: {{ site.algolia.application_id | jsonify }},
5+
apiKey: {{ site.algolia.api_key | jsonify }},
6+
indexName: {{ site.algolia.index_name | jsonify }}
7+
},
8+
page: {
9+
lang: {{ page.lang | jsonify }}
10+
}
11+
}
12+
</script>

jekyll/_layouts/classic-docs.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ <h2>Search Results for "<span id="search-term-display"></span>"</h2>
3737
</div><!-- .article-container -->
3838
</div><!-- .main-body -->
3939
{% include global-footer.html %}
40+
{% include js-config.html %}
4041
{% asset vendor.min.js %}
4142
<script>
4243
var _rollbarConfig = {

src-js/instantsearch.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import * as debounce from 'lodash.debounce';
22
import * as get from 'lodash.get';
33

4+
const ALGOLIA_APP_ID = window.circleJsConfig.algolia.appId;
5+
const ALGOLIA_API_KEY = window.circleJsConfig.algolia.apiKey;
6+
const ALGOLIA_INDEX_NAME = window.circleJsConfig.algolia.indexName;
7+
const ALGOLIA_COLLECTION = ((lang) => {
8+
// Page language is default language or missing, use default collection
9+
if (typeof lang !== 'string' || lang === 'en') {
10+
return 'cci2';
11+
} else {
12+
return `cci2_${lang}`;
13+
}
14+
})(get(window.circleJsConfig, 'page.lang'));
15+
416
const formatResultSnippet = (snippet) => {
517
const title = get(snippet, ['title', 'value'], '(untitled)');
618
const content = get(snippet, ['content', 'value'], '');
@@ -14,17 +26,17 @@ const formatResultSnippet = (snippet) => {
1426
// Instant search initialization
1527
export function init () {
1628
var search = instantsearch({
17-
appId: 'U0RXNGRK45',
18-
apiKey: 'dd49f5b81d238d474b49645a4daed322', // search-only API Key; safe for front-end code
19-
indexName: 'documentation',
29+
appId: ALGOLIA_APP_ID,
30+
apiKey: ALGOLIA_API_KEY,
31+
indexName: ALGOLIA_INDEX_NAME,
2032
routing: true,
2133
searchParameters: { hitsPerPage: 25 }
2234
});
2335

2436
// adding conditions to filter search
2537
search.addWidget(
2638
instantsearch.widgets.configure({
27-
filters: "collection: cci2"
39+
filters: `collection: ${ALGOLIA_COLLECTION}`
2840
})
2941
);
3042

0 commit comments

Comments
 (0)