Draft page being returned in GetPage

In index.html we have this code

{{ $headless := .Site.GetPage "/homepage" }}
{{ $reusablePages := $headless.Resources.ByType "page" }}
{{ $reusablePages := sort $reusablePages ".Params.weight" }}
{{ range first 1 $reusablePages }}
    ... HTML to render
{{ end }}

which will render the first page in $reusablePages. It works well when testing with hugo server. However, when adding the draft: true to the frontmatter of the accompanying markdown file, I expect this to not actually render any content. However, it renders the HTML, leaving {{ .Title }} rendered as well as an <a> tag with the permalink to the page.

Is there something I need to do when getting the reusable pages to prevent grabbing draft content?

Note - this also happens with the date front matter set in the future
Note - occurs in hugo build as well

If my memory serves me well:

  • Page resources does not have any concept of being “drafted” (or expired).
  • What you want is probably to put the reusable pages in a headless section.

If you rename the index.md to /content/homepage/_index.md file, you should be able to do:

{{ $headless := site.GetPage "homepage" }}
{{ $firstPage := index $headless.Pages 0  }}

The above will respect draft, expiryDate etc.