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

get_image_metadata: Cannot find path #1161

Closed
shumvgolove opened this issue Sep 5, 2020 · 9 comments
Closed

get_image_metadata: Cannot find path #1161

shumvgolove opened this issue Sep 5, 2020 · 9 comments

Comments

@shumvgolove
Copy link

shumvgolove commented Sep 5, 2020

Bug Report

Environment

Zola version: 0.12.0

Expected Behavior

I have a shortcode which uses get_image_metadata builtin function on image that is on the same path as the post:

{% set meta = get_image_metadata(path=page.path ~ src) %}

0.11.0 was working fine, but...

Current Behavior

...Zola 0.12.0 contains breaking change: All paths like current_path, page.path, section.path (except colocated assets) now have a leading /. With this change, I can not build my site, which results in:

Failed to build the site
Error: Failed to render content of /home/yo/sample.site/content/test-post/index.md
Reason: Failed to render image shortcode
Reason: Failed to render 'shortcodes/image.html'
Reason: Function call 'get_image_metadata' failed
Reason: `get_image_metadata`: Cannot find path: /test-post/1.png

Steps to reproduce

  1. Make shortcode which utilizes get_image_metadata on image in page.path location:
{% if src %}
{% set meta = get_image_metadata(path=page.path ~ src) %}
<img src="{{ config.base_url | safe }}{{ page.path | safe }}{{ src | safe }}" width="{{ meta.width }}" height="{{ meta.height }}"/>
{% endif %}
  1. Write some post with the shortcode.
  2. Try to build the site.

I can't think of any workaround to resolve the issue, which will strip off forward slash in the beginning.

@muhuk
Copy link

muhuk commented Sep 8, 2020

I am experiencing exactly the same bug.

Prefixing the path with @ seems to work. But it doesn't make sense TBH. (It doesn't work)


Workaround:

{% set path = page.path|trim_start_matches(pat="/") %}

@shumvgolove
Copy link
Author

@muhuk Oh, thanks for providing the workaround!

@Keats
Copy link
Collaborator

Keats commented Sep 8, 2020

Something to consider while doing #977 as well

@Keats
Copy link
Collaborator

Keats commented May 12, 2021

I just realised, are you using colocated assets? If so you have a page.assets list of paths you can use

@muhuk
Copy link

muhuk commented May 30, 2021

I just realised, are you using colocated assets? If so you have a page.assets list of paths you can use

Hey @Keats, page.assets is neat but I need a single, specific asset. My template looks like this:

  {% if page.extra.social.thumbnail %}
    {% set path = page.path|trim_start_matches(pat="/") %}
    {% set image_meta = get_image_metadata(path=path  ~ page.extra.social.thumbnail) %}
    <meta property="og:image" content="{{ get_url(path=page.path) ~ "/" ~ page.extra.social.thumbnail | safe }}">
    <meta property="og:image:width" content="{{ image_meta.width }}">
    <meta property="og:image:height" content="{{ image_meta.height }}">
  {% endif %}

And I use this in my page's header:

[extra.social]
thumbnail = "thumbnail.jpeg"

Just wanted to provide context.

@Keats
Copy link
Collaborator

Keats commented May 31, 2021

With the next version, I think something like

  {% if page.extra.social.thumbnail %}
    {% set image_meta = get_image_metadata(path=page.path  ~ page.extra.social.thumbnail) %}
    <meta property="og:image" content="{{ image_meta.url | safe }}">
    <meta property="og:image:width" content="{{ image_meta.width }}">
    <meta property="og:image:height" content="{{ image_meta.height }}">
  {% endif %}

will work

@Keats
Copy link
Collaborator

Keats commented Jul 19, 2021

Should be fixed in 0.14.

@Keats Keats closed this as completed Jul 19, 2021
@muhuk
Copy link

muhuk commented Oct 4, 2021

I bit late, but I can confirm this is fixed.

@sleibrock
Copy link

Sharing my work-around a few years too late. Page.path doesn't work for me because my source content/ folder uses a different layout than my output layout. I instead used Page.colocated_path as the base and that worked fine. Just do:

{% set image_meta = get_image_metadata(path=page.colocated_path ~ page.extra.social.thumbnail) %}

Didn't see this documented anywhere so leaving it behind for future visitors.

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

No branches or pull requests

4 participants