-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Relative URLs to root of project #85
Comments
Lume has a <img href="{{ 'assets/x.png' | url }}"> |
|
For example: Does it work for you? |
Not really, I'd still have to do one build for each location. Maybe a But mostly, how do you feel about a |
Ok, got it. There is a I think we can do something similar for your use case, a processor to search all elements using an absolute path in the href/src attributes and convert them to relative. In fact, I have done something like that in another ssg I've created some years ago |
Ahnnn. That could totally work. Good point. I made a quick implementation of preprocess. But I'd defer to you if you think it's a good idea for this to exist at all. |
Also, for future reference, here are the 3 implementations of with a tag, abusing Nunchukjs. Use with site.data("rootPath", function() {
return this.ctx.url.split('/').filter(x => x).map(_ => '..').join('/') || '.';
}); with a processor doing string substitution. Use with site.process([".njk", ".md", ".html"], (page) => {
const root = page.data.url.split('/').filter(x => x).map(_ => '..').join('/') || '.';
page.content = page.content.replaceAll("@ROOT@", root);
}); With a preprocessor (not supported). Use with site.preprocess([".njk", ".md", ".html"], (page) => {
page.data.rootPath = page.data.url.split('/').filter(x => x).map(_ => '..').join('/') || '.';
}); |
I've created a plugin to convert all urls to relative: https://github.com/lumeland/lume/blob/master/plugins/relative_urls.js You only have to import to your import relative from "https://raw.githubusercontent.com/lumeland/lume/master/plugins/relative_urls.js";
site.use(relative()) I have tested it and seems to work fine. Could you check it? |
It works perfectly. Thanks! :) |
I have a site (same data) that will be served from multiple locations. Therefore, it's not great to use absolute URLs there.
The problem is: I'm trying to generate a page data that points to the root, so I can, for example have a link pointing to:
{{ root }}/assets/x.png
that correctly resolves for all internal pages, no matter how deep their URLs is.I was able to do something like this with:
that mostly solves my problem but:
I didn't see any documentation on
this.ctx
and I'm worried this will break in the future. Should we makesite.data()
callbacks receives a context?I know there's
site.process
plugins, but it would be great if there was a plugin mechanism to transform the data before rendering, so something like this could also be implemented.The text was updated successfully, but these errors were encountered: