hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.48k stars 4.86k forks source link

Post title error: title "2015-10-11" displayed as "Sun Oct 11 2015 00:00:00 GMT+0800 (中国标准时间)" #2792

Closed xiaopxiaop closed 7 years ago

xiaopxiaop commented 7 years ago

Environment Info

Node version(node -v): v6.11.3

Your site _config.yml (Optional):

Your theme _config.yml (Optional):

Hexo and Plugin version(npm ls --depth 0):

+-- hexo@3.3.9 +-- hexo-asset-image@0.0.3 +-- hexo-deployer-git@0.3.1 +-- hexo-deployer-heroku@0.1.2 +-- hexo-deployer-openshift@0.1.2 +-- hexo-deployer-rsync@0.1.3 +-- hexo-generator-archive@0.1.4 +-- hexo-generator-category@0.1.3 +-- hexo-generator-feed@1.2.2 +-- hexo-generator-index@0.2.1 +-- hexo-generator-searchdb@1.0.8 +-- hexo-generator-sitemap@1.2.0 +-- hexo-generator-tag@0.2.0 +-- hexo-renderer-ejs@0.3.1 +-- hexo-renderer-marked@0.2.11 +-- hexo-renderer-stylus@0.2.3 +-- hexo-server@0.2.2 +-- htmlparser@1.7.7 `-- match-words@1.0.0

For BUG

A sample post 2015-10-11.md is as follows:

---
title: 2015-10-11
date: 2015-10-11 16:08:00
tags:
---

when viewing it on the browser, the title was changed to

Sun Oct 11 2015 00:00:00 GMT+0800 (中国标准时间)

image

However changing the title to 2015-10-9 in md file would make the post appear normal.

image

sabrinaluo commented 7 years ago

It's possiblely related to how the theme parses the date, which theme are you using? can you provide the theme repo url?

xiaopxiaop commented 7 years ago

I tried two theme, next & landscape, and both had the same issue. So I guess it's not related to theme, but hexo itself.

BTW, when I changed the title from 2015-10-11 to "2015-10-11", the problem was gone.

JLHwung commented 7 years ago

This is irrelevant to the theme.

The hexo post front-matter must conforms to either JSON or YAML. In YAML, the date type is represented as 2015-12-01. So what you write in the front-matter

title: 2015-10-11
date: 2017-10-03

is equivalent to:

{
   title: new Date("2015-10-11"),
   date: new Date("2017-10-03")
}

The title is converted to string using moment().format, thus is displayed as Sun Oct 11 2015 00:00:00 GMT+0800 (中国标准时间)

If you would like to have the string 2015-10-11 as title, go as

title: '2015-10-11'
date: 2017-10-03

It is interesting to note that hexo g 2015-10-11 does escape the title as string.

Hexo should have check the schema of front matter and throws error. But I'd rather keep things simple and leave it won't fix.