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 load image files under /static #911

Closed
lo48576 opened this issue Jan 4, 2020 · 5 comments
Closed

get_image_metadata cannot load image files under /static #911

lo48576 opened this issue Jan 4, 2020 · 5 comments

Comments

@lo48576
Copy link

lo48576 commented Jan 4, 2020

Bug Report

Environment

Zola version: 0.9.0

Expected Behavior

get_image_metadata("foo.jpg") successfully loads metadata of static/foo.jpg if there are no content/foo.jpg.

Current Behavior

get_image_metadata("foo.jpg") complains "Reason: get_image_meta: Cannot find path: foo.jpg" even if there is static/foo.jpg.

Step to reproduce

  1. Put an image to static folder, e.g. static/foo.jpg.
    • There should be no files with the same path, e.g. content/foo.jpg.
  2. Run get_image_metadata(path="foo.jpg") in a template.
    • Both local templates or theme templates are ok.
  3. Run zola build or zola serve.
    • It fails with `get_image_meta`: Cannot find path: foo.jpg error.

Additional info

I think the lines below should be changed in some way.

self.tera.register_function(
"get_image_metadata",
global_fns::GetImageMeta::new(self.content_path.clone()),
);

let src_path = self.content_path.join(&path);
if !src_path.exists() {
return Err(format!("`get_image_meta`: Cannot find path: {}", path).into());
}

@Keats
Copy link
Collaborator

Keats commented Jan 26, 2020

Hmm that would be a breaking change :/ But it makes sense to be able to use it on assets from static I think

@jasikpark
Copy link

perhaps just require a get_url() or “/static/foo.jpg” to differentiate?

Sent with GitHawk

@getzola getzola deleted a comment from jasikpark Mar 16, 2020
@getzola getzola deleted a comment from jasikpark Mar 16, 2020
@chris-morgan
Copy link
Contributor

Two related things:

  1. {{ get_image_metadata(path="../static/foo.jpg") }} works, but {{ get_url(path="../static/foo.jpg") }} doesn’t strip the ../static/ bit.

  2. content/foo.jpg actually doesn’t work anyway; {{ get_image_metadata(path="foo.jpg") }} works, but the image file is not copied. (Presumably because of how the front page is magic rather than being a normal section with an _index.md file—I consider this magic a grave error, incidentally—and it doesn’t copy files that it can’t associate with a section or page, which I think should either be allowed or should warn.) So if you want an image file in the root of the site, it needs to be in /static/ at present.

@Keats
Copy link
Collaborator

Keats commented Mar 18, 2020

For 2, the front page is not magic. It creates an empty section if there is no _index.md so the site renders fine but you can define your own _index.md without any issues: https://github.com/Keats/tera/blob/master/docs/content/_index.md
The issue is that assets are only copied from content when present in a colocated folder. Random files in the tree are ignored in any other cases, nothing to do with the index page and there are no concepts of sections with colocated assets currently.

@Keats
Copy link
Collaborator

Keats commented Jul 19, 2021

Should be fixed in 0.14.

@Keats Keats closed this as completed Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants