List .md in content subfolders using .Site.GetPage

Hi,

My directory structure is the following:

└── content
    ├── technical_note
        ├── python
        |   ├── post-1.md
        |   ├── post-2.md
        ├── linux
            ├── post-1.md
            ├── post-2.md

I would like to have a page that lists the content of my subdirectory technical_note and hyperlinks to the corresponding pages similar to the following:


Python

  • Post 1
  • Post 2

Linux

  • Post 1
  • Post 2

I have the following piece of code in themes/acedemic/layouts/summary_page/single.html:

        <h4 class="card-header">Python</h4>
        <div class="card-body">
          <ul>
            {{ $section := site.GetPage "/technical_note/python" }}
            {{ with $section }}
            {{ range .Pages }}
            <li><a href="{{.Permalink}}">{{.Title}}</a></li>
            {{ end }}
            {{ end }}
          </ul>
        </div>

        <h4 class="card-header">Linux</h4>
        <div class="card-body">
          <ul>
            {{ $section := site.GetPage "/technical_note/linux" }}
            {{ with $section }}
            {{ range .Pages }}
            <li><a href="{{.Permalink}}">{{.Title}}</a></li>
            {{ end }}
            {{ end }}
          </ul>
        </div>

I created a file named index.html in technical_note containing

---
title: "TEST technical layout"
authors: ["me"]
date: 2020-04-08T22:44:12+02:00
description:  "Layout test"
draft: false
type: summary_page
---

Nothing appears in the website. I would appreciate any help with this. The repository is located in: https://github.com/othrif/notes

Generally, the type of page you want is considered a “list” type, since it’s listing the contents of a section.

So the typical way you could do this would be as follows:

└── content
    ├── technical_note
        ├── _index.html
        ├── python
        |   ├── post-1.md
        |   ├── post-2.md
        ├── linux
            ├── post-1.md
            ├── post-2.md

So if you renamed /layouts/summary_page/single.html to /layouts/summary_page/list.html I think it will work.

For reference, the applicable row is in the docs is:

Section list for "posts" section with type set to "blog"

and

/layouts/summary_page/list.html

would match the 6th on that list because of the type you set in the front matter.

Thanks @angus for the feedback, it still doesn’t work by replacing single.html by list.html. I will take a closer look at the documentation you reference.

Did you also rename index.html to _index.html in technical_notes?

I should have called out that change specifically, it’s only noted in the directory listing.

Hi @angus, It worked! thanks a lot! I spent way too much time with this, to realize it has such a simple solution!

Your python and linux folder are not technically a section (put an “_index.md” file in it and it will become one.

So, to list these posts you cand do (site.GetPage "technical_note").RegularPages or something.

Note that if they had been sections, you can in a recent Hugo version do: (site.GetPage "technical_note").RegularPagesRecursive to get “all below”.

I have upgraded to 0.69.0 and this works too! thanks @bep

[edited as the question is not longer relevant here.]

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.