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 2: Line 2:
<includeonly>
<includeonly>
     <script>
     <script>
        // Returns a mapping from ['File:Img1.png', 'File:Img2.png'] to [{ title: 'File:Img1.png', url: 'http...'}, { title: 'File...', url: 'http...'}]
         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('|'));
             const imageUrlResponse = await fetch(imageUrlQuery).then(response => response.json());
             const imageUrlResponse = await fetch(imageUrlQuery).then(response => response.json());
             return Object.getOwnPropertyNames(imageUrlResponse.query.pages).map(page => ({
             return Object.getOwnPropertyNames(imageUrlResponse.query.pages).map(pageKey => ({
                 title: imageUrlResponse.query.pages[page].title,
                 title: imageUrlResponse.query.pages[pageKey].title,
                 url: imageUrlResponse.query.pages[page].imageinfo[0].url
                 url: imageUrlResponse.query.pages[pageKey].imageinfo[0].url
             }));
             }));
         }
         }
Line 21: Line 22:


             const imageData = await getImages(sources.map(source => source.image));
             const imageData = await getImages(sources.map(source => source.image));
             imageData.forEach(img => {
             imageData.forEach(image => sources[sources.findIndex(source => source.image === image.title)].image = image.url);
                sources[sources.findIndex(source => source.image === img.title)].image = img.url;
            })
            // console.log('img', imageData)
 
            // const logoUrlQuery = '/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=' +
            //                      encodeURIComponent(sources.map(source => source.image).join('|'));
            // const logoUrlResponse = await fetch(logoUrlQuery).then(response => response.json());
 
            // console.log(logoUrlResponse)
 
            // Object.getOwnPropertyNames(logoUrlResponse.query.pages).forEach(pageId => {
            //    const logoFileName = logoUrlResponse.query.pages[pageId].title;
            //    const logoUrl = logoUrlResponse.query.pages[pageId].imageinfo[0].url;
            //    sources[sources.findIndex(source => source.image === logoFileName)].image = logoUrl;
            // });
 
            console.log(sources)


            console.log('Sources:', sources)
             return sources;
             return sources;
         }
         }

Revision as of 14:27, 2 June 2022

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