Forum How do I...?

File URL Support with --baseurl Option

forkjake
Does the --baseurl option support file URLs (e.g. file://mypath)? I've done some experimentation on this -- it appears to support file URLs but only if the URLs in the HTML are not absolute paths.

For example, if I have <img src="/mycontext/images/image.jpg"/>, it will ignore the --baseurl value and report: "prince: /images/image.jpg: warning: can't open input file: No such file or directory." If I give it an HTTP URL such as http://localhost:8080/mypath, then it will work.

However, if the path is a relative path, it does work properly. For example, assume I have <img src="images/picture.jpg"/> and my image resides at /home/joe/web/images/picture.jpg. If I supply a base URL of file:///home/joe/web, then the image is found.

Should the --baseurl option work with a file URL when the URLs in the HTML are absolute paths?
mikeday
Should the --baseurl option work with a file URL when the URLs in the HTML are absolute paths?

This is a tricky area, really. If the base URL is a file path like /home/joe/web and you want to resolve a URL like /foo relative to that base URL, what should the result be: /foo, /home/joe/foo, or /home/joe/web/foo? Currently we assume /foo, which is consistent with what you would get if you typed in "cd /foo" and also consistent with how we treat HTTP URLs.

However, I can see that this can be annoying when you want to create a local mirror of your website, with /foo links pointing to /path/to/base/foo. Unfortunately I don't think we can make Prince resolve URLs in this manner without breaking things. This would require some kind of new option to specify the root path, eg. --root=/home/joe/web so that /foo would be resolved relative to that root. This might be rather complicated for us to add to Prince though, so I would suggest it would be better to use relative links instead.
PieterN
I have a problem concerning the --baseurl flag, so I decided to post my message in this topic.

My Prince (6.0 rev 6) command line is:
/home/pieter/vienna/app/prince/bin/prince --input=html --verbose --server --baseurl="/home/pieter/vienna/app/public/" --log="/home/pieter/vienna/app/log/prince.log" --prefix="/home/pieter/vienna/app/prince" --silent - -o -


You see I define my baseurl as /home/pieter/vienna/app/public/. What I want is to reference images in the vienna subdirectory IN the public directory. Therefore, I define my images with a relative src, like this:

<img src="vienna/logo.png" />


However, this results in the following error messages:

msg|inf||loading image: /home/pieter/vienna/app/vienna/logo.png
msg|wrn|/home/pieter/vienna/app/vienna/logo.png|can't open input file: No such file or directory


It looks as Prince strips the last path off of my baseurl definition. I've solved this problem by adding "./" to my baseurl definition, but wanted to post a message about my findings anyway. The last thing I want is to break functionality when upgrading Prince (when hopefully this bug is fixed).
mikeday
The base URL is the URL of the file that you are processing. It may be an entirely notional URL of a file that doesn't actually exist, but it's still pointing to a file, not a directory. This is why Prince (and browsers) will chop the end off the base URL: as that is the file name part, not the directory.
mikeday
In Prince 7.1 we have added an experimental new command-line option called --fileroot, which allows you to specify a path that will be used to resolve absolute filenames.