mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
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:
commit
b0d006b74a
1 changed files with 12 additions and 0 deletions
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue