Only been coding with Hugo for just under 2 months and I’m enjoying it immensely but finding some things a little tricky. Usually I am able to figure it out but this has me stuck.
I’ve got a content type “project” and each project has two thumbnail images, one in colour and the same one in black and white. Ideally I’d like to create the black and white (Grayscale) using the Image Filter functions rather than having to manage multiple images.
Just inside my pages range loop I use the global resource to get the image resource for the purpose of applying a filter but everything I try results in an error. Before trying the grayscale I was trying a basic resize as well as other filters/processes just to see that I could do anything with the image but no success at all.
“nil pointer…” or “can’t evaluate field Resources in type string…”
+++
black_and_white_thumb = "/uploads/nmbrs-thumb-bw.jpg"
categories = ["Music"]
date = 2016-07-05T23:00:00Z
excerpt = "Website for Numbers, a Glasgow based record label."
project_images = ["/uploads/nmbrs-001.png", "/uploads/nmbrs-002.png"]
thumb = "/uploads/nmbrs-thumb.jpg"
title = "Numbers"
[project_information]
agency = "Studio Remote, London"
client = "Numbers"
platform_and_tech = "WordPress"
role = "Developer"
website_url = ""
+++
Website for Numbers, a Glasgow based record label.
A tailored tagging system was implemented so the content could be interconnected. The connections are visible via **SVG**lines mapped between the related content.
Global resources need to be in the /assets directory, or a directory mounted to /assets. In your case, leave the images where they are, in /uploads. Then do this…
OK, I’ll need to focus my attention on the module config part as I could get the filters working as you demonstrated but only if I placed an image in assets. Still getting the “nil pointer…” when I try to use the .Params.thumb uploaded image even after adding this to config.toml:
Pretty sure I’ve got it now. The uploads directories were only established when I hooked it up to Forestry CMS. I’m sure these were the default settings.
UPLOAD DIRECTORY
The directory where media is stored inside of git
static/uploads
PUBLIC PATH
The path where media is served from
/uploads
All works locally but the build script fails on Netlify, “nil pointer evaluating resource.Resource.RelPermalink…” I’m not sure I’ll spend anymore time on it at this point but I very much appreciate the previous input as it really helped improve my understanding of certain parts of Hugo.
I’ll need to get a proper understanding of Module Config: mounts but at least I have the starting off point.
Thanks
Edit:
UPLOAD DIRECTORY
The directory where media is stored inside of git
/uploads
Changing this is in Forestry means it all works while following the guidance provided by @jmooring. Just thought I’d post this in case some else encounters this.
I ended up spending time looking at it as the curiosity was too much and its working fine the only thing I’d like to understand is how I can get the uploads to be organised in their own directory inside public after build the like the assets > css are inside in a directory public > css. The uploads are just added to the root of public. I thought specifying a path in the target would achieve this:
target
Where it should be mounted into Hugo’s virtual filesystem. It must start with one of Hugo’s component folders: static, content, layouts, data, assets, i18n, or archetypes. E.g. content/blog.
I thought I could do something like the content/blog example but with assets. The build fails.
Edit: I had only been using an ‘assets’ directory in my theme. Adding an ‘assets’ directory to the project root (Note: assets directory is not created by default.) removing the module mounts configuration and having my uploads added to the assets directory specifically assets > uploads sorted all this. Images are now in public/uploads after build and can be retreived using resources.Get so filters can be applied.
In case someone else encounters the same issue. I’ll attempt to detail it here in as simple terms as possible.
My original approach of adding uploaded images to static/uploads was fine but if there was any possibility of processing those images then it was problematic.
In order to process an asset with Hugo Pipes, it must be retrieved as a resource using resources.Get, which takes one argument: the filepath of the file relative to the asset directory.
As well as filters other tasks like getting the image dimension are much simpler when the file is a resource.
Therefore I change the settings in Forestry CMS to the following: