mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(utils/common-config): import parseDate and timezone functions for date handling (#19023)
This commit is contained in:
@@ -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')`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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>`)
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user