Skip to content

Commit

Permalink
Add typeahead page redirects (#206)
Browse files Browse the repository at this point in the history
* redirects

* Underground -> Diamonds

* Infected, Contagious, Resistant

* Mutation, Mutating Berries -> Farm
  • Loading branch information
CypherX authored Jul 13, 2024
1 parent 4baba87 commit d011311
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -79709,6 +79709,7 @@ const searchOptions = [
display: 'Hatchery',
type: 'Hatchery',
page: '',
redirects: ['Daycare'],
},
// Hatchery Helpers
{
Expand Down Expand Up @@ -79787,6 +79788,7 @@ const searchOptions = [
display: 'Farm',
type: 'Farm',
page: '',
redirects: ['Mutating Berries', 'Mutation'],
},
{
display: 'Farm Simulator',
Expand Down Expand Up @@ -79814,6 +79816,7 @@ const searchOptions = [
display: 'Pokérus',
type: 'Pokérus',
page: '',
redirects: ['EVs', 'Effort Values', 'Infected', 'Contagious', 'Resistant'],
},
// Dream Orbs
{
Expand Down Expand Up @@ -79928,6 +79931,7 @@ const searchOptions = [
display: 'Diamonds',
type: 'Diamonds',
page: '',
redirects: ['Underground'], // remove when Underground page added
},
{
display: 'Battle Points',
Expand Down Expand Up @@ -79988,6 +79992,12 @@ searchOptions.forEach(a => {
duplicates.forEach(d => d.display = `${d.display} (${d.type})`);
}
})
// Redirects
searchOptions.forEach(a => {
a.redirects?.forEach(r => {
searchOptions.push({ ...a, redirect: r });
});
});

/*
AUTO FILL FOR SEARCH BAR
Expand All @@ -80003,7 +80013,7 @@ var substringMatcher = (searchData) => {
const substrRegex = new RegExp(escapeRegExp(query), 'i');

// iterate through the pool of strings and for any string that matches the regex
const results = searchData.filter(d => substrRegex.test(d.display));
const results = searchData.filter(d => substrRegex.test(d.redirect || d.display));

cb(results.sort((a, b) => a.display.search(substrRegex) - b.display.search(substrRegex) || a.display.length - b.display.length));
};
Expand All @@ -80029,7 +80039,8 @@ $('#search').typeahead({
templates: {
notFound: '<a class="dropdown-item disabled">No results found...</a>',
suggestion: (suggestion) => {
return `<a href="#!${suggestion.type}/${suggestion.page}">${suggestion.display}</a>`;
const display = suggestion.redirect ? `${suggestion.redirect} → ${suggestion.display}` : suggestion.display;
return `<a href="#!${suggestion.type}/${suggestion.page}">${display}</a>`;
},
},
});
Expand Down
15 changes: 13 additions & 2 deletions scripts/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const searchOptions = [
display: 'Hatchery',
type: 'Hatchery',
page: '',
redirects: ['Daycare'],
},
// Hatchery Helpers
{
Expand Down Expand Up @@ -199,6 +200,7 @@ const searchOptions = [
display: 'Farm',
type: 'Farm',
page: '',
redirects: ['Mutating Berries', 'Mutation'],
},
{
display: 'Farm Simulator',
Expand Down Expand Up @@ -226,6 +228,7 @@ const searchOptions = [
display: 'Pokérus',
type: 'Pokérus',
page: '',
redirects: ['EVs', 'Effort Values', 'Infected', 'Contagious', 'Resistant'],
},
// Dream Orbs
{
Expand Down Expand Up @@ -340,6 +343,7 @@ const searchOptions = [
display: 'Diamonds',
type: 'Diamonds',
page: '',
redirects: ['Underground'], // remove when Underground page added
},
{
display: 'Battle Points',
Expand Down Expand Up @@ -400,6 +404,12 @@ searchOptions.forEach(a => {
duplicates.forEach(d => d.display = `${d.display} (${d.type})`);
}
})
// Redirects
searchOptions.forEach(a => {
a.redirects?.forEach(r => {
searchOptions.push({ ...a, redirect: r });
});
});

/*
AUTO FILL FOR SEARCH BAR
Expand All @@ -415,7 +425,7 @@ var substringMatcher = (searchData) => {
const substrRegex = new RegExp(escapeRegExp(query), 'i');

// iterate through the pool of strings and for any string that matches the regex
const results = searchData.filter(d => substrRegex.test(d.display));
const results = searchData.filter(d => substrRegex.test(d.redirect || d.display));

cb(results.sort((a, b) => a.display.search(substrRegex) - b.display.search(substrRegex) || a.display.length - b.display.length));
};
Expand All @@ -441,7 +451,8 @@ $('#search').typeahead({
templates: {
notFound: '<a class="dropdown-item disabled">No results found...</a>',
suggestion: (suggestion) => {
return `<a href="#!${suggestion.type}/${suggestion.page}">${suggestion.display}</a>`;
const display = suggestion.redirect ? `${suggestion.redirect}${suggestion.display}` : suggestion.display;
return `<a href="#!${suggestion.type}/${suggestion.page}">${display}</a>`;
},
},
});
Expand Down

0 comments on commit d011311

Please sign in to comment.