Widget: DCTList: Difference between revisions
From LINKS Community Center
Eschmidt (talk | contribs) No edit summary |
Eschmidt (talk | contribs) No edit summary |
||
Line 175: | Line 175: | ||
async function getDcts() { | async function getDcts() { | ||
const removePrefix = str => str.substring(str.indexOf(':') + 1); | |||
const | |||
const | const FUNC_KEY = 'functions'; | ||
const | const DESC_KEY = 'description' | ||
const | const queryBaseUrl = '/api.php?action=ask&format=json&query='; | ||
const functionsQuery = '[[Category:Function_category]]' + | |||
'|?-Subproperty_of=' + FUNC_KEY + | |||
'|?Has_description=' + DESC_KEY; | |||
const | const functionsQueryResponse = await fetch( | ||
queryBaseUrl + encodeURIComponent(functionsQuery) | |||
).then(response => response.json()); | |||
const functionsQueryResults = functionsQueryResponse.query.results; | |||
const functionsData = new Map(); | |||
Object.keys( | Object.keys(functionsQueryResults).forEach(key => { | ||
const functionCategory = functionsQueryResults[key]; | |||
removePrefix( | functionsData.set( | ||
{ | // Key: Name of the Function Category. | ||
[ | removePrefix(functionCategory.fulltext), | ||
[ | // Value: Description and subfunctions. | ||
} | { | ||
[DESC_KEY]: functionCategory.printouts[DESC_KEY][0], | |||
[FUNC_KEY]: functionCategory.printouts[FUNC_KEY].map(subfunction => removePrefix(subfunction.fulltext)) | |||
} | |||
) | |||
}) | }) | ||
console.log('Func result', | console.log('Func result', functionsData); | ||
const searchFunctions = [ | const searchFunctions = [ |
Revision as of 13:07, 30 August 2022
Development verstion of the DCT List.
Not ready for production!