fix(route/dnainindia): date parse (#19592)

* change css selector

* fix date time

* remove logger
This commit is contained in:
Nishant Singh 2025-07-15 18:59:12 +05:30 committed by GitHub
parent 030654d945
commit 892067ef5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 7 deletions

View File

@ -36,14 +36,23 @@ export async function handler(ctx) {
cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = load(response);
item.itunes_item_image = $('div.article-img img').attr('src');
item.category = $('div.tags ul li')
const itunes_item_image = $('div.article-img img').attr('src');
const category = $('div.tags ul li')
.toArray()
.map((item) => $(item).find('a').text());
const time = $('p.dna-update').text().split('Updated:')[1];
item.pubDate = timezone(parseDate(time, 'MMMDD,YYYY,hh:mmA'), +5.5);
item.author = 'DNA Web Team';
item.description = $('div.article-description')
// Process date
const timeText = $('p.dna-update').text();
const dateMatch = timeText.match(/Updated\s*:\s*([\w\s,:\d]+?)(?:\s*\||$)/);
let time = dateMatch ? dateMatch[1].trim() : '';
time = time.replace(/\s+IST$/, '');
const pubDate = timezone(parseDate(time), +5.5);
// Get author information
const authorMeta = $('meta[name="author"]').attr('content');
const author = authorMeta || 'DNA Web Team';
// Process description
const description = $('div.article-description')
.clone()
.children('div')
.remove()
@ -51,7 +60,16 @@ export async function handler(ctx) {
.toArray()
.map((element) => $(element).html())
.join('');
return item;
// Return all properties at once
return {
...item,
itunes_item_image,
category,
pubDate,
author,
description,
};
})
)
);