Merge pull request #2243 from omnivore-app/fix/wechat-handler-timezone

fix: convert published time to GMT +8 in the parsed wechat blogs
This commit is contained in:
Hongbo Wu 2023-05-24 16:33:22 +08:00 committed by GitHub
commit b0d006b74a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,4 @@
import { DateTime } from 'luxon'
import { ContentHandler } from '../content-handler'
export class WeixinQqHandler extends ContentHandler {
@ -11,6 +12,17 @@ export class WeixinQqHandler extends ContentHandler {
}
async preParse(url: string, dom: Document): Promise<Document> {
// Retrieve the publish time
const publishTime = dom.querySelector('#publish_time')?.textContent
if (publishTime) {
const dateTimeFormat = 'yyyy-LL-dd HH:mm'
// convert the publish time to a string in the format of "2023-01-01 00:00" in GMT+8
const publishTimeInGMT8 = DateTime.fromFormat(publishTime, dateTimeFormat)
.setZone('Asia/Shanghai')
.toFormat(dateTimeFormat)
// replace the publish time in the dom
dom.querySelector('#publish_time')?.replaceWith(publishTimeInGMT8)
}
// This replace the class name of the article info to preserve the block
dom
.querySelector('.rich_media_meta_list')