UNPKG

awwwards

Version:
81 lines (49 loc) 2.17 kB
import qs from 'querystring'; import axios from 'axios'; import $ from 'cheerio'; export default class Awwwards { constructor(query) { const url = 'https://awwwards.com/websites?' const req = axios.get(url + qs.stringify(query)); return req.then((res) => { let sites = []; $('.box-item', res.data).each((i, el) => { sites.push({ image: $('img[data-srcset]', el).attr('data-srcset').split(', ').pop().split(' ').shift(), site: 'https://awwwards.com' + $('figure a', el).attr('href'), link: $('a[target="_blank"]', el).attr('href'), title: $('h3', el).text(), author: { name: $('strong a', el).first().text(), url: 'https://awwwards.com' + $('strong a', el).first().attr('href'), country: $('.content > .row:nth-child(2)', el).text().trim().replace(/\s\s+/g, ' ').split(' from ').pop() }, date: $('.content > .row', el).last().text().trim().replace(/\s\s+/g, ' ').split(' in ').shift(), category: $('.content > .row', el).last().text().trim().replace(/\s\s+/g, ' ').split(' in ').pop() }); }); return sites; }); } static sites_of_the_day(query) { return new Awwwards({ ...query, award: 'sites_of_the_day' }); } static sites_of_the_month(query) { return new Awwwards({ ...query, award: 'sites_of_the_month' }); } static sites_of_the_year(query) { return new Awwwards({ ...query, award: 'sites_of_the_year' }); } static developer(query) { return new Awwwards({ ...query, award: 'developer' }); } static mobile_excellence(query) { return new Awwwards({ ...query, award: 'mobile_excellence' }); } static honorable_mentions(query) { return new Awwwards({ ...query, award: 'honorable' }); } static nominees(query) { return new Awwwards({ ...query, award: 'nominees' }); } }