From 4d422402f81a15e1989f114f864baa8444698cb5 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 24 May 2023 10:55:54 +0800 Subject: [PATCH] fix: convert published time to GMT +8 in the parsed wechat blogs --- .../src/websites/weixin-qq-handler.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/content-handler/src/websites/weixin-qq-handler.ts b/packages/content-handler/src/websites/weixin-qq-handler.ts index feff90955..cab4040c8 100644 --- a/packages/content-handler/src/websites/weixin-qq-handler.ts +++ b/packages/content-handler/src/websites/weixin-qq-handler.ts @@ -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 { + // 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')