Assets from child-page content have wrong (relative) paths when shown in sections

I built myself a section template that kind of works like a gallery. It iterates all pages from that section and shows their content. The child pages consist mainly of a picture (colocated with the page, no resize operation or anything) and a short comment.
These pictures are shown correctly on the page itself, but in the section they are broken because the relative path from the page is used (the subdirectory is missing). In the asset array however the correct/complete path to the image is available.

I donā€™t know when this broke for me, but it definitely used to work at some point. Did I miss a breaking change along the way or is this a bug? I could just use the asset variable instead of the page content, but I think if the user chooses to show the content on the parent section, the assets should be referenced correctly.

Iā€™d appreciate any help or pointers related to this issue :slight_smile:

Which version are you using? I believe it has used relative links for a while now

Iā€™m on 0.15.3.

This should be easily reproducible with a section template which contains:

{% for page in section.pages %}
  <h3><a href="{{ page.permalink }}">{{ page.title }}</a></h3>
  {{ page.content | safe }}
{% endfor %}

This is what one of my sub-pages looks like:

+++
title = "Diamonds"
date = 2020-01-20
[taxonomies]
tags = ["collage-poem", "art"]
+++

![diamonds](diamonds.jpg)

If youā€™d like to test with the complete website: ~irimi1/irimi.one - sourcehut git

Thanks, Iā€™ll add something like that as a test for the next release

Thanks, let me know if I can help or support you with something.
(Iā€™m not familiar with the codebase yet, otherwise I would have jumped right in and try to locate the issue.)

It might be in zola/page.rs at next Ā· getzola/zola Ā· GitHub but Iā€™m not sure at all

Hm, this part was last changed in May 2019, which is before I even started using zola for my website. I briefly tried building that version anyways to verify but ran into all sorts of build errors, probably because a lot of crates have been yanked since then (and maybe toolchain incompabilities?).

All this made me curious enough though that I wanna have a look myself, now that I have a rough idea where to start looking. Iā€™ll let you know if I find something.

1 Like
$ git bisect good
4086b0755a84e82645de3f43aab7460a1a5da6d6 is the first bad commit

This is the commit which breaks it for me.
From what Iā€™ve seen in the corresponding pull request and issue Iā€™m not sure whether thatā€™s intended or just a side effect. Maybe Tim can have a look at this? Iā€™m linking this thread in the pull request discussion to ping him.

I put together a version that fixes my problem and should still work with co-located subdirectories: Re-add modified check for colocated asset links Ā· irimi1/zola@36a2834 Ā· GitHub

I am not sure if I introduced some bad practices or ā€œcode smellā€ however and would like to get an opinion or suggestions for that. I also have broken at least one test, which I donā€™t understand yet how:

thread 'can_detect_links' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `1`', components/rendering/tests/links.rs:55:5

Iā€™d appreciate any help or ideas on what could be going wrong.

Edit: I see now how I broke the test. Iā€™d still appreciate your input though.
Edit: This loops all the way back here: Support colocating subfolders by timakro Ā· Pull Request #1582 Ā· getzola/zola Ā· GitHub (comment on markdown.rs)