import { getCurrentPath } from '@/utils/helpers'; const __dirname = getCurrentPath(import.meta.url); import cache from '@/utils/cache'; import ofetch from '@/utils/ofetch'; import { load } from 'cheerio'; import { art } from '@/utils/render'; import path from 'node:path'; const getImageById = async (id) => { const response = await ofetch('https://api.aeonmedia.co/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ query: 'query getImageById($id: ID!) { image(id: $id) { id url alt caption width height } }', variables: { id, site: 'Aeon' }, operationName: 'getImageById', }), }); return response.data.image.url; }; function format(article) { const type = article.type.toLowerCase(); let block = ''; let banner = ''; let authorsBio = ''; switch (type) { case 'film': block = art(path.join(__dirname, 'templates/video.art'), { article }); break; case 'guide': { banner = article.imageSquare?.url; authorsBio = article.authors.map((author) => author.bio).join(' '); const sectionNames = ['Need To Know', 'What To Do', 'Key Points', 'Learn More', 'Links & Books']; const sections = Object.keys(article).filter((key) => key.startsWith('section') && key !== 'section'); const content = sections .map((section) => { const capture = load(article[section]); capture('p.pullquote').remove(); const sectionName = sectionNames.shift(); return `