How to set index pages of site subsections?

Hello,

I have a “content” directory that is structured like this:

├── about.md
├── contact.md
├── courses
│   ├── course1.md
│   ├── course2.md
│   └── courses_index.md
├── projects
│   ├── projects_index.md  
│   ├── project1.md
│   └── project2.md
└── writings
    ├── paper1.md
    ├── paper2.md
    └── writings_index.md 

I want that to produce urls like:

paper1.md -> mysite://writings/title-of-paper1/
paper2.md -> mysite://writings/title-of-paper2/
writings/writings_index.md -> mysite://writings

and the same in all the other sections. I have written this in config.toml:

[permalinks]
post = "/:year/:month/:title/"
projects = "/projects/:title/"
writings = "/writings/:title/"
courses = “/courses/:title/”

it works for all pages, except for the *index.md ones. Even if I write e.g. “url: /writings/” or “url: /writings/index.html” in the frontmatter of writings_index.md doesn’t change anything. In all cases, “hugo server” gives me just a list of all pages in that sections when I go to /writings/

what am I doing wrong?
Thanks!

I think the names of your “index” pages are incorrect and should be “_index.md”.

This may help: https://gohugo.io/overview/source-directory#content-for-home-page-and-other-list-pages

1 Like

hi @magikstm,

using _index.md does not change anything either. More exactly, if I move writings/writings_index.md to writings/_index.md, remove the url parameter from its frontmatter (and do the same for projects_index.md, courses_index.md etc…)…

what I get when I load localhost:1313/writings/ is just a list, with summaries, of all the OTHER files in the writings directory, except the one renamed to _index.md.

So here hugo is NOT behaving as in that documentation page. By “here” I mean 2 different linux computers, one with fedora 64bit, hugo v0.18, another with ubuntu 16.04 64 bit, hugo v0.18.1

index.md and _index.md in the section not work in 0.18, try 0.17.

Hi @Mikhail,
I believe I have to partially correct what you said:

index.md and _index.md in the section not work in 0.18, try 0.17”

I have installed hugo 0.17 and tried again. index.md IS recognized and used to generate the index page of a section, meaning that courses/index.md becomes courses/index.html

_index.md, instead is treated as normal page by hugo0.17. A file called projects/_index.md was converted to projects/_index/index.html

The problem is that some developers do not believe that the _index.md does not work in 0.18. So if you want to have an index.md like 0.17, it is necessary to wait for more bug reports.

for what it’s worth, personally I equally dislike both index.md and _index.md, and even giving a full path in the frontmatter like "url: writings/index.html". Personally, I would really prefer to be able to say in the frontmatter something like:

isindex: "true"

to tell hugo “make of this file the /index.html of the folder it is in, period”. That way, I could give all my files whatever unique filenames I wanted, and without having to rewrite the url: keywords if I decide to move folders in other places.

I’m not sure how having a isIndex flag differs from the _index naming convention – conceptually it is the same thing.

_index.md works fine.

it would just be more convenient in practice, at least for me. But I agree, that’s why I started with “for what it’s worth, personally I…”

No, it does NOT. Right now, I have both 0.17 (as hugo0.17) and 0.18.1(as hugo) installed. Hugo0.17 works as you say (I still have the multilingual site problems I describe in another thread, but let’s do one thing at a time).

Hugo 0.18.1 instead does not recognize the naming convention, as you can see in this output below, just copied from my terminal (Linux Fedora 25, 64 bit, in case it matters, using the statically linked 64bit executable for Linux ). Instead of getting the page titled “Selected Writings” I get a listing of all the pages in the “writings” folder (starting from the one titled “Ebooks”, which is in the file content/writings/ebooks.md).

>$ cat content/writings/_index.md 
---
title: Selected Writings
date: 2016-12-30
---

this is a test index file of the "writings" section

>$ rm -rf public/ ; hugo >& hugo.0.18log
>$ w3m -dump public/writings/index.html | head -7
Home
About
Writings

Ebooks!
>$ hugo version
Hugo Static Site Generator v0.18.1 BuildDate: 2016-12-30T11:02:43+01:00
1 Like

Hey, bep. If it works really well, show me sample code!

The behavior is different between 0.17 and 0.18.

Why did you make a serious change just before the New Year 's holiday?

So people could have something nice to play with in the holidays? Seriously, Hugo 0.17 is still available.

Hugo 0.19 will, if someone wants to spend time implementing it, have a feature where you can turn off rendering of kinds of pages, so you can turn off automatic section rendering, and you will get back your “index.md” hacks behaviour, see

But you should really work on your communication skills. This is FREE software – people are spending their spare time implementing this great piece of software. Show some gratitude and stop whining.

Hugo 0.18 was announced as stable here on this forum one month before release, asking people to try it out and report back any issues. Many did, and none of them reported any “index.md” issues. None. So, we have tested hundreds of Hugo sites manually, and the automatic test coverage in Hugo is excellent – so this is one of the better tested open source releases so far this century.

So, if you have any CONCRETE issues with this release, i.e. not about the before mentioned naming conflict issue where both the section list and a page is rendered to the same “index.html”, then point us to the failing GitHub repo or similar, so we can have a look at it.

I have uploaded to the cloud site that does not display the content of _inex.md in the section “archive”. https://cloud.mail.ru/public/JTf2/ANtND6U9W
This section generated 0.17 version can be seen here: http://andreeva.newgod.su/archive/

I have checked your site, and it works fine for me.

Note that for /archive/_index.md you will have to provide a template for the section (look in the documentation how Hugo looks up templates) – now it defaults to the /_default/list.html which may or may not be what you want. If you modify this template, add {{ .Content }} you will see that the content from _index.md is picked up.

I understand that the documentation should be improved in this area.

Thank you. Now I understand. I created the copy of the /layouts/_default/single.html and renamed it to /layouts/_default/section.html. And now I have the _index.md in the sections is displayed as static content.

1 Like

@Mikhail,
If you can help improve the docs about this new feature, please do. Or point to where things are not clear. See also #2827. Thanks

Sorry, my English is very bad, I often write through a translator. In fact, in Hugo 0.18 appeared a new template /layouts/_default/section.html and is now necessary to create a new page in the documentation for it.
It is necessary for it to create the same page as for the single and the list.

The best option is to maintain compatibility with previous versions of Hugo. To do this, need to implement the following algorithm.

if exist index.md render it through single.html (as in previous versions)
if exist _index.md render it through section.html
if not exist (_index.md and index.md) render it through list.html  (as in previous versions)
if exist both (_index.md and index.md) generate an error message or do something else.

If this algorithm was able to realize that would have kept compatibility with previous versions.

@rdwatters, v0.18-DEV was pre-0.18, so you need to update to a new version for this to be relevant.

@moorereason Thanks, brother. Amazing that I didn’t notice that. I feel like a heel.

Ran go get with -u -v and am all good now. Sorry @bep.