fix(utils/common-config): import parseDate and timezone functions for date handling (#19023)

This commit is contained in:
Tony
2025-05-06 02:07:35 +08:00
committed by GitHub
parent 0510d8391e
commit f68f81c49d
4 changed files with 14 additions and 5 deletions
+2 -2
View File
@@ -28,8 +28,8 @@ async function handler() {
title: 'Jewish Museums - Exhibitions',
item: {
item: '#current article.exhibition, #upcoming article, #past article.exhibition',
title: `$('article.exhibition h3').text()`,
link: `$('article.exhibition > a').attr('href')`,
title: `$('h3').text()`,
link: `$('h3').parent().attr('href')`,
},
});
}
+2
View File
@@ -48,10 +48,12 @@ const server = setupServer(
<li>
<a href="/1">1</a>
<div class="description">RSSHub1</div>
<div class="date">2025-01-01</div>
</li>
<li>
<a href="/2">2</a>
<div class="description">RSSHub2</div>
<div class="date">2025-01-02</div>
</li>
</ul>
</div>`)
+3 -2
View File
@@ -51,6 +51,7 @@ describe('index', () => {
title: `$('a').text() + ' - %title%'`,
link: `$('a').attr('href')`,
description: `$('.description').html()`,
pubDate: `timezone(parseDate($('.date').text(), 'YYYY-MM-DD'), 0)`,
},
});
@@ -62,14 +63,14 @@ describe('index', () => {
description: 'RSSHub1',
guid: undefined,
link: '/1',
pubDate: undefined,
pubDate: new Date('2025-01-01T00:00:00Z'),
title: '1 - buildData',
},
{
description: 'RSSHub2',
guid: undefined,
link: '/2',
pubDate: undefined,
pubDate: new Date('2025-01-02T00:00:00Z'),
title: '2 - buildData',
},
],
+7 -1
View File
@@ -1,10 +1,16 @@
import { load } from 'cheerio';
import ofetch from '@/utils/ofetch';
import iconv from 'iconv-lite';
import { parseDate as _parseDate } from '@/utils/parse-date';
import _timezone from '@/utils/timezone';
function transElemText($, prop) {
const regex = /\$\((.*)\)/g;
let result = prop;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const parseDate = _parseDate;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const timezone = _timezone;
if (regex.test(result)) {
// eslint-disable-next-line no-eval
result = eval(result);
@@ -43,7 +49,7 @@ async function buildData(data) {
let charset = 'utf-8';
for (const attr of contentType.split(';')) {
if (attr.includes('charset=')) {
charset = attr.split('=').pop() || 'utf-8';
charset = (attr.split('=').pop() || 'utf-8').toLowerCase();
}
}
// @ts-expect-error custom property