Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

导入hexo markdown的部分文档时间错误 #142

Closed
xflcx1991 opened this issue Jun 12, 2020 · 12 comments
Closed

导入hexo markdown的部分文档时间错误 #142

xflcx1991 opened this issue Jun 12, 2020 · 12 comments

Comments

@xflcx1991
Copy link

xflcx1991 commented Jun 12, 2020

描述问题

导入符合hexo文件头的markdown文档后部分文章的时间显示错误。

我看到solo的文档(https://hacpai.com/article/1498490209748)说支持导入hexo头的markdown文件,也看到了这个issue(导入 Markdown 文件存档时间问题 #112 https://github.com/88250/solo/issues/112),随即删除了所有文章(吐槽,还得一个一个删除),尝试了更新镜像,也确实有更新(6月10日),重启了容器。重新导入,但还是有同样的几个文档时间显示错误。

但是错误的有规律,所有有错误的文档都是时间非常晚,比如

date: 2020-01-01 20:23:03

如果是早上或者下午3点多均不会显示日期错误。所以我猜是否是时区的问题导致转换北京时间时计算成了下一天?

期待的结果

应该按照hexo文件头部定义的时间(默认是北京时间,或者有选择时区的功能)来显示文章时间
或者,提供后台修改文章时间的功能。

截屏或录像

2020-06-12_16-42.png

其他信息

暂无

@88250
Copy link
Owner

88250 commented Jun 12, 2020

你是本地启动的还是 Docker 部署?

@xflcx1991
Copy link
Author

你是本地启动的还是 Docker 部署?

Docker 部署,尽量按照文档推荐做法。另外开启了 lute_http。

@88250
Copy link
Owner

88250 commented Jun 14, 2020

Docker 镜像里面已经设置了时区,估计是数据库时区没有配置一致。

@xflcx1991
Copy link
Author

xflcx1991 commented Jun 15, 2020

不行,我删除容器,删除solo数据库。设置数据库my.cnf默认时区是东八区,新建solo库,开启docker时的JDBC连接字符串时区改为serverTimezone=Asia/Shanghai,导入文章,还是显示1月2日。这该怎么排查。

@88250
Copy link
Owner

88250 commented Jun 15, 2020

article 表里有两个字段 articleCreatedarticleUpdated 都是时间毫秒,手动转换后看下是否正常。

@xflcx1991
Copy link
Author

article 表里有两个字段 articleCreatedarticleUpdated 都是时间毫秒,手动转换后看下是否正常。

修改后,首页文章列表里日期是正确的了,但是文章详情里还是不正确。

  1. 文章详情里用的是那个表?
  2. 这是否可以说明在解析 hexo文件头的时候读取时间就算错了。

@88250
Copy link
Owner

88250 commented Jun 15, 2020

  • 手改数据库后,因为有内存缓存,所以详情里没生效,最好是停服以后再改数据库
  • 导入 markdown 时解析代码在 ImportService.java 中,有可能的话请帮忙调试,我看代码似乎没问题,用的是 JVM 默认时区,Docker 镜像里设置过时区,但为什么没生效有点奇怪

@xflcx1991
Copy link
Author

xflcx1991 commented Jun 16, 2020

* 手改数据库后,因为有内存缓存,所以详情里没生效,最好是停服以后再改数据库

* 导入 markdown 时解析代码在 ImportService.java 中,有可能的话请帮忙调试,我看代码似乎没问题,用的是 JVM 默认时区,Docker 镜像里设置过时区,但为什么没生效有点奇怪

单步调试,问题找到了,在 YAML加载 frontMatter 时时间就已经有问题了。稍后截图。
截图在此。
NiL3oq.png

看到《Solo 从设计到实现 》里一篇文章( Solo 导入 Markdown 文章 https://hacpai.com/article/1547643961141)说用了 SnakeYaml 来解析。看到截图SnakeYaml已经把时间字符串解析成了date类型的值,可能需要在SnakeYaml里去寻找时区设置了。

P.S. 问题的还有可能是 CST 本身就是一个有混淆的时区概念,有4个时区的缩写都是它。

@xflcx1991
Copy link
Author

xflcx1991 commented Jun 16, 2020

临时解决方法:
在 SnakeYaml 的文档( https://bitbucket.org/asomov/snakeyaml/wiki/Documentation )里,看到这样的示例:

Time: 2001-11-23 15:01:42 -5

所以我本地的markdown文档时间后加一个+8

date: 2020-01-01 20:23:03 +8

再导入就正常了。

@xflcx1991
Copy link
Author

xflcx1991 commented Jun 16, 2020

@88250 问题应该终结了。
看了 SnakeYaml 文档( https://bitbucket.org/asomov/snakeyaml/wiki/Documentation )里提到 yaml 的标准( https://yaml.org/type/timestamp.html ),里面提到

If the time zone is omitted, the timestamp is assumed to be specified in UTC.

并给出了几种时间示例:

canonical: 2001-12-15T02:59:43.1Z
valid iso8601: 2001-12-14t21:59:43.10-05:00
space separated: 2001-12-14 21:59:43.10 -5
no time zone (Z): 2001-12-15 2:59:43.10
date (00:00:00Z): 2002-12-14

看来按照 yaml 规范,时间本来就应该写时区,不写我就认为是 UTC,这和 SnakeYaml 就无关了,它确实是按照规范解析的。但是这样 solo 的教程里得注明这一点了。

@88250
Copy link
Owner

88250 commented Jun 16, 2020

感谢反馈和帮忙定位排查,稍后在文档中注明 🙏

@88250 88250 closed this as completed Jun 16, 2020
@88250
Copy link
Owner

88250 commented Jun 16, 2020

在文档中进行了补充 https://hacpai.com/article/1498490209748

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants