symfony-tools/docs-builder

How can I change the URL of images?

javiereguiluz opened this issue · 2 comments

I'm working on integrating the docs builder in a new symfony.com section. So far it works great (I'm using a new RstParser class instead of generating it via the command or the PHAR).

The only issue I have is with images. I need to change their URL pattern and I don't know how to do it:

// Wrongly generated URL
/bundles/<the-bundle-name>/<the-bundle-branch>/_images/<the-image-name>.png

// The URL we need
/doc/bundles/<the-bundle-name>/<the-bundle-branch>/_images/<the-image-name>.png

I have this:

$builder = new Builder(KernelFactory::createKernel($buildContext));
$builder->build($buildContext->getSourceDir(), $buildContext->getOutputDir());

If I add this before the ->build() call, it changes all links, not only images, so it breaks everything:

$builder->getConfiguration()->setBaseUrl('doc');

And if I use this, nothing happens, so I don't know how this callable works:

$builder->getConfiguration()->setBaseUrlEnabledCallable(fn($path) => dd($path));

Could you please help me? Thanks!

I don't think different base URLs for images vs normal links is supported by the Rst Parser atm. All urls are generated by the same $environment->relativeUrl() method: https://github.com/doctrine/rst-parser/blob/26190b50a57eda961f5a9678350aa8c82dbdfd0a/lib/HTML/Directives/Figure.php#L42


Btw, setBaseUrlEnabledCallable() is a callable that returns a boolean whether the url should be prefixed with the base url. It cannot change the URL itself.

I've looked into this again because it's the bigger blocker right now. The good news is that I've just found the CopyImagesListener that Ryan created in this project ... and I've been able to change it a bit and the images now work. So, I'm going to close this as fixed for now and I'll submit my changes later. Thanks!