Skip to content

Commit 0c60e6f

Browse files
feat(validate_config): add timezone check
1 parent f4962ca commit 0c60e6f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/hexo/validate_config.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assert from 'assert';
2+
import moment from 'moment-timezone';
23
import type Hexo from './index';
34

45
export = (ctx: Hexo): void => {
@@ -24,5 +25,24 @@ export = (ctx: Hexo): void => {
2425
if (config.root.trim().length <= 0) {
2526
throw new TypeError('Invalid config detected: "root" should not be empty!');
2627
}
27-
};
2828

29+
if (!config.timezone) {
30+
log.warn('No timezone setting detected! Using the default timezone UTC.');
31+
config.timezone = 'UTC';
32+
} else {
33+
const configTimezone = moment.tz.zone(config.timezone);
34+
if (!configTimezone) {
35+
log.warn(
36+
`Invalid timezone setting detected! "${config.timezone}" is not a valid timezone. Using the default timezone UTC.`
37+
);
38+
config.timezone = 'UTC';
39+
} else {
40+
const machineTimezone = moment.tz.guess();
41+
if (configTimezone.name !== machineTimezone) {
42+
log.warn(
43+
`The timezone "${config.timezone}" setting is different from your machine timezone "${machineTimezone}". Make sure this is intended.`
44+
);
45+
}
46+
}
47+
}
48+
};

0 commit comments

Comments
 (0)