Skip to content

Commit

Permalink
Improve tests added in #523
Browse files Browse the repository at this point in the history
- Don't use inline shortcodes; they look messy and are not very
  reusable
- Add a better and proper "getpage" shortcode.

Ref #358
  • Loading branch information
kaushalmodi committed Jan 13, 2022
1 parent 5b3a9c6 commit eaadde8
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 85 deletions.
2 changes: 0 additions & 2 deletions test/site/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ 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
77 changes: 33 additions & 44 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -7085,52 +7085,22 @@ discarded because the front-matter type is YAML.
: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]]
{{{oxhugoissue(358)}}} | [[https://gohugo.io/content-management/build-options/][~_build~ page params]]

#+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.
#+hugo: {{< getpage "do-not-list" >}}
#+hugo: {{< getpage "do-not-render" >}}
#+hugo: {{< getpage "do-not-render-or-list" >}}
*** _build: Don't list this page :dont_list:
:PROPERTIES:
:EXPORT_FILE_NAME: do-not-list
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :_build '((list . nil))
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :_build '((list . never))
:END:
#+begin_description
Build this page but don't list it in /list/ pages.
#+end_description

[[https://gohugo.io/content-management/build-options/#list][~_build.list~ option]]

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

See the [[../][parent]] list page -- This page is found using the ~.GetPage~
Expand All @@ -7139,22 +7109,41 @@ method there, but it won't be listed there under "Posts in
*** _build: Don't render this page :dont_render:
:PROPERTIES:
:EXPORT_FILE_NAME: do-not-render
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :_build '((render . nil))
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :_build '((render . never))
:END:
#+begin_description
Do not render this page, but.. still list it.
#+end_description

[[https://gohugo.io/content-management/build-options/#render][~_build.render~ option]]

*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.
and metadata can be found using the ~site.GetPage~ method.

#+begin_mark
This page is listed on that parent list page, but the link won't lead
to this page as.. it did not get rendered. That link will point to
that page itself because with ~render~ set to ~false~ or ~"never"~,
the ~.Permalink~ and ~.RelPermalink~ get set to ~""~.
#+end_mark
*** _build: Don't render or list this page :dont_render:dont_list:headless:
:PROPERTIES:
:EXPORT_FILE_NAME: do-not-render-or-list
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :_build '((render . nil) (list . nil))
:END:
#+begin_description
Do not render or list this page.
#+end_description

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

See the [[../][parent]] list page -- This page is not rendered, but its content
and metadata can be found using the ~site.GetPage~ method.

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.
Setting both ~render~ and ~list~ to ~false~ or ~"never"~ makes this
page behave like a *headless* page bundle -- [[https://github.com/gohugoio/hugo/issues/6412#issuecomment-573446730][ref]].
* Date and slug inheritance :inheritance:date:slug:
:PROPERTIES:
:EXPORT_DATE: 2018-02-12
Expand Down
35 changes: 4 additions & 31 deletions test/site/content/posts/build-front-matter/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,10 @@ 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)
`ox-hugo` Issue #[358](https://github.com/kaushalmodi/ox-hugo/issues/358) | [`_build` page params](https://gohugo.io/content-management/build-options/)

{{< 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 >}}
{{< getpage "do-not-list" >}}

{{< 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 >}}
{{< getpage "do-not-render" >}}

---

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.
{{< getpage "do-not-render-or-list" >}}
4 changes: 3 additions & 1 deletion test/site/content/posts/build-front-matter/do-not-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ 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
list = "never"
+++

[`_build.list` option](https://gohugo.io/content-management/build-options/#list)

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

See the [parent](../) list page -- This page is found using the `.GetPage`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
+++
title = "_build: Don't render or list this page"
description = "Do not render or list this page."
tags = ["front-matter", "page-bundles", "_build", "dont-render", "dont-list", "headless"]
draft = false
[_build]
render = false
list = false
+++

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

See the [parent](../) list page -- This page is not rendered, but its content
and metadata can be found using the `site.GetPage` method.

Setting both `render` and `list` to `false` or `"never"` makes this
page behave like a **headless** page bundle -- [ref](https://github.com/gohugoio/hugo/issues/6412#issuecomment-573446730).
15 changes: 8 additions & 7 deletions test/site/content/posts/build-front-matter/do-not-render.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ description = "Do not render this page, but.. still list it."
tags = ["front-matter", "page-bundles", "_build", "dont-render"]
draft = false
[_build]
render = false
render = "never"
+++

[`_build.render` option](https://gohugo.io/content-management/build-options/#render)

**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.
and metadata can be found using the `site.GetPage` method.

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.
<mark>This page is listed on that parent list page, but the link won't lead
to this page as.. it did not get rendered. That link will point to
that page itself because with `render` set to `false` or `"never"`,
the `.Permalink` and `.RelPermalink` get set to `""`.</mark>
10 changes: 10 additions & 0 deletions test/site/layouts/shortcodes/getpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{ $page := (.Get 0) }}
{{ with site.GetPage $page }}
<h2 style="color: blue;">"{{ $page }}"</h2>
<h3>Page Metadata</h3>
{{ partial "debugprint" . }}
<h3>Page Params</h3>
{{ partial "debugprint" .Params }}
<h3>Page Content</h3>
<blockquote>{{ .Content }}</blockquote>
{{ end }}

0 comments on commit eaadde8

Please sign in to comment.