Hugo 0.32 Related Questions/Discussions

On a more serious note. It was just a choice by me. Kind would confuse it with the Page Kind, which is different. This is a MIME type hybrid. There is page and image, but all the other values are fetched from the media type (json, xml, css etc.)

I’m trying to add a json manifest as a Page Resource that would list all the resources while providing extra informations (file icon, description, ref. etc…)
For this I created a shortcode to be added to the markdown. It will list the files in the manifest, and associate them with the corresponding Page Resource (targeted by its prefix)

I need to target the hugo rel path of the json and do it like this :

{{ $AbsPath := strings.Split .AbsSourceFilename "/content/" }}
{{ $RelPath := printf "/content/%s" (index $path 1) }}
{{ $manifest := getJSON $RelPath }}

I just wonder if there is not a better approach to this. This doesn’t seem to be perfect since one can have a “/content/” subdirectory inside its content path.

Thanks.

No, there is no simpler way, but I’m not sure you want to go down that route. When I added JSON files as example in my resources test site, I had client side handling in mind (JavaScript).

If you want to add metadata to pages, I suggest you use either page front matter or data files.

I may consider adding a Content method to Resource, but I’m not sure …

I would love that Content :wink:
The manifest is more about adding metadata to files, like pdf and such. I guess I could use front matter for this as well, but if we have too many files… Will look into it!

Thanks for your help!

You might be interested in this:

Please chime in with ideas/wishes.

Love it! Thanks.

Following along with @RickCogley’s example, I’m trying to use the new page bundles and a shortcode within my content markdown. Something isn’t clicking for me as I’m getting the following during build:

template: shortcodes/img.html:1:12: executing "shortcodes/img.html" at <$.Page.Resources.Get...>: can't evaluate field Resources in type *hugolib.Page

Here’s my content structure:

content
-- work
   -- project-name
       -- index.md
       -- images
          -- example.jpg

In layouts/shortcodes/img.html

{{ $img := $.Page.Resources.GetByPrefix (.Get 0) }}
<figure>
    <img src="{{ $img.RelPermalink }}" alt="(.Get 1)" />
    <figcaption>(.Get 1)</figcaption>
</figure>

And in my Markdown for a project:

{{< img "example" "Example image" >}}

While this seems to be in line with the discussion above, I guess I’m missing something. Any help?

Edit: I should note I’m on v0.32.4

Your code looks correct. But have you seen the example shortcode at the Docs for Hugo 0.32?

In this example the parameter by position is fetched in the form of .Page.Resources.GetByPrefix (.Get 0) without the $

I don’t think you need to Access the Global Context in this case, but then again I’m not 100% sure why you have that error.

Try this and if the above suggestion fixed your issue tell us.

However if your issue is not fixed then do post a link to a repo with your Hugo or a test project’s source code so that others can see what’s happening.

Error message says you’re not.

I removed the $ and had the same error.

Repo is at https://github.com/jeremybise/thosegeeks-hugo

I assume I am?

❯ hugo version
Hugo Static Site Generator v0.32.4 darwin/amd64 BuildDate: 2018-01-11T14:03:42-05:00

Running hugo spits out this with the above code:

❯ hugo
Building sites … panic: reflect: Method on nil interface value [recovered]
        panic: reflect: Method on nil interface value

goroutine 62 [running]:
text/template.errRecover(0xc42068f538)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:146 +0x1c5
panic(0x1953340, 0x26abe80)
        /usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491 +0x283
reflect.Value.Method(0x19aa640, 0xc4207ce7f8, 0x94, 0x1, 0xc, 0x0, 0x0)
        /usr/local/Cellar/go/1.9.2/libexec/src/reflect/value.go:1135 +0x162
reflect.Value.MethodByName(0x19aa640, 0xc4207ce7f8, 0x94, 0xc4203b4365, 0xc, 0x94, 0x1,0x1996120)
        /usr/local/Cellar/go/1.9.2/libexec/src/reflect/value.go:1170 +0x11b
text/template.(*state).evalField(0xc42068f4b8, 0x19c8b60, 0xc420318f40, 0x16, 0xc4203b4365, 0xc, 0x2b04ac0, 0xc4202666c0, 0xc42055a030, 0x1, ...)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:559 +0x23f
text/template.(*state).evalFieldChain(0xc42068f4b8, 0x19c8b60, 0xc420318f40, 0x16, 0x19aa640, 0xc4207ce7f8, 0x94, 0x2b04ac0, 0xc4202666c0, 0xc4204f1f10, ...)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:528 +0x22a
text/template.(*state).evalVariableNode(0xc42068f4b8, 0x19c8b60, 0xc420318f40, 0x16, 0xc4202666c0, 0xc42055a030, 0x1, 0x1, 0x0, 0x0, ...)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:516 +0x192
text/template.(*state).evalCommand(0xc42068f4b8, 0x19c8b60, 0xc420318f40, 0x16, 0xc420266660, 0x0, 0x0, 0x0, 0x19aa640, 0xc4207ce7f8, ...)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:440 +0x735
text/template.(*state).evalPipeline(0xc42068f4b8, 0x19c8b60, 0xc420318f40, 0x16, 0xc42051f950, 0x0, 0x0, 0x94)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:408 +0x115
text/template.(*state).walk(0xc42068f4b8, 0x19c8b60, 0xc420318f40, 0x16, 0x2b04460, 0xc4202666f0)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:234 +0x4af
text/template.(*state).walk(0xc42068f4b8, 0x19c8b60, 0xc420318f40, 0x16, 0x2b047c0, 0xc420266480)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:242 +0x11d
text/template.(*Template).execute(0xc420523f40, 0x2af94e0, 0xc420758000, 0x19c8b60, 0xc420318f40, 0x0, 0x0)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:197 +0x1f9
text/template.(*Template).Execute(0xc420523f40, 0x2af94e0, 0xc420758000, 0x19c8b60, 0xc420318f40, 0xc4206855c8, 0x1062c00)
        /usr/local/Cellar/go/1.9.2/libexec/src/text/template/exec.go:180 +0x53
html/template.(*Template).Execute(0xc420266420, 0x2af94e0, 0xc420758000, 0x19c8b60, 0xc420318f40, 0xc4206855f0, 0x185db62)
        /usr/local/Cellar/go/1.9.2/libexec/src/html/template/template.go:122 +0x8c
github.com/gohugoio/hugo/tpl.(*TemplateAdapter).Execute(0xc4205c83a0, 0x2af94e0, 0xc420758000, 0x19c8b60, 0xc420318f40, 0x0, 0x0)
        /private/tmp/hugo-20180111-58747-1p55h4c/hugo-0.32.4/src/github.com/gohugoio/hugo/tpl/template.go:81 +0x83
github.com/gohugoio/hugo/hugolib.renderShortcodeWithPage(0x2afe4a0, 0xc4205c83a0, 0xc420318f40, 0x0, 0x0)
        /private/tmp/hugo-20180111-58747-1p55h4c/hugo-0.32.4/src/github.com/gohugoio/hugo/hugolib/shortcode.go:721 +0xd3
github.com/gohugoio/hugo/hugolib.renderShortcode(0x1a60635, 0x2, 0x1a61ebf, 0x4, 0x1a62a83, 0x4, 0xc4206ddea0, 0x17, 0xc42022cbe8, 0x3, ...)
        /private/tmp/hugo-20180111-58747-1p55h4c/hugo-0.32.4/src/github.com/gohugoio/hugo/hugolib/shortcode.go:340 +0x631
github.com/gohugoio/hugo/hugolib.prepareShortcodeForPage.func1(0x198be00, 0xc4207ce1e0,0xc420685b78, 0x1b0ba88)
        /private/tmp/hugo-20180111-58747-1p55h4c/hugo-0.32.4/src/github.com/gohugoio/hugo/hugolib/shortcode.go:261 +0xa8
github.com/gohugoio/hugo/hugolib.(*shortcodeHandler).executeShortcodesForDelta(0xc4204115c0, 0xc420764000, 0x1b, 0xc420685ca0)
        /private/tmp/hugo-20180111-58747-1p55h4c/hugo-0.32.4/src/github.com/gohugoio/hugo/hugolib/shortcode.go:406 +0xd1
github.com/gohugoio/hugo/hugolib.handleShortcodes(0xc420764000, 0xc4203de400, 0x3ef, 0x3ef, 0x0, 0x0, 0x0, 0x0, 0x0)
        /private/tmp/hugo-20180111-58747-1p55h4c/hugo-0.32.4/src/github.com/gohugoio/hugo/hugolib/hugo_sites.go:577 +0x1b5
github.com/gohugoio/hugo/hugolib.(*Page).prepareForRender(0xc420764000, 0xc42040e100, 0x1, 0x0)
        /private/tmp/hugo-20180111-58747-1p55h4c/hugo-0.32.4/src/github.com/gohugoio/hugo/hugolib/page.go:1038 +0x1a3
github.com/gohugoio/hugo/hugolib.(*Site).preparePagesForRender.func1(0xc42040e100, 0xc42045b8c0, 0xc420693500, 0xc420471710)
        /private/tmp/hugo-20180111-58747-1p55h4c/hugo-0.32.4/src/github.com/gohugoio/hugo/hugolib/hugo_sites.go:551 +0xb6
created by github.com/gohugoio/hugo/hugolib.(*Site).preparePagesForRender
        /private/tmp/hugo-20180111-58747-1p55h4c/hugo-0.32.4/src/github.com/gohugoio/hugo/hugolib/hugo_sites.go:548 +0xd3

That all references 0.32.4. If I’m missing something, please let me know.

Thanks!!

Um… I cannot find your shortcode in that repo.

Aaaaaaand I failed to push. My bad. It’s all there now.

In your content files you are calling your shortcode like this:

{{< img "images/marion-trash.jpg" "Marion trash pickup schedule widget" >}}

That images/ is the culprit for the failure of your project to generate.

You should put your images directly next to your index.md as is the recommended way for .Resources

I haven’t seen in the Docs or in @bep 's Test Repo anything about Page Bundles with images in a separate folder. Every example I’ve seen had images etc alongside index.md

Couple things going on here it seems.

First, @alexandros, removing the images/ and moving the files adjacent did indeed make it work. I guess in interpreted from the hierarchy screenshot in the 0.32 HOWTO, there is a folder there called hugo-is-cool and it has an images folder and I just figured it would work. I was wrong. So thank you!

Second, I figured out the Resources issue I had above. I’m very new to Hugo and found victor-hugo from Netlify and thought it was a cool starting point. The issue is its gulp uses hugo-bin, which hasn’t been updated to 0.32 yet. I can run hugo and all works, but I guess I can’t run the fancy script until hugo-bin from npm gets updated.

Yes. But I haven’t seen the /hugo-is-cool/ hierarchy with an /images/ subfolder in action. Not in the Hugo 0.32 test repo. But maybe @bep can tell me where I’m wrong and how this is supposed to work.

@jeremybise you can get rid of the bin directory, and you should and replace with a netlify.toml similar to the one below.

# Global settings applied to the whole site.
[build]
  command = "hugo"
  publish = "public"

# The default version you use for production if you don't use context below
[build.environment]
  HUGO_VERSION = "0.32.3"

# build a preview of the site (Drafts and Future dates also)
[context.deploy-preview]
  command = "hugo --buildFuture"

[context.production.environment]
  HUGO_VERSION = "0.32.3"
# you can lock a version of hugo for a deploy preview
[context.deploy-preview.environment]
  HUGO_VERSION = "0.32.3"
# you can lock a version of hugo for a branch-deploy (other than previews)
[context.branch-deploy.environment]
  HUGO_VERSION = "0.32.3"

Then make sure to edit the gulp command to use hugo instead of the bin path which you can test local if you have hugo setup in a path on your machine.

The context on Netlify allows for you to target a Hugo version also by the type of deploy. So you can branch the master of your repo and test the latest and greatest on netlify without affecting production.

I think I’m too dumb to figure out how to make that gulpfile run hugo rather than what it does now.

Dude, you are not dumb. You chose this stack!

PM me or hit me up in the Netlify chat with your repo and I will PR the change for you.

I would have created an issue in GitHub, but maybe it’s better to discus it here beforehand.

It appears the .RelPermalink and .Permalink properties of page resources of type “page” are empty.
This breaks the .GetByPrefix method which relies on it.
This makes it impossible to get a page resources by its prefix. Ex:

.
└── content
    └── post
        └── that-new-post
            ├── index.md
            └── credits.md

.Resources.GetByPrefix "credits" returns “nil”