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 3: Line 3:
     <script>
     <script>
         // Returns a mapping from ['File:Img1.png', 'File:Img2.png'] to [{ title: 'File:Img1.png', url: 'http...'}, { title: 'File...', url: 'http...'}]
         // Returns a mapping from ['File:Img1.png', 'File:Img2.png'] to [{ title: 'File:Img1.png', url: 'http...'}, { title: 'File...', url: 'http...'}]
        // Original order is NOT preserved
         async function getImages(imageTitles) {
         async function getImages(imageTitles) {
             const imageUrlQuery = '/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=' + encodeURIComponent(imageTitles.join('|'));
             const imageUrlQuery = '/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=' + encodeURIComponent(imageTitles.join('|'));
Line 22: Line 23:


             const imageData = await getImages(sources.map(source => source.image));
             const imageData = await getImages(sources.map(source => source.image));
             imageData.forEach(image => sources[sources.findIndex(source => source.image === image.title)].image = image.url);
             imageData.forEach(img => sources[sources.findIndex(source => source.image === img.title)].image = img.url);


             console.log('Sources:', sources)
             // console.log('Sources:', sources)
             return sources;
             return sources;
         }
         }
Line 34: Line 35:
             const dctQueryUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(dctQuery);
             const dctQueryUrl = '/api.php?action=ask&format=json&query=' + encodeURIComponent(dctQuery);
             const dctResponse = await fetch(dctQueryUrl).then(response => response.json());
             const dctResponse = await fetch(dctQueryUrl).then(response => response.json());
             console.log(dctResponse);
 
            const list = Object.getOwnPropertyNames(dctResponse.query.results).map(dctKey => {
                const dct = {};
                dct.name = dctKey;
                dct.url = dctResponse.query.results[dctKey].fullurl;
                return dct;
            })
             console.log('DCT:', list);
         }
         }



Revision as of 11:14, 7 June 2022

Development verstion of the DCT List.
Not ready for production!