Conversation
|
To test it with Hexo, checkout this branch: https://github.com/hexojs/hexo/tree/timezone-dev (I'll open a Pull Request once this merged) |
There was a problem hiding this comment.
Pull Request Overview
This pull request addresses timezone handling issues in hexo-front-matter by implementing a comprehensive timezone solution. The changes replace the existing date parsing logic with a more robust system that respects explicit timezone information and provides fallback mechanisms.
- Replaces js-yaml with the yaml library and adds luxon for better timezone handling
- Implements custom timestamp parsing that respects timezone information from multiple sources
- Updates test cases to validate timezone behavior across different scenarios
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| package.json | Updates dependencies from js-yaml to yaml and adds luxon for timezone handling |
| lib/timestamp.ts | Implements custom timestamp factory with timezone-aware parsing logic |
| lib/front_matter.ts | Integrates custom timestamp parsing and updates YAML processing |
| test/index.ts | Replaces old date test with comprehensive timezone test cases |
Comments suppressed due to low confidence (1)
lib/front_matter.ts:144
- Add TypeScript type annotations for the parameters. The
optionsparameter should be typed consistently with theStringifyOptionsinterface or a subset of yaml library options.
}
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mimi <stevenjoezhang@gmail.com>
yoshinorin
left a comment
There was a problem hiding this comment.
Personally, I think this looks good to merge, but I'd like to hear other maintainers' opinions as well.
lib/timestamp.ts
Outdated
| @@ -0,0 +1,91 @@ | |||
| // https://github.com/eemeli/yaml/blob/main/src/schema/yaml-1.1/timestamp.ts | |||
There was a problem hiding this comment.
IMHO:
I think it would be better to use the commit hash from when the code was copied (v2.7.1) instead of pointing to main.
| "dependencies": { | ||
| "js-yaml": "^4.1.0" | ||
| "luxon": "^3.6.1", | ||
| "yaml": "2.7.1" |
There was a problem hiding this comment.
Question:
Why is only the yaml package pinned to a specific version? I assume it's because you copied the source code from that version—is that correct?
There was a problem hiding this comment.
Yes, since I modified parts of the timestamp parsing code, to avoid compatibility issues, I prefer to use exactly the same version. Later, when we upgrade the yaml dependency, we can rely on unit tests to determine whether it remains compatible.
Signed-off-by: Mimi <1119186082@qq.com>
check list
Description
Issue resolved: #28
See also hexojs/hexo#4548
This pull request introduces significant changes to timezone handling, aiming to address long-standing timezone issues in Hexo. (Of course, after hexo-front-matter is updated, Hexo’s code will also need corresponding adjustments — for example, passing the timezone parameter when calling hexo-front-matter, and prompting users to properly configure the timezone in
_config.yml)The core logic can be found in the comments of
lib/timestamp.ts. Specifically:1. If a timezone is set in the timestamp, use that timezone.
2. Otherwise, use the timezone defined in the Hexo configuration. hexo-front-matter no longer read the timezone from the machine, as this can cause issues in CI environments or when collaborators are in different timezones.
3. If no timezone is provided, treat the timestamp as UTC by default and take no further action.
Note that this behavior differs from the YAML specification — YAML treats unspecified timestamps as UTC, whereas we apply Hexo’s configured timezone.
To support the new functionality, I used the
yamlandluxonlibraries, which are different from Hexo’s current dependencies (js-yamlandmoment-timezone). However, all unit tests have passed, so I believe this should not cause any issues.Additional information