Toni Homedes i Saun
Toni Homedes i Saun

Reputation: 716

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

Seen many questions asking how to omit index.html in previous versions of Jekyll, but I do want to include it.

Is there any config variable or other to make Jekyll 3.0.x include it?

By page I'm refering to the object you get when doing something like

<ul>
{% for page in site.pages %}
  <li>{{ page.url }}</li>
{% endfor %}
</ul>

Not to the current page.

Found this solution, but it's not very practical:

    {% assign last_url_char = page.url | split: '' | last %}
    {% if last_url_char == '/' %}
    {%    assign page_url = page.url | append: "index.html" %}
    {% else %}
    {%    assign page_url = page.url %}
    {% endif %}

Upvotes: 2

Views: 436

Answers (1)

marcanuy
marcanuy

Reputation: 23972

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

Upvotes: 1

Related Questions