Skip to content

Commit

Permalink
Merge pull request #523 from kaushalmodi/build-front-matter
Browse files Browse the repository at this point in the history
Add test for _build front-matter
  • Loading branch information
kaushalmodi committed Jan 13, 2022
2 parents 95a6760 + 21ebee4 commit 5b3a9c6
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/site/config.toml
Expand Up @@ -17,6 +17,8 @@ enableGitInfo = true

disableFastRender = true # Hugo 0.30

enableInlineShortcodes = true # Hugo 0.52 - https://gohugo.io/templates/shortcode-templates/#inline-shortcodes

[markup]
[markup.highlight]
codeFences = true # default = true
Expand Down
79 changes: 79 additions & 0 deletions test/site/content-org/all-posts.org
Expand Up @@ -7076,6 +7076,85 @@ discarded because the front-matter type is YAML.
#+begin_src toml
# this TOML block will export to the Markdown body
#+end_src
** _build Front-matter Bundle :page_bundles:___build:
:PROPERTIES:
:EXPORT_HUGO_BUNDLE: build-front-matter
:END:
*** _build Front-matter
:PROPERTIES:
:EXPORT_FILE_NAME: _index
:END:

{{{oxhugoissue(358)}}} | [[https://gohugo.io/news/0.65.0-relnotes/#new-in-hugo-core][Hugo v0.65.0 release notes]]

#+begin_export hugo
{{< getpage1.inline >}}
{{ with site.GetPage "do-not-list" }}
<h2>"do-not-list"</h2>
<p>
Found "do-not-list" page -> <a href="{{ .Permalink }}">{{ .Title }}</a>
</p>
<p>
<strong>Content</strong>:
<blockquote>{{ .Content }}</blockquote>
</p>
{{ end }}
{{< /getpage1.inline >}}
#+end_export

#+begin_export hugo
{{< getpage2.inline >}}
{{ with site.GetPage "do-not-render" }}
<h2>"do-not-render"</h2>
<p>
Found "do-not-render" page -> <a href="{{ .Permalink }}">{{ .Title }}</a> (<mark>As this page is not
technically rendered, this link doesn't actually link to that page; it just links to its parent page.</mark>)
</p>
<p>
<strong>Content</strong>:
<blockquote>{{ .Content }}</blockquote>
{{ end }}
</p>
{{< /getpage2.inline >}}
#+end_export

-----

- Note :: An [[https://gohugo.io/templates/shortcode-templates/#inline-shortcodes][/inline shortcode/]] is used above. ~enableInlineShortcodes
= true~ needs to be added to the site config for that to work.
*** _build: Don't list this page :dont_list:
:PROPERTIES:
:EXPORT_FILE_NAME: do-not-list
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :_build '((list . nil))
:END:
#+begin_description
Build this page but don't list it in /list/ pages.
#+end_description

*This is the "do not list" page.*

See the [[../][parent]] list page -- This page is found using the ~.GetPage~
method there, but it won't be listed there under "Posts in
‘posts/build-front-matter/’".
*** _build: Don't render this page :dont_render:
:PROPERTIES:
:EXPORT_FILE_NAME: do-not-render
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :_build '((render . nil))
:END:
#+begin_description
Do not render this page, but.. still list it.
#+end_description

*This is the "do not render" page.*

See the [[../][parent]] list page -- This page is not rendered, but its content
and metadata can be found using the ~site.GetPage~ method. This page
also listed on that parent list page, but the link won't lead to this
page as.. it did not get rendered.

So, with the ~_build.render~ set to ~false~, this page kind of behaves
like a [[https://gohugo.io/content-management/page-resources][Page Resource]] of "page" /ResourceType/. So we can still access
this page's ~.Content~ and other metadata like ~.Title~, etc.
* Date and slug inheritance :inheritance:date:slug:
:PROPERTIES:
:EXPORT_DATE: 2018-02-12
Expand Down
40 changes: 40 additions & 0 deletions test/site/content/posts/build-front-matter/_index.md
@@ -0,0 +1,40 @@
+++
title = "_build Front-matter"
tags = ["front-matter", "page-bundles", "_build"]
draft = false
+++

`ox-hugo` Issue #[358](https://github.com/kaushalmodi/ox-hugo/issues/358) | [Hugo v0.65.0 release notes](https://gohugo.io/news/0.65.0-relnotes/#new-in-hugo-core)

{{< getpage1.inline >}}
{{ with site.GetPage "do-not-list" }}
<h2>"do-not-list"</h2>
<p>
Found "do-not-list" page -> <a href="{{ .Permalink }}">{{ .Title }}</a>
</p>
<p>
<strong>Content</strong>:
<blockquote>{{ .Content }}</blockquote>
</p>
{{ end }}
{{< /getpage1.inline >}}

{{< getpage2.inline >}}
{{ with site.GetPage "do-not-render" }}
<h2>"do-not-render"</h2>
<p>
Found "do-not-render" page -> <a href="{{ .Permalink }}">{{ .Title }}</a> (<mark>As this page is not
technically rendered, this link doesn't actually link to that page; it just links to its parent page.</mark>)
</p>
<p>
<strong>Content</strong>:
<blockquote>{{ .Content }}</blockquote>
{{ end }}
</p>
{{< /getpage2.inline >}}

---

Note
: An [_inline shortcode_](https://gohugo.io/templates/shortcode-templates/#inline-shortcodes) is used above. `enableInlineShortcodes
= true` needs to be added to the site config for that to work.
14 changes: 14 additions & 0 deletions test/site/content/posts/build-front-matter/do-not-list.md
@@ -0,0 +1,14 @@
+++
title = "_build: Don't list this page"
description = "Build this page but don't list it in _list_ pages."
tags = ["front-matter", "page-bundles", "_build", "dont-list"]
draft = false
[_build]
list = false
+++

**This is the "do not list" page.**

See the [parent](../) list page -- This page is found using the `.GetPage`
method there, but it won't be listed there under "Posts in
‘posts/build-front-matter/’".
19 changes: 19 additions & 0 deletions test/site/content/posts/build-front-matter/do-not-render.md
@@ -0,0 +1,19 @@
+++
title = "_build: Don't render this page"
description = "Do not render this page, but.. still list it."
tags = ["front-matter", "page-bundles", "_build", "dont-render"]
draft = false
[_build]
render = false
+++

**This is the "do not render" page.**

See the [parent](../) list page -- This page is not rendered, but its content
and metadata can be found using the `site.GetPage` method. This page
also listed on that parent list page, but the link won't lead to this
page as.. it did not get rendered.

So, with the `_build.render` set to `false`, this page kind of behaves
like a [Page Resource](https://gohugo.io/content-management/page-resources) of "page" _ResourceType_. So we can still access
this page's `.Content` and other metadata like `.Title`, etc.

0 comments on commit 5b3a9c6

Please sign in to comment.