| 36 | }; |
| 37 | |
| 38 | async function handler(ctx) { |
| 39 | const link = `https://github.com/topics/${ctx.req.param('name')}`; |
| 40 | const { data, url } = await got(link, { |
| 41 | searchParams: new URLSearchParams(ctx.req.param('qs')), |
| 42 | }); |
| 43 | const $ = load(data); |
| 44 | |
| 45 | return { |
| 46 | title: $('title').text(), |
| 47 | description: $('.markdown-body').text().trim(), |
| 48 | link: url, |
| 49 | item: $('article.border') |
| 50 | .toArray() |
| 51 | .map((item) => { |
| 52 | item = $(item); |
| 53 | |
| 54 | const title = item.find('h3').text().trim(); |
| 55 | const author = title.split('/', 1)[0]; |
| 56 | const description = (item.find('a img').prop('outerHTML') ?? '') + item.find('div > div > p').text(); |
| 57 | const link = `https://github.com${item.find('h3 a').last().attr('href')}`; |
| 58 | const category = item |
| 59 | .find('.topic-tag') |
| 60 | .toArray() |
| 61 | .map((item) => $(item).text().trim()); |
| 62 | const pubDate = parseDate(item.find('relative-time').attr('datetime')); |
| 63 | |
| 64 | return { |
| 65 | title, |
| 66 | author, |
| 67 | description, |
| 68 | link, |
| 69 | category, |
| 70 | pubDate, |
| 71 | }; |
| 72 | }), |
| 73 | }; |
| 74 | } |