Search code examples
rubyjekylljekyll-extensions

JekyllRB: how to create an online book (force permalink to be like chapter/1)


Jekyll by default uses specified variables to generate permalink. But in my case I need permalink to use page specific variable like chapter to generate url something like /chapters/:chapter instead of using date and other stuff


Solution

  • You can't use any front matter variable to create your permalinks, only the Jekyll defined keys for the type of page.

    To get the URLs you're after, you could use collections, as Wickramaranga said. In your _config.yml, you define your chapters collection:

    collections:
      chapters:
        output: true
        permalink: /chapters/:title/
    

    Then create your chapters, e.g. /_chapters/1.md, /_chapters/2.md.

    That'd create http://localhost:4000/chapters/1/ and http://localhost:4000/chapters/2/