最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to attach a time stamp to markdown front matter in Gatsby.js - Stack Overflow

programmeradmin4浏览0评论

I'm going through the Gatsby example starter blog and this is one of the markdown blog posts:

.md

I reckon the author doesn't hardtype to the frontmatter a string like date: "2015-05-01T22:12:03.284Z" every time he'd make a post.

Is this a vim feature? How do I automate adding time stamps to Gatsby's markdown files on save of the file?

Help appreciated :)

I'm going through the Gatsby example starter blog and this is one of the markdown blog posts:

https://raw.githubusercontent./gatsbyjs/gatsby-starter-blog/master/src/pages/2015-05-01-hello-world/index.md

I reckon the author doesn't hardtype to the frontmatter a string like date: "2015-05-01T22:12:03.284Z" every time he'd make a post.

Is this a vim feature? How do I automate adding time stamps to Gatsby's markdown files on save of the file?

Help appreciated :)

Share Improve this question asked Sep 19, 2017 at 9:52 SebastianSebastian 1,3151 gold badge17 silver badges27 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Gatsby supports all official date & time formats!

So you can also just write "2015-05-1".

The filesystem source plugin does provide timestamp data as seen here: https://github./gatsbyjs/gatsby/blob/master/packages/gatsby-source-filesystem/src/create-file-node.js#L52

It's undocumented so it may change in the future, but you can use fields modifiedTime, accessTime, birthTime and changeTime in any markdown GraphQL query.

Please note that these values are provided by the OS, so they may be higly unreliable. Usually OS timestamps on files are just indicative and shouldn't be trusted. Some OSes don't uses them at all depending on how the filesystem is mounted.

What you can do is to switch to another data source that will provide reliable create and updated timestamps. Wordpress provide that data. MongoDB can be used to provide that given you use the right admin interface. Others sources like Contentfull also may or may not provide that info.

By the way, if you absolutely want it, and are okay with the drawbacks, it's quite straight forward to add these fields in your GraphQL query.

发布评论

评论列表(0)

  1. 暂无评论