({ link: articleLink, date })
| 20 | } |
| 21 | |
| 22 | async 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 | } |
no test coverage detected