From e06f833e213d907d0dbe61ccb18ed215a4cd1bc8 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 4 Jul 2023 18:46:35 +0800 Subject: [PATCH] fix: missing published date in some wechat articles * some wechat articles do not have `create_time` in the dom javascript so use the `publish_time` node in the dom content --- .../src/websites/weixin-qq-handler.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/content-handler/src/websites/weixin-qq-handler.ts b/packages/content-handler/src/websites/weixin-qq-handler.ts index cab4040c8..4ae9f6ae8 100644 --- a/packages/content-handler/src/websites/weixin-qq-handler.ts +++ b/packages/content-handler/src/websites/weixin-qq-handler.ts @@ -17,11 +17,16 @@ export class WeixinQqHandler extends ContentHandler { 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) + const publishTimeISO = DateTime.fromFormat( + publishTime, + dateTimeFormat + ).toISO() + + // create a meta node to store the publish time with timezone + const metaNode = dom.createElement('meta') + metaNode.setAttribute('name', 'date') + metaNode.setAttribute('content', publishTimeISO) + dom.querySelector('head')?.appendChild(metaNode) } // This replace the class name of the article info to preserve the block dom