nhoizey / eleventy-plugin-link_to

A Nunjucks tag to link to another internal content in Eleventy with its slug.
MIT License
4 stars 0 forks source link

Usage with global path prefix? #5

Open mbforbes opened 2 years ago

mbforbes commented 2 years ago

Hi there,

Thank you for writing this plugin!

I'm not sure whether there's a natural way for it to play nicely with eleventy's global path prefix.

The path prefix mechanism prepends something to all URLs in case your website doesn't start at /. E.g., building with eleventy --pathprefix 'website-3' would produce URLs that start with /website-3/.

When I build with a --pathprefix, then link_to still produces URLs without the prefix.

I thought to pipe them through eleventy's filter for adding path prefixes, url, like so:

{% link_to "/posts/paralysis/" | url %}

This produces the correct URL, but I get an error in the build log that link_to is looking for the new path, and couldn't find it:

[link_to] Couldn't find any content with slug '/website-3/posts/paralysis/'

I'm not sure whether there is a workaround, or whether the plugin would require changes to support the path prefix?

Many thanks for your time!

nhoizey commented 2 years ago

Hi @mbforbes, that's a good issue to solve indeed! 👍

I wonder if there's a way to get the pass prefix in the plugin code. Would you have an idea about that?

mbforbes commented 2 years ago

Thank you for the reply, @nhoizey! 🙏

That's a great question. Haven't touched plugin code so I hadn't even considered that it might be awkward to plumb through, but looking now I see the plugin doesn't refer to anything eleventy! From the docs it looks like this is a top-level config option, so we'd need access to the eleventy config object somehow?