optimize directory structure

This commit is contained in:
DIYgod
2018-12-26 18:35:10 +08:00
parent c68251e461
commit 38a90e29b0
475 changed files with 52 additions and 52 deletions

View File

@@ -0,0 +1,36 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = 'http://blogread.cn/news/newest.php';
const response = await axios({
method: 'get',
url,
});
const $ = cheerio.load(response.data);
const resultItem = $('.media')
.map((index, elem) => {
elem = $(elem);
const $link = elem.find('dt a');
return {
title: $link.text(),
description: elem
.find('dd')
.eq(0)
.text(),
link: $link.attr('href'),
author: elem
.find('.small a')
.eq(0)
.text(),
};
})
.get();
ctx.state.data = {
title: '技术头条',
link: url,
item: resultItem,
};
};