2

I'm using Jekyll to create a page and the docs suggest that Jekyll has the option to create pages in the root directory, or to create new directories for new pages.

From http://jekyllrb.com/docs/pages/

Where you put HTML files for pages depends on how you want the pages to work. There are two main ways of creating pages:

  • Place named HTML files for each page in your site’s root folder.
  • Create a folder in the site’s root for each page, and place an index.html file in each page folder.
project
-- _includes
-- _site
---- about
------ index.html
----assets
------ css
------ img
------ js
--assets
---- css
---- img
---- js
-- _config.yml
-- about.html
-- index.html

How do I configure Jekyll to create pages in the root directory?

Aaron Benjamin
  • 1,291
  • 3
  • 18
  • 27

2 Answers2

6

If you create an about.html page at the root of you Jekyll folder, it will generated in _site/about.html except if you put a permalink in the front matter.

By default the about page has a permalink (permalink: /about/) it is then generated in _site/about/index.html.

With permalink you can even do :

  • page in pages/mypage.html
  • permalink: my-nice-page.html
  • generated at _site/my-nice-page.html

Note: If you set your global permalink in _config.yml to pretty, all pages will be generated in order to give pretty urls like http://domain.tld/about/ (in _site/about/index.html). You can the change this variable to date or other or put a permalink in your page to override the global one.

David Jacquel
  • 51,670
  • 6
  • 121
  • 147
  • 1
    The only thing I have in the frontmatter is a title. If I remove this, Jekyll places the about.html file in the root directory. If it has a title, it creates an about/ directory with an index.html file. – Aaron Benjamin Jan 02 '15 at 13:51
  • I saw your `_config.yml`. The `permalink: pretty` tells Jekyll to generate pages in folders. I've edited my answer. – David Jacquel Jan 02 '15 at 14:24
1

You place them in whatever your jekyll project folder is. So if you're folder is myjekyllproject then you'll add a file named index.html or about.html. From there you will do a jekyll build. Jekyll will then put include that file in your myjekyllproject/_site folder.

Marc K
  • 261
  • 3
  • 8
  • 23
  • When I build, Jekyll is creating new directories. The output is /about/index.html rather than /about.html – Aaron Benjamin Jan 02 '15 at 04:34
  • In your project folder do you have an about folder with an index.html in it, or an about.html in just the project folder? – Marc K Jan 02 '15 at 04:37
  • Based on that is looks like you have both an about.html and an about/index.html When you do a jekyll serve and go to http://localhost:4000/about.html and http://localhost:4000/about/ do those both display? – Marc K Jan 02 '15 at 04:47
  • no... when I build, jekyll creates the /about directory and index file. It's not creating an about.html file. – Aaron Benjamin Jan 02 '15 at 04:51
  • Do you have frontmatter in the header of your about.html file? – Marc K Jan 02 '15 at 04:56
  • yes, just the title and layout | Edit: that seemed to be the problem :( is there a way to use front-matter without Jekyll creating new directories? – Aaron Benjamin Jan 02 '15 at 05:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/68054/discussion-between-marc-k-and-aaron-benjamin). – Marc K Jan 02 '15 at 05:20
  • Change the permalink to your liking. The way it is defined (or if you use the default), determines how the processed files are distributed. My `_config.yml` simply contains `permalink: date` and it keeps the same directory structure as the original. – Rudy Velthuis Jan 04 '15 at 18:49