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

Function processItem

lib/routes/30secondsofcode/utils.ts:22–54  ·  view source on GitHub ↗
({ link: articleLink, date })

Source from the content-addressed store, hash-verified

20}
21
22async function processItem({ link: articleLink, date }) {
23 return await cache.tryGet(`30secondsofcode:${articleLink}`, async () => {
24 const finalLink = `${rootUrl}${articleLink}`;
25 const response = await ofetch(finalLink);
26 const $ = load(response);
27 const tags = $.root()
28 .find('body > main > nav > ol > li:not(:first-child):not(:last-child)')
29 .toArray()
30 .map((tag) => $(tag).find('a').text());
31 const article = $('main > article');
32 const title = article.find('h1').text();
33 article.find('img').each((_, element) => {
34 const img = $(element);
35 const src = img.attr('src');
36 if (src?.startsWith('/')) {
37 img.attr('src', `${rootUrl}${src}`);
38 }
39 });
40 const image = article.find('img').attr('src');
41 const description = article.clone().find('h1, script').remove().end().html();
42
43 return {
44 title,
45 link: finalLink,
46 pubDate: parseDate(date),
47 description,
48 author: '30 Seconds of Code',
49 category: tags,
50 image: `${rootUrl}${image}`,
51 banner: `${rootUrl}${image}`,
52 } as DataItem;
53 });
54}

Callers 1

processListFunction · 0.70

Calls 4

parseDateFunction · 0.90
$Function · 0.85
endMethod · 0.80
loadFunction · 0.50

Tested by

no test coverage detected