Widget: DCTList: Difference between revisions

From LINKS Community Center
Jump to: navigation, search
Eschmidt (talk | contribs)
No edit summary
Eschmidt (talk | contribs)
No edit summary
Line 154: Line 154:
     ];
     ];


    const getUrl = title =>  title ? '/index.php/Special:FilePath/' + title : title;
     const escapeAttr = text => text ? text.replace(/\s/g, '-') : text;
     const escapeAttr = text => text ? text.replace(/\s/g, '-') : text;
     const hasFunction = (dctResult, subfunctions) => subfunctions.some(func => {
     const getFilePath = title => title ? '/index.php/Special:FilePath/' + title : title;
        const printoutResult = dctResult.printouts[func];
    const getQueryUrl = query => '/api.php?action=ask&format=json&query=' + encodeURIComponent(query);
        return printoutResult && printoutResult[0] && printoutResult[0].fulltext.toLowerCase() === 'yes'
    const removePrefix = str => str.substring(str.indexOf(':') + 1);
    });


     async function getSources() {
     async function getSources() {
         const sourceQuery = '/api.php?action=ask&format=json&query=' + encodeURIComponent('[[Category:Social media platform]]|?IMAGE');
         const sourceResponse = await fetch(
         const sourceResponse = await fetch(sourceQuery).then(response => response.json());
            getQueryUrl('[[Category:Social media platform]]|?IMAGE')
 
         ).then(response => response.json());
         const results = sourceResponse.query.results;
         const results = sourceResponse.query.results;
         const sources = Object.getOwnPropertyNames(results).map(platformName => ({
          
             name: platformName,
        return Object.keys(results).map(platform => {
            image: getUrl(results[platformName].printouts['IMAGE'][0].fulltext.replace('PAGENAME:', ''))
             const img = results[platform].printouts['IMAGE'][0];
        }));
            return {
 
                name: platform,
         return sources;
                image: img ? getFilePath(img.fulltext.replace('PAGENAME:', '')) : undefined
            };
         });
     }
     }


     async function getDcts() {
     async function getDcts() {
         const removePrefix = str => str.substring(str.indexOf(':') + 1);
         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 FUNC_KEY = 'functions';
        const DESC_KEY = 'description'


        const queryBaseUrl = '/api.php?action=ask&format=json&query=';
         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] ? getUrl(dctResult.printouts['Image'][0].fulltext) : void 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!