feat(route): add Go语言中文网板块 (#12274)

This commit is contained in:
Ethan Shen
2023-04-11 05:30:52 +08:00
committed by GitHub
parent ddb81b9eee
commit a5a3afa4bd
8 changed files with 104 additions and 65 deletions

View File

@@ -1,29 +1,7 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { FetchGoItems } = require('./utils');
module.exports = async (ctx) => {
const url = 'https://studygolang.com/go/weekly';
const response = await got({
method: 'get',
url,
});
const $ = cheerio.load(response.data);
const resultItem = $('div.topic div.title')
.map((_index, elem) => {
elem = $(elem);
const $link = elem.find('a');
const title = $link.text();
const link = $link.attr('href');
return {
title,
link,
};
})
.get();
ctx.params.id = 'weekly';
ctx.state.data = {
title: 'Go语言爱好者周刊',
link: url,
item: resultItem,
};
ctx.state.data = await FetchGoItems(ctx);
};