Add badge filtering and shop category to the site
- Introduced a new 'shops' category in the build script and README. - Implemented badge filtering in the filter functionality, allowing users to filter entries by badge.
This commit is contained in:
22
build.js
22
build.js
@@ -14,7 +14,8 @@ const CATEGORY_LABELS = {
|
||||
manufacturers: 'Tillverkare',
|
||||
products: 'Produkter',
|
||||
services: 'Tjänster',
|
||||
experiences: 'Upplevelser'
|
||||
experiences: 'Upplevelser',
|
||||
shops: 'Butiker'
|
||||
};
|
||||
|
||||
// Badge tiers (highest to lowest)
|
||||
@@ -207,8 +208,14 @@ function extractFilters(entries) {
|
||||
const categories = [...new Set(entries.map(e => e.category).filter(Boolean))].sort();
|
||||
const regions = [...new Set(entries.map(e => e.region).filter(Boolean))].sort();
|
||||
const tags = [...new Set(entries.flatMap(e => e.tags || []))].sort();
|
||||
const badges = [...new Set(entries.map(e => e.badge).filter(Boolean))].sort((a, b) => {
|
||||
// Sort by tier (highest first)
|
||||
const tierA = BADGE_TIERS[a]?.tier || 99;
|
||||
const tierB = BADGE_TIERS[b]?.tier || 99;
|
||||
return tierA - tierB;
|
||||
});
|
||||
|
||||
return { categories, regions, tags };
|
||||
return { categories, regions, tags, badges };
|
||||
}
|
||||
|
||||
// Generate filter HTML
|
||||
@@ -224,6 +231,10 @@ function generateFilterHTML(filters) {
|
||||
const tagOptions = filters.tags.map(t =>
|
||||
`<option value="${t}">${t}</option>`
|
||||
).join('');
|
||||
|
||||
const badgeOptions = filters.badges.map(b =>
|
||||
`<option value="${b}">${BADGE_TIERS[b]?.label || b}</option>`
|
||||
).join('');
|
||||
|
||||
return `
|
||||
<div class="filters">
|
||||
@@ -241,6 +252,13 @@ function generateFilterHTML(filters) {
|
||||
${regionOptions}
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter-group">
|
||||
<label for="badge-filter">Märkning</label>
|
||||
<select id="badge-filter">
|
||||
<option value="">Alla märkningar</option>
|
||||
${badgeOptions}
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter-group">
|
||||
<label for="tag-filter">Tagg</label>
|
||||
<select id="tag-filter">
|
||||
|
||||
Reference in New Issue
Block a user