feat: use updated and dynamic error codes for support pages

This commit is contained in:
Jonathan Barrow
2024-05-01 17:20:35 -04:00
parent 7e1c746bd6
commit 5bd21a3d3e
6 changed files with 92 additions and 27 deletions

View File

@@ -45,12 +45,11 @@
<p>{{ locale.docs.search.caption }}</p>
<label for="errorCode">{{ locale.docs.search.label }}</label>
<div class="input-wrapper">
<input id="errorCode" placeholder="ABC-012-3456" required />
<input id="errorCode" placeholder="012-3456" required />
<div class="matches">
</div>
</div>
</div>
</div>
</div>
</div>
@@ -58,30 +57,14 @@
{{#section 'foot'}}
<script src="/assets/js/docssidebarhandler.js"></script>
<script id="errorList" type="application/json">
{{{errorList}}}
</script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.6.2/dist/fuse.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cleave.js@1.6.0/dist/cleave.min.js"></script>
<script>
// Get the error list from the script tag
let rawErrorList = JSON.parse(document.getElementById('errorList').innerHTML);
// Convert the error list to a single flat array
rawErrorList = Object.values(rawErrorList).flat();
// We remove the unknown characters (e.g. the X in JXT-598-2XXX), so fuse.js will be able to match the error codes
const errorList = rawErrorList.map(error => {
return error.replace(/X*$/g, '');
});
const fuse = new Fuse(errorList, {includeMatches: true, threshold: 0.4});
const fuse = new Fuse({{{errorList}}}, {includeMatches: true, threshold: 0.4});
const cleave = new Cleave('input#errorCode', {
delimiter: '-',
blocks: [3, 3, 4],
uppercase: true
blocks: [3, 4]
});
const matchesContainer = document.querySelector('.matches');
@@ -102,10 +85,10 @@
if (matches.length > 0) {
matches.forEach(match => {
const errorCode = match.item.padEnd(12, 'X');
const errorCode = match.item;
const matchLink = document.createElement('a');
matchLink.innerText = errorCode;
matchLink.href = `/docs/errors/${errorCode}`;
matchLink.href = `/docs/error/${errorCode}`;
matchesContainer.appendChild(matchLink);
});
} else {