Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include working example of hugos image porcessing with netlify #19

Closed
brasilikum opened this issue May 8, 2018 · 7 comments · Fixed by #784
Closed

Include working example of hugos image porcessing with netlify #19

brasilikum opened this issue May 8, 2018 · 7 comments · Fixed by #784

Comments

@brasilikum
Copy link

brasilikum commented May 8, 2018

Hugo has powerful image processing capabilities built in, however they are limited to a “Page Bundle” layout, where your images live in the same folder as the content that is referencing them. NetlifyCMS does not (yet?) support this layout.
Instead, all images are stored in one folder under /static.

It is possible to make netlify and Hugo image processing work together by moving the image folder inside of content and making it a “headless” (non-rendered) section. Access can be provided via partials.

I got this to work after a lot of trail and error and I am not exactly sure if I am doing it the best way.

Building an example into this template could probably spare people a lot of experimentation.

@erquhart
Copy link
Contributor

Agreed - can you add a description with a little more info?

@brasilikum
Copy link
Author

Done

@easherma
Copy link
Contributor

easherma commented Nov 7, 2018

@brasilikum can you link to your approach? I'm wrestling with the same issue.

@brasilikum
Copy link
Author

@easherma, sorry, it's not public, but here is the structure I ended up going with:
screen shot 2018-11-07 at 9 51 41 pm

I am using the following snippet to get a specific image:

    {{ $page := . }}
    {{ with $.Site.GetPage "page" "img/index.md" }}
        {{ $imgPath := split $page.Params.images "/"}}
        {{ $img := index $imgPath 2 }}
        {{ with .Resources.GetMatch $img }}
            {{$img400 := .Fill "800x400 Center"}}
            <img src="{{ $img400.RelPermalink }}">
        {{ end }}
    {{ end }}

Images are flat under the img directory (because of netlify).

The only non image file is the index.md with the following content:

---
title: Images
headless: true
---

Hope it helps

@easherma
Copy link
Contributor

easherma commented Nov 8, 2018 via email

@marcojakob
Copy link

marcojakob commented Apr 25, 2019

Thanks. Interesting approach.

Using Hugo's image processing will be much more straight forward once NetlifyCMS allows images to be stored relative to content. See decaporg/decap-cms#1472

Then we won't need the workaround with a separate img folder in content with a hack using a headless bundle.

@curzolapierre
Copy link

Hello, I can see that (decaporg/decap-cms#1472) issue has been fixed now.

What is the current status of the issue here?
What would be the best way to use the image processing now?

I tried to move the images to site/content/img but still, it seems that .Resources.GetMatch is not able to find them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants