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

升级主题后,文章会刷新更新日期,时间为刚才的部署时间 #60

Closed
XMuli opened this issue Aug 26, 2020 · 20 comments
Closed
Assignees

Comments

@XMuli
Copy link
Contributor

XMuli commented Aug 26, 2020

前几天,更新 yun v0.9.7 后,刚才只是更新了一下配置后,所有文章都被现实更新时间为本次(hexo g -d) 的日期了,但其实,大多数文章,是没有更新日期了,容易误导看客
image

@YunYouJun
Copy link
Owner

主题使用 hexo 提供的 post.updatedpost.date 进行对比,若不同则显示更新日期。而 Hexo 自动获取了文件修改的时间作为文章的更新时间,可能是重新升级时,移动了文件,判断文件已修改,所以 hexo 提供了文件修改的时间作为 updated 的信息。

但主题对此信息进行处理判断是不合适的,因此我觉得最好的方式是文章初始化时,自动生成 updated 字段,其时间与 date 相同即可,hexo 将读取该字段作为更新日期。

可以修改 scaffolds/post.md,以便每次生成文章时自动添加该字段及时间:

---
title: {{ title }}
date: {{ date }}
updated: {{ date }}
tags:
categories:
---

@XMuli
Copy link
Contributor Author

XMuli commented Aug 26, 2020

post.updatedpost.date 是两个本地文件?(我没有在文件夹找到) 还是字符串关键词?

而 Hexo 自动获取了文件修改的时间作为文章的更新时间,可能是重新升级时,移动了文件,判断文件已修改,所以 hexo 提供了文件修改的时间作为 updated 的信息。

看起来不是,好像通过 CI 自动部署,就会变成网站时候,就会更新更新时间了,明天在同一台电脑上,再次 push 修改试试看,看看日期会不会变成 27 号。

能默认设置为一下? 文章.md 中没有 updated: {{ date }} 字段就默认不显示 更新时间,手动添加了的, 才显[以前的旧文章有 200 多篇]

@YunYouJun
Copy link
Owner

YunYouJun commented Aug 26, 2020

post.datepost.updated 为 hexo 在为每篇文章进行渲染时提供的变量,主题可以通过代码获取。
这部分的数值与文章 front-matter 中的设置的 dateupdated 有关,未设置 updated 时,hexo 默认返回文件的修改时间。

如果主题默认设置不显示更新时间的话,反之就无法实现「默认显示文件修改日期作为更新日期」这一需求了。
所以设想根据 updateddate 是否相同来判定是否显示更新日期,可以取到一定的平衡点。

或者是否有其他方案建议?

@XMuli
Copy link
Contributor Author

XMuli commented Aug 26, 2020

未设置 updated 时,hexo 默认返回文件的修改时间

未设置时候,默认返回修改时间和 date 一样即可?这样或许更好 (创建时间和修改时间一致)🍀

@YunYouJun
Copy link
Owner

未设置时候,默认返回修改时间和 date 一样即可?这样或许更好 (创建时间和修改时间一致)🍀

这部分是由 hexo 默认返回的,不是主题设置的。

@YunYouJun
Copy link
Owner

YunYouJun commented Aug 26, 2020

我在 hexo 文档找到了相关的设置,你可以通过设置 hexo 的 updated_option 来解决这一问题。

https://hexo.io/docs/configuration#Date-Time-format

@YunYouJun
Copy link
Owner

YunYouJun commented Aug 26, 2020

修改 hexo 工作目录下 _config.ymlupdated_option 值为 date 即可,测试可行。

# updated_option: "mtime"
updated_option: "date"

如果没有变化,记得 hexo clean

@XMuli
Copy link
Contributor Author

XMuli commented Aug 27, 2020

谢谢, 我晚上试一下

@YunYouJun
Copy link
Owner

如果仍有问题,可以重启该 Issue。

@XMuli
Copy link
Contributor Author

XMuli commented Aug 28, 2020

最近有点繁忙,刚升级了一下 yun v1.0, 很棒~~~~
在修改 hexo 工作目录下 _config.yml 中,添加了一行 updated_option: "date", 但是之前的文章,把文章更新时间错误的刷新到了 2020-08-26 但是没有自动消失。不知到时什么原因~

@YunYouJun YunYouJun reopened this Aug 28, 2020
@YunYouJun
Copy link
Owner

记得 hexo clean 下,我测试是可以的。

@XMuli
Copy link
Contributor Author

XMuli commented Aug 28, 2020

我的脚本里面 是有 hexo clean 的; 然后本地也这样做过了,但是刚刚, push 之后,就被刷新为 2020-08-28(这会的日期)

image

image

image

@XMuli
Copy link
Contributor Author

XMuli commented Aug 28, 2020

很奇怪,在本地执行 hexo clean , g, s;在本地预览后 之后,也全部都有文章更新日期,不过是 2020-07-26 的

我们预想中的是:加了 updated_option: "date" 之后,是会 read*.md,没有 update 在 title 中,就在文章预览中,就不会有更新日期吗?

@YunYouJun
Copy link
Owner

如果想要不显示更新日期,应当将 updated_option配置为 empty

@YunYouJun
Copy link
Owner

能否提供一下仓库文件以供测试?我本地的文章时间显示测试正常。

@XMuli
Copy link
Contributor Author

XMuli commented Aug 29, 2020

我把整个文件夹压缩后都发给你,已经私发给你了, 提供你测试使用(只移除了半文章,减小体积)

@YunYouJun
Copy link
Owner

@XMuli 我似乎明白问题所在了。你使用的是 hexo v4.2.1。而 hexo v5.0 已经由原先的配置项 use_date_for_updated 迁移至 updated_option
如果你想要设置 updated_option,应当先更新 hexo 至 5.0 以上版本。

@XMuli
Copy link
Contributor Author

XMuli commented Aug 29, 2020

@YunYouJun 是的, 当我升级完 hexo v5.0 版本之后,回复之前的正常显示了;十分感谢你的帮助,且升级后,是有出现如下提示验证了你的猜想:

WARN  Deprecated config detected: "use_date_for_updated" is deprecated, please use "updated_option" instead. See https://hexo.io/docs/configuration for more details.

@YunYouJun
Copy link
Owner

因为问题已得到解决,我将关闭该 Issue。

@XMuli
Copy link
Contributor Author

XMuli commented Aug 29, 2020

给后面的人一个参考:Hexo 升级教程

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