用Netlify自动构建Hugo博客时,会导致文章最会更新时间全部变成最后构建时间,(本地渲染时是发现不了这样的问题的)这样也失去了Lastmod的意义。
下面给出解决办法:
修改根目录下的netlify.toml代码。
修改前:

[build]
command = "hugo --gc --minify"
publish = "public"

修改为:

[build]
command = '''find content/posts -name '*.md' | while read file; do touch -d "$(git log -1 --format="@%ct" "$file")" "$file"; done; hugo --gc --minify'''
publish = "public"

若只修改posts文件夹内的文章,按上述代码即可,若content内有多个文章文件夹,或自己配置的其他文件夹,可使用下面代码:

[build]
command = '''find content -name '*.md' | while read file; do touch -d "$(git log -1 --format="@%ct" "$file")" "$file"; done; hugo --gc --minify'''
publish = "public"

或根据自己实际需要配置。

若有其他更好的方案,欢迎留言,或fork文章进行修改提交。