How to Link to a Page with Page.Url Without the HTML Extension in Jekyll

How to link to a page with page.url without the html extension in Jekyll?

The value returned by {{ page.url }} reflects what the permalink for the page is.

To get the urls to not include the "index.html" part you will need to add a permalink setting to the front matter for each of these pages. This actually removes the need of having all the files named "index.html" and in separate folders.

So your front matter would contain something like:

---
permalink: /scratchpad/level/relative/
---

Note the trailing slash, if you omit this then Jekyll would create a file called "relative" instead of a directory containing an index.html file.

Remove html extension from GitHub Pages

I would assume you would have to use subdirectories (but there may be a simpler way):

/index.html            => http://jasonhoffmann.github.io
/contact/index.html => http://jasonhoffmann.github.io/contact

However, you may have more control using CNAME to redirect the GitHub page to your own domain. Sorry I don't have a definite answer for you, but hopefully this can get you started.

How do I remove the .html extension from not only posts, but pages as well in Jekyll?

This setting in _config.yml will work :

# applies pretty for all
permalink: pretty

# overrides permalink for posts
defaults:
-
scope:
path: ""
type: "posts"
values:
permalink: /:year/:month/:day/:title/

Note that a permalink in a page front matter will override the one in config.

Jekyll extension-less permalinks with markdown

I think you are doing it correctly, it is just a matter of configuring your webserver properly (assuming it supports removing the extension). It works properly locally cause the built in jekyll webserver can do it by default. The docs have info on this here:

http://jekyllrb.com/docs/permalinks/#extensionless-permalinks

On AWS S3 it says you can host with extensionless urls by uploading files with no extension at all, and then setting the content type to text/html. I don't think it is possible to get jekyll to output contact.html as just contact with no extension. So you get the web server to remove the extension, if it supports that (on s3 I use the trailing /).

This has some interesting info too:
https://github.com/jekyll/jekyll/issues/3345

How do I remove file extensions from a URLs of a GitHub Pages site (Jekyll) while keeping my HTML files in one folder?

In about.html use the following permalink

---
title: My about title
permalink: /about/
---

And in contact.html:

---
title: My contact title
permalink: /contact/
---

To remove trailing slashes you need to configure the web server

Then you can create links hardcoding the URL or using the link tag:

[Link to a page]({{ site.baseurl }}{% link about.html %})
#Or
<a href="/about/">About</a>

Another way is to create the following file structure:

├── index.html
├── about
│   └── index.html
└── contact
  └── index.html

Then be sure your permalinks do not include the .html extension in _configu.yml and it will automatically generate the URLs.

html-proof jekyll website with .html extension-less internal links

I've got a new working PR for this in https://github.com/gjtorikian/html-proofer/pull/311. You can use it like this until it gets merged:

Gemfile: gem 'html-proofer', github: "Floppy/html-proofer", branch: "jekyll-3-extensionless-links"

It adds a assume_extension option: HTML::Proofer.new("./_site", assume_extension: ".html").run

Or you can use the --assume-extension=.html command line switch if you're using the binary.


Edit: this was released and available in html-proofer 3.0.4 I'm currently using. The api is slightly different, assume_extension has become a switch, defaulting to false. So you'd do:

HTML::Proofer.new("./_site", assume_extension: true).run

or

htmlproofer ./Site --assume-extension

It works in combination with the extension options if you'd like a different extension for your pages than the default .html.

Can Jekyll 3.0.x _include_ the index.html in page.url

You need to specify the .html extension in the permalinks setting:

 permalink: /blog/:slug.html

Then all the pages will have that extension.

update

Create a fresh 3.0 install:

$ jekyll _3.0_ new mysite
$ cd mysite

Edit about.html and remove the custom permalink to see the changes after we generate pages with the .html extension:

---
layout: page
title: About
permalink: /about/ <--- delete
---

Specify different permalinks for pages and posts in _config.yml:

defaults:
-
scope:
type: pages
values:
permalink: /:path/:basename:output_ext
-
scope:
type: posts
values:
permalink: /:year/:month/:day/:title.html

Add the following code to index.html to see the available pages and its urls:

<p>Current page: {{page.url}}</p>

{% for my_page in site.pages %}
{% if my_page.title %}
url: {{my_page.url }}
{% endif %}
{% endfor %}

Now serve the website $ jekyll _3.0_ serve and access to http://localhost:4000/index.html



Related Topics



Leave a reply



Submit