|
| 1 | +import { load } from 'cheerio'; |
| 2 | + |
| 3 | +import type { Route } from '@/types'; |
| 4 | +import ofetch from '@/utils/ofetch'; |
| 5 | +import { parseDate } from '@/utils/parse-date'; |
| 6 | + |
| 7 | +export const route: Route = { |
| 8 | + path: '/chrono', |
| 9 | + categories: ['new-media'], |
| 10 | + example: '/lephoceen/chrono', |
| 11 | + parameters: {}, |
| 12 | + features: { |
| 13 | + requireConfig: false, |
| 14 | + requirePuppeteer: false, |
| 15 | + antiCrawler: false, |
| 16 | + supportBT: false, |
| 17 | + supportPodcast: false, |
| 18 | + supportScihub: false, |
| 19 | + }, |
| 20 | + radar: [ |
| 21 | + { |
| 22 | + source: ['lephoceen.fr/chrono'], |
| 23 | + target: '/chrono', |
| 24 | + }, |
| 25 | + ], |
| 26 | + name: 'Fil Info Le Phocéen (Chrono)', |
| 27 | + maintainers: ['Loopy03'], |
| 28 | + handler: async (_) => { |
| 29 | + const response = await ofetch('https://www.lephoceen.fr/chrono'); |
| 30 | + const $ = load(response); |
| 31 | + |
| 32 | + // Récupération du fichier json |
| 33 | + const jsonRaw = $('script[id="__NEXT_DATA__"]').html(); |
| 34 | + const jsonData = JSON.parse(jsonRaw); |
| 35 | + |
| 36 | + // Tableau des articles via le chemin identifié du fichier json |
| 37 | + // Structure: props -> pageProps -> data -> datas |
| 38 | + const articles = jsonData?.props?.pageProps?.data?.datas || []; |
| 39 | + |
| 40 | + const items = articles.map((item: any) => { |
| 41 | + // Gestion du lien : le slug est relatif, on ajoute le domaine |
| 42 | + const baseUrl = 'https://www.lephoceen.fr'; |
| 43 | + const link = item.slug.startsWith('http') ? item.slug : `${baseUrl}${item.slug}`; |
| 44 | + |
| 45 | + // Gestion de la date : Le JSON fournit un timestamp UNIX (en secondes) |
| 46 | + const pubDate = parseDate(item.date.publish_at.timestamp * 1000); |
| 47 | + |
| 48 | + return { |
| 49 | + title: item.title, |
| 50 | + link, |
| 51 | + description: item.text || `[${item.category?.name}] ${item.title}`, |
| 52 | + pubDate, // L'objet Date standard gère le fuseau correctement |
| 53 | + category: [item.category?.name], |
| 54 | + image: item.images?.['16x9']?.url, |
| 55 | + }; |
| 56 | + }); |
| 57 | + |
| 58 | + return { |
| 59 | + title: 'Le Phocéen - Fil Info', |
| 60 | + link: 'https://www.lephoceen.fr/chrono', |
| 61 | + item: items, |
| 62 | + }; |
| 63 | + }, |
| 64 | +}; |
0 commit comments