Hey, I was wondering if there is a way to get content from pages where draft = true
without actually generating the page in the build.
Use case:
I have a directory of pages each with a .Title
and some are ready to be published, others not. However, I would like to list all the pages linking to the ones where draft = false
and just putting the .Title
when draft = true
. This would prevent people from navigating to the (still in draft) page if they can figure out the URL β which should be pretty simple.
Some code (not tested - but in theory it should work (I might be missing some .Params
or something, but the intent should be clear)
// Directory
...
β
βββ content/
β βββ post-1.md // title = "Hello Hugo" author="Mr. X" draft = false
β βββ post-2.md // title = "Another Title" author="Mr. Y" draft = true
β βββ post-3.md // title = "Yet Another Title" author="Mrs. Z" draft = false
β βββ _index.md // draft = false
...
This is really where the question is (I am 100% sure this is not correct )
// layout/_default/list.html
{{ range .Pages }}
<div>
{{ if eq .draft true }}
{{ .Title }}
{{ else }}
<a href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}
<span>By: {{ .author }}</span>
</div>
{{ end }}
// Desired Output Directory
...
β
βββ pages/
β βββ post-1.html
β βββ post-3.html
β βββ index.html
...
// Desired Output in /pages/index.html
<div>
<a hrfe=".../posts/post-1.html">Hello Hugo</a>
<span>By: Mr. X</span>
</div>
<div>
<span>Another Title</span>
<span>By: Mr. Y</span>
</div>
<div>
<a hrfe=".../posts/post-1.html">Yet Another Title</a>
<span>By: Mrs. Z</span>
</div>
I think that this could be very useful for book and documentation websites which want to indicate that particular content is in the works, but is not ready for public consumption. I would be interested if people have other use cases.
-hs