Skip to content

Commit 2611af6

Browse files
JTorreGADubhlaoich
andauthored
feat: change coveo key based on build environment (#12)
* feat: change coveo key based on build environment * fix: add staging * fix: update staging key * fix: simplified code duplication --------- Co-authored-by: Alan Dooley <[email protected]>
1 parent 730e194 commit 2611af6

File tree

2 files changed

+55
-41
lines changed

2 files changed

+55
-41
lines changed

assets/js/coveo.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1+
import * as params from '@params';
12
document.addEventListener('DOMContentLoaded', function () {
2-
Coveo.SearchEndpoint.configureCloudV2Endpoint("", 'xx79df1e1f-11e4-4da5-8ea8-2ed7e24cca6a'); // Prod API key
3-
// Coveo.SearchEndpoint.configureCloudV2Endpoint("", 'xxe1e9046f-585c-4518-a14a-6b986a5efffd'); // test API key
4-
const root = document.getElementById("search");
5-
const searchBoxRoot = document.getElementById("searchbox");
6-
Coveo.initSearchbox(searchBoxRoot, "/search.html");
7-
var resetbtn = document.querySelector('#reset_btn');
8-
if (resetbtn) {
9-
resetbtn.onclick = function () {
10-
document.querySelector('.coveo-facet-header-eraser').click();
11-
};
12-
}
13-
Coveo.$$(root).on("querySuccess", function (e, args) {
14-
resetbtn.style.display = "block";
15-
});
16-
Coveo.$$(root).on('afterComponentsInitialization', function (e, data) {
17-
setTimeout(function () {
18-
document.querySelector('.CoveoOmnibox input').value = Coveo.state(root, 'q');
19-
}, 1000);
20-
});
21-
Coveo.$('#search').on("newResultsDisplayed", function (e, args) {
22-
for (var i = 0; i < e.target.lastChild.children.length; i++) {
23-
//Remove the title for tooltip box
24-
Coveo.$('.CoveoResultLink').removeAttr('title');
3+
Coveo.SearchEndpoint.configureCloudV2Endpoint("", params.coveokey);
4+
const root = document.getElementById("search");
5+
const searchBoxRoot = document.getElementById("searchbox");
6+
Coveo.initSearchbox(searchBoxRoot, "/search.html");
7+
var resetbtn = document.querySelector('#reset_btn');
8+
if (resetbtn) {
9+
resetbtn.onclick = function () {
10+
document.querySelector('.coveo-facet-header-eraser').click();
11+
};
2512
}
26-
});
27-
Coveo.init(root, {
28-
f5_product_module: {
29-
dependsOn: "@f5_product",
30-
dependsOnCondition: (parentFacet) => {
31-
const id = parentFacet.options.id;
32-
const value = "NGINX Management Suite";
33-
const selected = parentFacet.queryStateModel.get(`f:${id}`)
34-
return selected.includes(value);
13+
Coveo.$$(root).on("querySuccess", function (e, args) {
14+
resetbtn.style.display = "block";
15+
});
16+
Coveo.$$(root).on('afterComponentsInitialization', function (e, data) {
17+
setTimeout(function () {
18+
document.querySelector('.CoveoOmnibox input').value = Coveo.state(root, 'q');
19+
}, 1000);
20+
});
21+
Coveo.$('#search').on("newResultsDisplayed", function (e, args) {
22+
for (var i = 0; i < e.target.lastChild.children.length; i++) {
23+
//Remove the title for tooltip box
24+
Coveo.$('.CoveoResultLink').removeAttr('title');
3525
}
36-
}
37-
});
38-
})
39-
26+
});
27+
Coveo.init(root, {
28+
f5_product_module: {
29+
dependsOn: "@f5_product",
30+
dependsOnCondition: (parentFacet) => {
31+
const id = parentFacet.options.id;
32+
const value = "NGINX Management Suite";
33+
const selected = parentFacet.queryStateModel.get(`f:${id}`)
34+
return selected.includes(value);
35+
}
36+
}
37+
});
38+
})
39+
40+

layouts/partials/scripts.html

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,31 @@
1111
<script src="{{ $jsBootstrap.RelPermalink }}" type="text/javascript" integrity="{{ $jsBootstrap.Data.Integrity }}"></script>
1212

1313

14-
{{ if ( not ( in .Site.Params.buildtype "package" ) ) }}
14+
1515
<!-- START COVEO -->
1616
<script class="coveo-script" src="https://static.cloud.coveo.com/searchui/v2.10104/0/js/CoveoJsSearch.Lazy.min.js" integrity="sha512-HxdDBIp5snbqtu1TPkBnXLKEvN9IPz3PeZW8zT9KfsflV9Ck822XDroDlpVbfCfXeiu8C0RDVn0fdu7aGy/H1g==" crossorigin="anonymous"></script>
1717

1818
<script src="https://static.cloud.coveo.com/searchui/v2.10104/0/js/templates/templates.js" integrity="sha512-CR0Yk/LIwgh1MsKqjecDp/r6F9ipKc6gA+4+E1pplT3N3r1pk+la/HaqyDiKtjOFwrwIIbIYBFrUJgPql93QHw==" crossorigin="anonymous"></script>
1919

20-
{{ $coveo := resources.Get "js/coveo.js" }}
21-
{{ $secureCoveo := $coveo | minify | fingerprint "sha512" }}
20+
<!-- build a different coveo.js (with different key) based on build env -->
21+
22+
{{ $.Scratch.Set "coveoSc" "" }}
23+
{{ if eq hugo.Environment "production" }}
24+
{{- $coveo := resources.Get "js/coveo.js" | js.Build ( dict "params" ( dict "coveokey" "xx79df1e1f-11e4-4da5-8ea8-2ed7e24cca6a" )) -}}
25+
{{ $.Scratch.Set "coveoSc" $coveo}}
26+
{{ else if eq hugo.Environment "staging" }}
27+
{{- $coveo := resources.Get "js/coveo.js" | js.Build ( dict "params" ( dict "coveokey" "xxdb89e3ea-5468-4e34-824f-91cf8b004b66" )) -}}
28+
{{ $.Scratch.Set "coveoSc" $coveo}}
29+
{{ else }}
30+
{{- $coveo := resources.Get "js/coveo.js" | js.Build ( dict "params" ( dict "coveokey" "xxe1e9046f-585c-4518-a14a-6b986a5efffd" )) -}}
31+
{{ $.Scratch.Set "coveoSc" $coveo}}
32+
{{ end }}
33+
{{ $secureCoveo := $.Scratch.Get "coveoSc" | minify | fingerprint "sha512" }}
34+
35+
2236
<script src="{{ $secureCoveo.RelPermalink }}" integrity="{{ $secureCoveo.Data.Integrity }}" type="text/javascript"></script>
2337

24-
<!-- END COVEO -->
25-
{{ end }}
38+
2639

2740
<!-- Load the Redoc resources if we're not using Dev Portal for the API reference layout-->
2841
{{ if not ( eq .Site.Params.useDevPortal true ) }}

0 commit comments

Comments
 (0)