wjdp / htmltest

:white_check_mark: Test generated HTML for problems
MIT License
323 stars 54 forks source link

Allow specifying the base URL for the generated files #184

Open dkarlovi opened 2 years ago

dkarlovi commented 2 years ago

Is your feature request related to a problem? Please describe.

Some tools provide a way to generate a site for a specific base URL, for example Hugo supports setting a baseURL. This allows generating for multiple targets, generating for a subdirectory, etc.

Example:

BASE_URL=https://example.com/some/path ./my-generator --out=./public

Generates files which might have (some) of the URLs be absolute, for example https://example.com/some/path/images/logo.svg

Describe the solution you'd like

At this point, all URLs which start with https://example.com/some/path should be treated as local URLs and tried to be resolved using the filesystem, for example:

https://example.com/some/path/images/logo.svg => ./public/images/logo.svg
/some/path/images/logo.svg => ./public/images/logo.svg
shishkin commented 2 years ago

And some will be generated as relative, e.g. /some/path/main.css. Those currently are not resolved relatively to the root directory.

francescocaponio commented 1 year ago

On this same topic, it would be nice to have the same feature swap-urls of html-proofer, where your can replace a relative path with a base path to a relative path starting from the root, for instance /subgroup/repo-name/ to /. This is needed when publishing to gitlab pages, where your path starts with /subgroup/repo-name/, but htmltest would raise error with such path.