mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-17 19:32:00 +00:00
b2bd79196d
* feat: rewrite search module (WIP) There are some caveats because it is a WIP - Messages are not i18n yet - Missing placeholder suggestion thumbnail - Only REST mode works - Missing greeting message when there is no search query - Code might look like a mess (I learned JS not long ago) * refactor: remove old search module * feat: clean up search suggestion styles * feat: hide overflow for suggestion text * feat: add action API and various cleanup * feat: re-add abort controller * feat: add message support and tweaks * feat: use virtual config instead of ResourceLoader hook * fix: missing comma in const definition * feat: add ARIA attributes
45 lines
893 B
JavaScript
45 lines
893 B
JavaScript
const config = require( '../config.json' );
|
|
|
|
/**
|
|
* Build URL used for fetch request
|
|
*
|
|
* @param {string} input
|
|
* @return {string} url
|
|
*/
|
|
function getUrl( input ) {
|
|
const endpoint = config.wgScriptPath + '/rest.php/v1/search/title?q=',
|
|
query = '&limit=' + config.wgCitizenMaxSearchResults;
|
|
|
|
return endpoint + input + query;
|
|
}
|
|
|
|
/**
|
|
* Map raw response to Results object
|
|
*
|
|
* @param {Object} data
|
|
* @return {Object} Results
|
|
*/
|
|
function convertDataToResults( data ) {
|
|
const results = [];
|
|
|
|
data = data.pages;
|
|
|
|
for ( let i = 0; i < data.length; i++ ) {
|
|
results[ i ] = {
|
|
id: data[ i ].id,
|
|
title: data[ i ].title,
|
|
description: data[ i ].description
|
|
};
|
|
if ( data[ i ].thumbnail && data[ i ].thumbnail.url ) {
|
|
results[ i ].thumbnail = data[ i ].thumbnail.url;
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
module.exports = {
|
|
getUrl: getUrl,
|
|
convertDataToResults: convertDataToResults
|
|
};
|