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

Undocumented or Faulty: linking colocated assets on a slug page through template #2598

Open
Yamavu opened this issue Aug 5, 2024 · 3 comments

Comments

@Yamavu
Copy link

Yamavu commented Aug 5, 2024

Documentation issue

Summary

Listing all colocated assets of a page in a template page.html . The content index.md uses a slug

(tested on versions 0.18.0 and 0.19.1)

Files linked in markdown are unaffected.

file setup:

_index.md
page/
  image1.jpg
  image2.jpg
  index.jpg

From the documentation:

<div>
{% for asset in page.assets -%}
  {%- if asset is matching("[.](jpg|png)$") -%}
    {% set image = resize_image(path=asset, width=240, height=180) %}
    <a href="{{ get_url(path=asset) }}" target="_blank">
      <img src="{{ image.url }}" />
    </a>
  {%- endif %}
{%- endfor %}
</div>

If the page also uses a custom slug variable, {{ get_url(path=asset) }} doesn't provide this correctly,

Zola will only display the right output when the link is written like:

{{page.permalink | safe}}{{asset | split(pat='/') | last  | safe }}

Maybe I overlooked something, but linking all co-located assets seems to be quite essential for building almost any kind of art or photo gallery.

Proposed solution

Either current documentation should be expanded or get_url() should include this functionality.

@Yamavu Yamavu changed the title linking colocated assets on a slug page Undocumented or Faulty: linking colocated assets on a slug page through template Aug 6, 2024
@Raymi306
Copy link
Contributor

I just ran into this as well.

@Yamavu
Copy link
Author

Yamavu commented Aug 11, 2024

as far as I understood, get_url ( path, lang="en", trailing_slash=false, cachebust=false ) is also used internally which is why is simple and optimized.

the function currently supposed to only work with MD files, not the page assets (even though the documentation suggests that).

The function has a fallback option to also link to the static directory, and happens to work with un-sluggified content nodes too. It feels pretty alpha to me

@Keats
Copy link
Collaborator

Keats commented Aug 14, 2024

Basically it's for 2 things:

  1. if it starts with @/, resolve the internal link
  2. otherwise just make a permalink with what we've been given without checking anything

To handle 2 for assets with renamed slugs, it would require detecting it's a colocated asset, load the related page and generate the permalink from there (what you need to load exactly in the GetUrl fn is TBD, you don't want to add the whole site).
If someone wants to do a PR for that I would take it.

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

3 participants