MCPcopy Create free account
hub / github.com/DIYgod/RSSHub / handler

Function handler

lib/routes/30secondsofcode/category.ts:45–68  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

43};
44
45async function handler(ctx) {
46 const category = ctx.req.param('category') ?? '';
47 const subCategory = ctx.req.param('subCategory') ?? '';
48
49 const rootUrl = 'https://www.30secondsofcode.org';
50 const currentUrl = `${rootUrl}${category ? `/${category}` : ''}${subCategory ? `/${subCategory}` : ''}${category || subCategory ? '/p/1/' : ''}`;
51
52 const response = await ofetch(currentUrl);
53 const $ = load(response);
54 const heroElement = $('section.hero');
55 const heading = heroElement.find('div > h1').text();
56 const description = heroElement.find('div > p').text();
57 const image = heroElement.find('img').attr('src');
58
59 const fullList = $('section.preview-list > ul > li').toArray();
60 const items = await processList(fullList);
61 return {
62 title: heading,
63 description,
64 image: `${rootUrl}${image}`,
65 link: rootUrl,
66 item: items,
67 } as Data;
68}

Callers

nothing calls this directly

Calls 3

processListFunction · 0.90
$Function · 0.85
loadFunction · 0.50

Tested by

no test coverage detected