Brajeshwar
Brajeshwar

Reputation: 1520

Avoid directory for some HTML files when permalink setting is pretty in Jekyll

I've "permalink: pretty" in the config and this works pretty well with what I want with my static site (not a blog) - pages with "index.html" inside the folders/pages.

What is the best way to have a specific page or pages such as "error.html" render as "error.html" in my root folder and not "error/index.html"?

P.S. I want to use the default template so I can maintain the site design flow.

EDIT:

So far, here is the working method.

In the S3's "Enable Web Hosting" pane > Error Document have it as "error/index.html". This does work and is fine but I do wish to be able to control how some html's are rendered by Jekyll.

Upvotes: 3

Views: 1022

Answers (3)

Cai
Cai

Reputation: 3649

If you use permalink: pretty in _config.yml, have a 404.md in your jekyll site root path, and want to have a "domain.com/404.html", simply add permalink: in the .md file:

---
layout: page
title: "404: Page Not Found"
permalink: 404.html
---

The 404.html will be in your _site root path.

Upvotes: 4

Polygnome
Polygnome

Reputation: 7795

You can specify the permalink format for each page individually in the YAML Front Matter.

However, Jekyll does not handle 404 errors at all. If you are GitHub pages, what your question indicates, then the 404.html file in the root folder will be served when an 404 error is encountered. The custom 404 MUST NOT be a Jekyll processed page but rather plain HTML. This means you can not specify YAML Front Matter. So basically, when you use GitHub Pages, GitHub will always serve your custom 404 file under the URL that you tried to reach. Period.

If you are hosting your Jekyll page yourself, then you should refer to your web servers manual.

Upvotes: 1

Harshit
Harshit

Reputation: 1

Use 'permalink: none' in your _config.yml file, then it will not create error/index.html after build.

Upvotes: -1

Related Questions