Skip to content

Commit

Permalink
feat(search): ✨ strip wikitext link syntax in search
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair3149 committed Aug 26, 2023
1 parent 2fa1e4b commit 0c0f4f4
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions resources/skins.citizen.search/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,34 @@ const typeahead = {

searchQuery.setValue( typeahead.input.element.value );

// Template syntax should trigger template search
// TODO: Perhaps this should be integrated into the searchQuery module
if ( searchQuery.value.startsWith( '{{' ) ) {
searchQuery.replace( /{{(.[^}]*)}?}?/, 'Template:$1' );
}
typeahead.updateSearchClient();

// TODO: Merge this with the search client command and put this somewhere else
const replaceRules = [
{
startWith: '{{',
pattern: /{{(.[^}]*)}?}?/,
replace: 'Template:$1',
clients: [ 'mwActionApi', 'mwRestApi' ]
},
{
startWith: '[[',
pattern: /\[\[(.[^\]]*)\]?\]?/,
replace: '$1',
clients: [ 'mwActionApi', 'mwRestApi' ]
}
];

replaceRules.forEach( ( rule ) => {
if ( rule.clients.includes( searchClient.active.id ) && searchQuery.value.startsWith( rule.startWith ) ) {
searchQuery.replace( rule.pattern, rule.replace );
}
} );

return Promise.resolve( `Search query updated to ${searchQuery.value}.` );
},
afterSeachQueryInput: function () {
typeahead.updateSearchQuery().then( async () => {
await typeahead.updateSearchClient();
updateTypeaheadItems();
} )
typeahead.updateSearchQuery().then( updateTypeaheadItems )
.catch( () => {
// Don't do anything if search query has not changed.
} );
Expand Down

0 comments on commit 0c0f4f4

Please sign in to comment.