Files
Sukka d82847f541 style/chore(eslint): enforce new rules (#8040)
* style: prefer object shorthand syntax
* refactor: prefer Array#map over Array#forEach
* style: prefer arrow callback
* chore(eslint): update rules
* style: auto fix by eslint
2021-08-17 22:23:23 +08:00

50 lines
1.7 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const baseUrl = 'https://art.icity.ly';
/**
* type: ['all', 'latest', 'hot', 'end_soon', 'coming', 'outdated']
* city: ['shanghai', 'beijing',....]
*/
module.exports = async (ctx) => {
const city = ctx.params.city;
const type = ctx.params.type || 'all';
const url = `${baseUrl}/${city}/${type}`;
const response = await got({
method: 'get',
url,
headers: {
Referer: url,
},
});
const data = response.data;
const $ = cheerio.load(data);
const context = $('.imsm-section');
const city_name = context.find('a > h3').text();
const exhibition_type = context.find('li.active > a').text();
const title = `${city_name} - ${exhibition_type} - 每日环球展览 iMuseum`;
const list = $('.imsm-entries.list li');
ctx.state.data = {
title,
link: url,
description: $('meta[name="description"]').attr('content'),
item:
list &&
list
.map((item, index) => {
item = $(index);
const pretitle = item.find('.pretitle').children()[0].prev ? item.find('.pretitle').children()[0].prev.data : '';
const subtitle = item.find('.subtitle').children()[0].next ? item.find('.subtitle').children()[0].next.data : '';
return {
title: item.find('div.title').text(),
description: `${subtitle} ${pretitle} <img src="${item.find('img.cover').attr('src')}">`,
link: `${baseUrl}${item.find('a.info').attr('href')}`,
};
})
.get(),
};
};