Widget: DCTList: Difference between revisions
From LINKS Community Center
Eschmidt (talk | contribs) No edit summary |
Eschmidt (talk | contribs) No edit summary |
||
Line 154: | Line 154: | ||
]; | ]; | ||
const escapeAttr = text => text ? text.replace(/\s/g, '-') : text; | const escapeAttr = text => text ? text.replace(/\s/g, '-') : text; | ||
const | const getFilePath = title => title ? '/index.php/Special:FilePath/' + title : title; | ||
const getQueryUrl = query => '/api.php?action=ask&format=json&query=' + encodeURIComponent(query); | |||
const removePrefix = str => str.substring(str.indexOf(':') + 1); | |||
async function getSources() { | async function getSources() { | ||
const | const sourceResponse = await fetch( | ||
getQueryUrl('[[Category:Social media platform]]|?IMAGE') | |||
).then(response => response.json()); | |||
const results = sourceResponse.query.results; | const results = sourceResponse.query.results; | ||
return Object.keys(results).map(platform => { | |||
const img = results[platform].printouts['IMAGE'][0]; | |||
return { | |||
name: platform, | |||
image: img ? getFilePath(img.fulltext.replace('PAGENAME:', '')) : undefined | |||
}; | |||
}); | |||
} | } | ||
async function getDcts() { | async function getDcts() { | ||
const | const FUNC_KEY = 'functions'; | ||
const DESC_KEY = 'description'; | |||
const hasFunction = (dctResult, subfunctions) => subfunctions.some(func => { | |||
const printoutResult = dctResult.printouts[func]; | |||
return printoutResult && printoutResult[0] && printoutResult[0].fulltext.toLowerCase() === 'yes' | |||
}); | |||
const functionsQuery = '[[Category:Function_category]]' + | const functionsQuery = '[[Category:Function_category]]' + | ||
'|?-Subproperty_of=' + FUNC_KEY + | '|?-Subproperty_of=' + FUNC_KEY + | ||
Line 307: | Line 310: | ||
dct.url = dctResult.fullurl; | dct.url = dctResult.fullurl; | ||
dct.dataSources = dctResult.printouts['Data Sources'].map(source => source.fulltext).sort(); | dct.dataSources = dctResult.printouts['Data Sources'].map(source => source.fulltext).sort(); | ||
dct.logo = dctResult.printouts['Image'][0] ? | dct.logo = dctResult.printouts['Image'][0] ? getFilePath(dctResult.printouts['Image'][0].fulltext) : void 0; | ||
dct.functions = []; | dct.functions = []; | ||
Revision as of 14:41, 30 August 2022
Development verstion of the DCT List.
Not ready for production!