Jekyll Filename Without Date

后端 未结 3 1474
离开以前
离开以前 2021-02-03 20:15

I want to build documentation site using Jekyll and GitHub Pages. The problem is Jekyll only accept a filename under _posts with exact pattern like YYYY-MM-DD

相关标签:
3条回答
  • 2021-02-03 21:05

    I guess that you are annoyed with the post url http://domaine.tld/category/2014/11/22/post.html.

    You cannot bypass the filename pattern for posts, but you can use permalink (see documentation).

    _posts/2014-11-22-other-post.md

    ---
    title:  "Other post"
    date:   2014-11-22 09:49:00
    permalink: anything-you-want
    ---
    

    File will be anything-you-want/index.html.

    Url will be http://domaine.tld/anything-you-want.

    0 讨论(0)
  • 2021-02-03 21:20

    Don't use posts; posts are things with dates. Sounds like you probably want to use collections instead; you get all the power of Posts; but without the pesky date / naming requirements.

    https://jekyllrb.com/docs/collections/

    I use collections for almost everything that isn't a post. This is how my own site is configured to use collections for 'pages' as well as more specific sections of my site:

    0 讨论(0)
  • 2021-02-03 21:22

    What I did without "abandoning" the posts (looks like using collections or pages is a better and deeper solution) is a combination of what @igneousaur says in a comment plus using the same date as prefix of file names:

    1. Use permalink: /:title.html in _config.yml (no dates in published URLs).
    2. Use the format 0001-01-01-name.md for all files in _posts folder (jekyll is happy about the file names and I'm happy about the sorting of the files).

    Of course, we can include any "extra information" on the name, maybe some incremental id o anything that help us to organize the files, e.g.: 0001-01-01-001-name.md.

    0 讨论(0)
提交回复
热议问题