antwarjs / antwar

A static site generator built with React and Webpack.
https://antwar.js.org/
MIT License
460 stars 35 forks source link

posts’ dates #84

Closed iamstarkov closed 9 years ago

iamstarkov commented 9 years ago

Minimum viable blog should have: articles and articles list. And obviously articles list should be sorted by date otherwize it’s uselss, so posts’ dates are one of the most detail for the blog. For example jekyll teach about dates on configuration step: YEAR-MONTH-DAY-title.md. How did you manage to extract dates from posts?

bebraw commented 9 years ago

We solve this through processItem.date hook. It uses YAML headmatter date by default if it exists. If not, you can pass a custom date. In that case you would do something like this:

paths: {
  blog: {
    processItem: {
      date: function(o) {
        // parse date from filename or something
        return new Date(o.fileName.split('-').slice(0, 3).join('.'));
      }
    }
  }
}
iamstarkov commented 9 years ago

pretty neat, can I override it for my blog?

bebraw commented 9 years ago

Yeah, that's why we have the hook. :+1:

Note that we default to sort by date (reversed) by default. As mentioned elsewhere it's possible to customize this per section. I needed to do that for my book for instance.

iamstarkov commented 9 years ago

awsm

bebraw commented 9 years ago

I suppose it's safe to close this. Let me know if you have any further issues. I'll create a FAQ entry out of this.

iamstarkov commented 9 years ago

I suppose it's safe to close this.

sure