-
Notifications
You must be signed in to change notification settings - Fork 991
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
Discussion: Reenable link rewriting for colocated assets #1779
Conversation
In getzola#1582 I broke the asset colocation example from the documentation: https://www.getzola.org/documentation/content/overview/#asset-colocation The breakage was discovered by irimi1: getzola#1582 (comment) When I wrote getzola#1582 I was not aware of the old behavior: links to assets used to be rewritten to absolute links, so that colocated assets could be linked to from `pagename/index.md` simply as `asset.xyz` instead of `pagename/asset.xyz`. I unintentionally changed this, so that currently you have to write `pagename/asset.xyz`. Read this commit as a partial revert of getzola#1582. It restores the old behavior as described above. Caveats: 1. This will break lots of sites, just like getzola#1582 unintentionally broke lots of sites (but no one seemed to notice). 2. The old behavior is restored, including the quirk, that when linking from a page `pagename.md` to a section asset `asset.xyz` you need to write `../asset.xyz`, even though both files are in the same folder on disk. You can make sense of it in the following way: the asset belongs to the section so that is one level up from the page.
Hello i definitely noticed and had to work around it . Sorry i didn't catch it earlier that's because i don't have time to update my sites all of the time, but i'll soon setup an automated CI to ensure that my sites continue to build against zola next branch. I personally believe rewriting those URLs is a good thing as it's consistent with the folder view. To be fair, path rules are a fairly complex topic and there's been long debates about how to make them more consistent. I personally haven't followed the conclusions of those debates (i'll get up to speed), but i've personally advocated for searching for simpler rules for path resolution which would support all the types of links we need: standard HTML links (relative/absolute with I'm not sure about the best syntax or the best choice of building blocks, but i'm sure there's currently a lot of corners we're cutting: for example how can i link to some resource from the site root from markdown? an absolute URL will only work with sites living on the webroot of the domain, so i had to wrap that into a shortcode calling |
That's the status in the end: https://github.com/getzola/zola/blob/master/components/templates/src/global_fns/helpers.rs#L7 but for now it only applies in Tera functions, not in the markdown rendering. |
Any idea on how to solve this neatly @southerntofu ? |
@@ -62,6 +70,11 @@ fn find_anchor(anchors: &[String], name: String, level: u16) -> String { | |||
find_anchor(anchors, name, level + 1) | |||
} | |||
|
|||
/// Colocated asset links refers to the files in the same directory. | |||
fn is_colocated_asset_link(link: &str) -> bool { | |||
!link.starts_with('/') && !link.starts_with('#') && !STARTS_WITH_SCHEMA_RE.is_match(link) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to consider ../
as well? Those assets also wouldn’t be colocated, but I don’t know if those links could occur while using zola in a reasonable way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency we want to change links starting with ../
as well. Imagine you want to link to section/asset.png
from section/page/index.md
, then you would write ../asset.png
. That would be rewritten to section/page/../asset.png
, which is correct. Without link rewriting the link would be broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, makes sense. What exactly is '/'
for then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/
is for absolute links. We should probably prepend base_url
, but not the page permalink.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks for explaining! :)
The old behaviour makes more sense for me since when creating a page using |
I just recently decided to try to fix the problem I had in #1705 and was about to make a PR when I stumbled upon this. In my use-case it also makes sense to rewrite the links as absolute, since I need them to be displayed in other parts of the webpage, e.g. as part of previews/summaries of posts. Unfortunately it was broken by #1582, like other use-cases of this functionality as it seems from this discussion. |
Ok I think this is the last big thing to solve for 0.16. Does this patch satisfy everyone? |
ping @Irimi1 @timakro @southerntofu @Yaroslav-95 to confirm, not 100% sure what the emoji reactions mean :) |
On 22/06/09 12:53PM, Vincent Prouillet wrote:
ping @Irimi1 @timakro @southerntofu @Yaroslav-95 to confirm, not 100%
sure what the emoji reactions mean :)
Tested it on my end, and it definitely satisfies me :) Will be very
glad to see this patch on 0.16 so I can finally remove zola from
my package manager's ignore list.
|
I’m also happy with that patch :) |
This is added to the |
Just a quick ping @Irimi1 @timakro @Yaroslav-95 to make sure it works for you. I'm getting confused again with that :) |
On 22/10/11 10:55AM, Vincent Prouillet wrote:
Just a quick ping @Irimi1 @timakro @Yaroslav-95 to make sure it works for you. I'm getting confused again with that :)
Works for me™ alright.
…--
Ярослав де ла Пенья Смирнов
Yaroslav de la Peña Smirnov
|
Working for me, too :) |
In #1582 I broke the asset colocation example from the documentation:
https://www.getzola.org/documentation/content/overview/#asset-colocation
The breakage was discovered by irimi1:
#1582 (comment)
When I wrote #1582 I was not aware of the old behavior: links to assets
used to be rewritten to absolute links, so that colocated assets could
be linked to from
pagename/index.md
simply asasset.xyz
instead ofpagename/asset.xyz
. I unintentionally changed this, so that currentlyyou have to write
pagename/asset.xyz
.Read this commit as a partial revert of #1582. It restores the old
behavior as described above.
Caveats:
lots of sites (but no one seemed to notice).
from a page
pagename.md
to a section assetasset.xyz
you need towrite
../asset.xyz
, even though both files are in the same folderon disk. You can make sense of it in the following way: the asset
belongs to the section so that is one level up from the page.
@Irimi1
Please discuss this before merging. Some might prefer the current behavior over the old behavior.