What are the differences between a post and a page in Jekyll?

痞子三分冷 提交于 2020-12-29 05:30:05

问题


I am using Jekyll. What are the differences between a post and a page? As far as I can see:

  1. they both can contain YAML front matter, and
  2. a post has a date and a permalink, but a page doesn't.

Are there more differences?


回答1:


Here are the differences

  • A post filename contains the title and the date of the post. An invalid date in the filename causes an error.
  • Posts are comparable objects, which means two posts can be compared. The comparison is made by the post date and the post slugs.
  • The generated default relative URL of a post and a page are different (e.g. /2000/01/01/my-post.html and /about.html).
  • A page can be placed anywhere but a post can only be placed under _posts folder.
  • A post has more data out of the box for use in Liquid templates (title, URL, date, id, categories, next, previous, tags, content).
  • A post has a unique id.

A post represents a blog post (so it is used to easily create a blog post). A page represents a website page.




回答2:


There are couple difference mostly about how page will be generated and handled:

Post is any document living in _posts directory. If is handled by site.posts collection and final URL will be generated using permalink configured in config yaml file.

Pages are any documents living outside _posts directory - they will always remain relative path to root directory as URL.

Except of that and mentioned by you differences they both work the same. Some plugins are handling them differently, but it's up to plugin developer(there are no guidelines about this topic).



来源:https://stackoverflow.com/questions/15095625/what-are-the-differences-between-a-post-and-a-page-in-jekyll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!