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
This commit is contained in:
Hongbo Wu 2023-07-04 18:46:35 +08:00
parent fe450ffe20
commit e06f833e21

View file

@ -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