Open MatchaChoco010 opened 5 years ago
@MatchaChoco010 Thanks a report. I reproduced it. But, I can't judge fix this behavior or not. I think this problem impact is big.
I ask to other hexo maintainer this problem.
@tommy351 @NoahDragon @JLHwung How do you think about this.
I spent some time digging into this today and found out where the bug is. Unfortunately removing timezone
from _config.yml is not a valid workaround me because I run the build on a cloud server just prior to deploy which is running in UTC timezone.
In plugins/filter/post_permalink.js
we can see how the path is constructed. It reads from data.date
which is prepared by the hexo database layer. If you print the value, you will see that while the timestamp is correct, its timezone is off -- It's just UTC.
Next, I dig into why the timezone specified in the config file was not applied. The timezone is being used in models/types/moment.js
in the cast
function: It reads options.timezone
where it is defined in models/post.js
by reading [ctx.config.timezone](https://github.com/hexojs/hexo/blob/master/lib/models/post.js#L25)
.
Now if you print out ctx.config
, you will see that it is NOT your personal config. Instead, it's the default config comes with hexo. Digging into how hexo initialize hexo/index.js
, we see that [registerModels](https://github.com/hexojs/hexo/blob/master/lib/hexo/index.js#L100)
happened before [load_config](https://github.com/hexojs/hexo/blob/master/lib/hexo/index.js#L169)
. That's why!
This is where I'm not sure what's the best way to proceed. I think the current logic is wrong. We obviously are using config before it is loaded. We have a few options here:
hexo.init()
before using hexo stuff. I'm not sure how big the assumptions were. hexo.init()
is also, unfortunately, an async function so we can't just simply call it in those callsites too.init()
is being called which might break some other cases as well. It also makes the init
function useless.I'm happy to code this up and send a PR, but I would like to discuss which approach would be more preferable?
Thanks!
still have someone try to fix this?
@tobyqin So far, it is still remain as a known issue.
@SukkaW thanks, I workaround it by removing the timezone info in config file and build environment.
Environment Info
Node version(
node -v
):v10.9.0site to reproduce the ploblem:
https://github.com/MatchaChoco010/hexo-timezone-permalink
For BUG
_config.yml is this:
and
source/_posts/test.md
is this:The permalink of this article should be
/2018/10/11/test/
. Buthexo generate
in Japan, which +0900,/2018/10/12/test/index.html
is generated.The article date is correct (2018/10/11).
Change the machine timezone to -0500 and
hexo generate
,/2018/10/11/test.index.html
is generated.It seems that the permalink is not generated correctly if the time zone of _config.yml and the time zone setting of the machine are incorrect.