Skip to content

feat: change coveo key based on build environment #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 37 additions & 36 deletions assets/js/coveo.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import * as params from '@params';
document.addEventListener('DOMContentLoaded', function () {
Coveo.SearchEndpoint.configureCloudV2Endpoint("", 'xx79df1e1f-11e4-4da5-8ea8-2ed7e24cca6a'); // Prod API key
// Coveo.SearchEndpoint.configureCloudV2Endpoint("", 'xxe1e9046f-585c-4518-a14a-6b986a5efffd'); // test API key
const root = document.getElementById("search");
const searchBoxRoot = document.getElementById("searchbox");
Coveo.initSearchbox(searchBoxRoot, "/search.html");
var resetbtn = document.querySelector('#reset_btn');
if (resetbtn) {
resetbtn.onclick = function () {
document.querySelector('.coveo-facet-header-eraser').click();
};
}
Coveo.$$(root).on("querySuccess", function (e, args) {
resetbtn.style.display = "block";
});
Coveo.$$(root).on('afterComponentsInitialization', function (e, data) {
setTimeout(function () {
document.querySelector('.CoveoOmnibox input').value = Coveo.state(root, 'q');
}, 1000);
});
Coveo.$('#search').on("newResultsDisplayed", function (e, args) {
for (var i = 0; i < e.target.lastChild.children.length; i++) {
//Remove the title for tooltip box
Coveo.$('.CoveoResultLink').removeAttr('title');
Coveo.SearchEndpoint.configureCloudV2Endpoint("", params.coveokey);
const root = document.getElementById("search");
const searchBoxRoot = document.getElementById("searchbox");
Coveo.initSearchbox(searchBoxRoot, "/search.html");
var resetbtn = document.querySelector('#reset_btn');
if (resetbtn) {
resetbtn.onclick = function () {
document.querySelector('.coveo-facet-header-eraser').click();
};
}
});
Coveo.init(root, {
f5_product_module: {
dependsOn: "@f5_product",
dependsOnCondition: (parentFacet) => {
const id = parentFacet.options.id;
const value = "NGINX Management Suite";
const selected = parentFacet.queryStateModel.get(`f:${id}`)
return selected.includes(value);
Coveo.$$(root).on("querySuccess", function (e, args) {
resetbtn.style.display = "block";
});
Coveo.$$(root).on('afterComponentsInitialization', function (e, data) {
setTimeout(function () {
document.querySelector('.CoveoOmnibox input').value = Coveo.state(root, 'q');
}, 1000);
});
Coveo.$('#search').on("newResultsDisplayed", function (e, args) {
for (var i = 0; i < e.target.lastChild.children.length; i++) {
//Remove the title for tooltip box
Coveo.$('.CoveoResultLink').removeAttr('title');
}
}
});
})

});
Coveo.init(root, {
f5_product_module: {
dependsOn: "@f5_product",
dependsOnCondition: (parentFacet) => {
const id = parentFacet.options.id;
const value = "NGINX Management Suite";
const selected = parentFacet.queryStateModel.get(`f:${id}`)
return selected.includes(value);
}
}
});
})


23 changes: 18 additions & 5 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,31 @@
<script src="{{ $jsBootstrap.RelPermalink }}" type="text/javascript" integrity="{{ $jsBootstrap.Data.Integrity }}"></script>


{{ if ( not ( in .Site.Params.buildtype "package" ) ) }}

<!-- START COVEO -->
<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>

<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>

{{ $coveo := resources.Get "js/coveo.js" }}
{{ $secureCoveo := $coveo | minify | fingerprint "sha512" }}
<!-- build a different coveo.js (with different key) based on build env -->

{{ $.Scratch.Set "coveoSc" "" }}
{{ if eq hugo.Environment "production" }}
{{- $coveo := resources.Get "js/coveo.js" | js.Build ( dict "params" ( dict "coveokey" "xx79df1e1f-11e4-4da5-8ea8-2ed7e24cca6a" )) -}}
{{ $.Scratch.Set "coveoSc" $coveo}}
{{ else if eq hugo.Environment "staging" }}
{{- $coveo := resources.Get "js/coveo.js" | js.Build ( dict "params" ( dict "coveokey" "xxdb89e3ea-5468-4e34-824f-91cf8b004b66" )) -}}
{{ $.Scratch.Set "coveoSc" $coveo}}
{{ else }}
{{- $coveo := resources.Get "js/coveo.js" | js.Build ( dict "params" ( dict "coveokey" "xxe1e9046f-585c-4518-a14a-6b986a5efffd" )) -}}
{{ $.Scratch.Set "coveoSc" $coveo}}
{{ end }}
{{ $secureCoveo := $.Scratch.Get "coveoSc" | minify | fingerprint "sha512" }}


<script src="{{ $secureCoveo.RelPermalink }}" integrity="{{ $secureCoveo.Data.Integrity }}" type="text/javascript"></script>

<!-- END COVEO -->
{{ end }}


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