Skip to content

Commit

Permalink
scheduler log
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Jan 20, 2025
1 parent 5f7013a commit 9cc1c2a
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions lib/db/getSiteData.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,33 @@ function handleDataBeforeReturn(db) {
// 新特性,判断文章的发布和下架时间,如果不在有效期内则进行下架处理
const publish = isInRange(p.title, p.date)
if (!publish) {
const currentTimestamp = Date.now()
const startTimestamp = getTimestamp(
p.date.start_date,
p.date.start_time,
p.date.time_zone
)
const endTimestamp = getTimestamp(
p.date.end_date,
p.date.end_time,
p.date.time_zone
)
console.log(
'[定时任务] 隐藏--> 文章:',
p.title,
'当前时间戳:',
currentTimestamp,
'目标时间戳:',
startTimestamp,
'-',
endTimestamp
)
console.log(
'[定时发布] 隐藏--> 文章:',
p.title,
'当前时间:',
Date.now(),
'目标',
new Date(),
'目标时间:',
p.date
)
// 隐藏
Expand Down Expand Up @@ -651,47 +672,31 @@ function isInRange(title, date = {}) {
// 获取当前时间的时间戳(基于目标时区)
const currentTimestamp = Date.now()

// 辅助函数:生成指定日期时间的时间戳(基于目标时区)
function getTimestamp(date, time) {
if (!date) return null
const dateTimeString = `${date}T${time}:00` // 拼接日期时间
return new Date(
new Date(dateTimeString).toLocaleString('en-US', { timeZone: time_zone })
).getTime()
}

// 获取开始和结束时间的时间戳
const startTimestamp = getTimestamp(start_date, start_time)
const endTimestamp = getTimestamp(end_date, end_time)
const startTimestamp = getTimestamp(start_date, start_time, time_zone)
const endTimestamp = getTimestamp(end_date, end_time, time_zone)

// 判断是否在范围内
if (startTimestamp && currentTimestamp < startTimestamp) {
console.log(
'[定时发布] 未到发布时间:',
title,
'指定时间:',
new Date(startTimestamp),
'当前时间:',
new Date(currentTimestamp)
)
return false
}

if (endTimestamp && currentTimestamp > endTimestamp) {
console.log(
'[定时发布] 超过下架时间:',
title,
'指定时间:',
new Date(endTimestamp),
'当前时间:',
new Date(currentTimestamp)
)
return false
}

return true
}

// 辅助函数:生成指定日期时间的时间戳(基于目标时区)
function getTimestamp(date, time, time_zone) {
if (!date) return null
const dateTimeString = `${date}T${time}:00` // 拼接日期时间
return new Date(
new Date(dateTimeString).toLocaleString('en-US', { timeZone: time_zone })
).getTime()
}

/**
* 获取导航用的精减文章列表
* gitbook主题用到,只保留文章的标题分类标签分类信息,精减掉摘要密码日期等数据
Expand Down

0 comments on commit 9cc1c2a

Please sign in to comment.