Setting url in front matter and breadcrumb behaviour

Given a page

  1. located at /content/authorship/author-1.md, and
  2. with the front matter parameter url: authors/author-1/portrait,

the page is published as expected under public/authors/author-1/portrait.`

The breadcrumb.html partial below, however, finds the authorship section as its ancestor, and not, as I was expecting, the section where it is published: authors/author-1.

<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    {{ range .Ancestors.Reverse }}
      {{if not .Page.IsHome}}
        <li class="breadcrumb-item">
          <a href="{{ .RelPermalink }}">
            {{ with .Params.authors }}
              {{ delimit . ", " " og " }}:
            {{ end }}
            {{ .LinkTitle }}
          </a>
        </li>
      {{end}}
    {{ end }}
    <li class="breadcrumb-item active">
      <a aria-current="page" href="{{ .RelPermalink }}">
        {{ with .Params.authors }}
          {{ delimit . ", " " og " }}:
        {{ end }}
        {{ with .Page.Params.partTitle }}
          {{ . }}:
        {{end}}
        {{ .LinkTitle }}
      </a>
    </li>
  </ol>
</nav>

An empty breadcrumb from the parent (headless an untitled) authorship section is
rendered:

<ol class="breadcrumb">
  <li class="breadcrumb-item">
    <a href=""> </a>
  </li>
  <li class="breadcrumb-item active">
    <a aria-current="page" href="/authors/author-1/authorship/">Authorship</a>
  </li>
</ol>

What I’m looking for is this:

<ol class="breadcrumb">
  <li class="breadcrumb-item">
    <a href="/authors/">authors</a>
  </li>
  <li class="breadcrumb-item">
    <a href="/authors/author-1">Author 1</a>
  </li>
  <li class="breadcrumb-item active">
    <a aria-current="page" href="/authors/author-1/authorship/">Authorship</a>
  </li>
</ol>

I am running Hugo v0.134.2

i would say, Ancestors walks the source tree not the published one. it

Returns a collection of Page objects, one for each ancestor section of the given page.

with a manual url setup there might be no page at the some of the published path components.

imho you will have to parse the pages url yourself in that case.

if there is no constraint I would change the file tree and avoid manual urls.

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