Skip to content

Commit

Permalink
chore: add internal mapping of category names
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderleegs committed Aug 18, 2024
1 parent d9303c8 commit 8b2bc22
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
4 changes: 2 additions & 2 deletions _includes/main_scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@
<link rel="stylesheet" href="{{- site.baseurl -}}/assets/css/algolia.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js" integrity="sha256-DABVk+hYj0mdUzo+7ViJC6cwLahQIejFvC+my2M/wfM=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch.production.min.js" integrity="sha256-9242vN47QUX50UG5Gf5XDO1YREWCEJRyXHofh5fsl24=" crossorigin="anonymous"></script>
<script src="{{- "/assets/js/algolia-search.js" | relative_url -}}" crossorigin="anonymous"></script>
<script type="module" src="{{- "/assets/js/algolia-search.js" | relative_url -}}" crossorigin="anonymous"></script>
{%- endif -%}

{%- if page.layout == 'egazette-search-landing' -%}
<link rel="stylesheet" href="{{- site.baseurl -}}/assets/css/algolia.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js" integrity="sha256-DABVk+hYj0mdUzo+7ViJC6cwLahQIejFvC+my2M/wfM=" crossorigin="anonymous"></script>
<script src="{{- "/assets/js/algolia-search-landing.js" | relative_url -}}" crossorigin="anonymous"></script>
<script type="module" src="{{- "/assets/js/algolia-search-landing.js" | relative_url -}}" crossorigin="anonymous"></script>
{%- endif -%}

{%- include chatbot-scripts.html -%}
Expand Down
2 changes: 1 addition & 1 deletion _layouts/egazette-search-landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h2 class="h2 pb-3"><b>{{- page.title -}}</b></h2>
<div>
<div class="algolia-search-category-item">
<input id="category-legislative" type="checkbox" data-category="category" value="Legislative Supplements">
<label for="category-legislative"><b>Legislative Supplements</b></label>
<label for="category-legislative"><b>Legislation Supplements</b></label>
</div>
<div id="legislative-supplements" class="pl-7"></div>
</div>
Expand Down
31 changes: 31 additions & 0 deletions assets/js/algolia-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const CATEGORY_INTERNAL_MAPPING = {
"Government Gazette": "Government Gazette",
"Legislative Supplements": "Legislation Supplements",
"Other Supplements": "Other Supplements",
"Advertisements": "Advertisements",
"Appointments": "Appointments",
"Audited Reports": "Audited Reports",
"Cessation of Service": "Cessation of Service",
"Corrigendum": "Corrigendum",
"Death": "Death",
"Dismissals": "Dismissals",
"Leave": "Leave",
"Bankruptcy Act Notice": "Notices (Bankruptcy Act)",
"Companies Act Notice": "Notices (Companies Act)",
"Notices under the Constitution": "Notices (Constitution)",
"Notices under other Acts": "Notices (other Acts)",
"Revocation": "Revocation",
"Tenders": "Tenders",
"Termination of Service": "Termination of Service",
"Vacation of Service": "Vacation of Service",
"Others": "Others",
"Bills Supplement": "Bills Supplement",
"Acts Supplement": "Acts Supplement",
"Subsidiary Legislation Supplement": "Subsidiary Legislation Supplement",
"Revised Acts": "Revised Acts",
"Revised Subsidiary Legislation": "Revised Subsidiary Legislation",
"Government Gazette Supplement": "Government Gazette Supplement",
"Industrial Relations Supplement": "Industrial Relations Supplement",
"Trade Marks Supplement": "Trade Marks Supplement",
"Treaties Supplement": "Treaties Supplement"
}
4 changes: 3 additions & 1 deletion assets/js/algolia-search-landing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CATEGORY_INTERNAL_MAPPING } from "./algolia-constants.js";

const searchClient = algoliasearch(
"1V7DZGZJKK",
"0ba2c5f100ff5fd004415e4abbcf9b9c"
Expand Down Expand Up @@ -44,7 +46,7 @@ function createCheckboxes(container, categories, searchCategoryName) {
checkbox.dataset.category = searchCategoryName
const label = document.createElement('label');
label.htmlFor = checkbox.id;
label.textContent = categoryItem;
label.textContent = CATEGORY_INTERNAL_MAPPING[categoryItem];
container.appendChild(itemWrapper)
itemWrapper.appendChild(checkbox);
itemWrapper.appendChild(label);
Expand Down
20 changes: 16 additions & 4 deletions assets/js/algolia-search.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CATEGORY_INTERNAL_MAPPING } from "./algolia-constants.js";

const searchClient = algoliasearch(
"1V7DZGZJKK",
"0ba2c5f100ff5fd004415e4abbcf9b9c"
Expand Down Expand Up @@ -131,7 +133,8 @@ search.addWidgets([
// Map all possible values to their corresponding item or a default item with count 0
const orderedItems = categories.map(value => {
if (currentItemsMap.has(value)) {
return currentItemsMap.get(value)
const adjustedMapping = { ...currentItemsMap.get(value), highlighted: CATEGORY_INTERNAL_MAPPING[value] }
return adjustedMapping
} else if (selectedCategories.includes(value)) {
return { highlighted:value, value, label: value, count: 0, isRefined: true }
}
Expand All @@ -158,11 +161,11 @@ search.addWidgets([
const orderedItems = availableSubcategories.map(value => {
const res = currentItemsMap.get(value)
if (currentItemsMap.has(value)) {
return { ...res, highlighted: `${res.count === 0 ? `${value} (No results)` : value}`}
return { ...res, highlighted: `${res.count === 0 ? `${CATEGORY_INTERNAL_MAPPING[value]} (No results)` : CATEGORY_INTERNAL_MAPPING[value]}`}
} else if (selectedSubcategories.includes(value)) {
return { highlighted: `${value} (No results)`, value, label: value, count: 0, isRefined: true }
return { highlighted: `${CATEGORY_INTERNAL_MAPPING[value]} (No results)`, value, label: value, count: 0, isRefined: true }
}
return { highlighted: `${value} (No results)`, value, label: value, count: 0, isRefined: false }
return { highlighted: `${CATEGORY_INTERNAL_MAPPING[value]} (No results)`, value, label: value, count: 0, isRefined: false }
});
return orderedItems;
}
Expand All @@ -177,6 +180,15 @@ search.addWidgets([
cssClasses: {
delete: "currentRefinementsIsomer",
},
transformItems(items) {
return items.map(item => ({
...item,
refinements: item.refinements.map(refinement => ({
...refinement,
label: CATEGORY_INTERNAL_MAPPING[refinement.label] || refinement.label, // Map the label using internalMapping
}))
}));
}
}),
instantsearch.widgets.clearRefinements({
container: "#clear-refinements",
Expand Down

0 comments on commit 8b2bc22

Please sign in to comment.