Skip to content
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

Add option to warn about absolute internal URLs ? #436

Closed
lurch opened this issue Jun 22, 2017 · 5 comments
Closed

Add option to warn about absolute internal URLs ? #436

lurch opened this issue Jun 22, 2017 · 5 comments

Comments

@lurch
Copy link

lurch commented Jun 22, 2017

I dunno if this is a feature that html-proofer already has (?) but if not, I think this would be a nice option to add.

In raspberrypi/documentation#669 a user found a link in https://www.raspberrypi.org/documentation/configuration/config-txt/video.md which didn't work, but this wasn't picked up by html-proofer.

In the source markdown (scroll down to the dpi_group, dpi_mode, dpi_output_format section), the link looks like [here](/hardware/raspberrypi/dpi/README.md) - note that it starts with a leading slash. This link works fine when viewing the page on Github (which links it to https://github.com/raspberrypi/documentation/blob/master/hardware/raspberrypi/dpi/README.md) and would also work fine if the HTML generated from this was being deployed to the root of a domain; but in our particular case the HTML generated from this is deployed to a subdirectory https://www.raspberrypi.org/documentation/ which means the absolute-link ends up linking to https://www.raspberrypi.org/hardware/raspberrypi/dpi/README.md which 404s. (the correct link would be https://www.raspberrypi.org/documentation/hardware/raspberrypi/dpi/README.md)

To catch situations like this (where the generated URL isn't being deployed to the root of a domain) it would be nice if html-proofer had an option (which should probably be disabled by default?) to warn if an internal URL starts with a leading slash.

@lurch
Copy link
Author

lurch commented Jun 22, 2017

raspberrypi/documentation#670 fixes the broken link. But it would still be nice if html-proofer could have caught it :-)

@fulldecent
Copy link
Collaborator

Thanks for sharing. In general, relative URLs that start with a slash are neither discouraged nor documented as deviation from best practice.

It is possible for html-proofer to make such a check. But adding such an option would not be consistent with our project scope.

We encourage you to implement this, if you are interested. Please see our documentation at https://github.com/gjtorikian/html-proofer/wiki/How-to-make-a-custom-class and we will be happy to list it on our list of extensions at https://github.com/gjtorikian/html-proofer/wiki/Extensions-(custom-classes). It's really simple. You can copy the code from https://github.com/fulldecent/html-proofer-mailto_awesome as a starting point and the main code you want is probably one line of code in this file: https://github.com/fulldecent/html-proofer-mailto_awesome/blob/master/lib/mail_to_awesome.rb

For now I will close this issue as out of scope for this project.

@gjtorikian
Copy link
Owner

As well, for something like this, you may be able to use the url_swap option, which, if I'm understanding correctly, might look like this:

url_swap: { "^/hardware/": "/documentation/hardware/" }

That is: any link starting with /hardware should be prepended with /documentation first.

@lurch
Copy link
Author

lurch commented Jun 23, 2017

In general, relative URLs that start with a slash are neither discouraged nor documented as deviation from best practice.

Yeah, that's why I suggested it should be an option that's disabled by default, unless explicitly enabled ;-)

But adding such an option would not be consistent with our project scope.

Oh, I would have thought it comes under the "if your internal links are working" section? :-/
For situations where the pages aren't being hosted in the root of a domain, I'd consider checking for not-absolute-internal-links as more important than checking-internal-hash-references *shrug*

We encourage you to implement this, if you are interested.

I'm afraid I've never written any Ruby, so I wouldn't even know where to start :-(
Rather than closing this, perhaps it could be left open as a "feature request" in case somebody who does know Ruby feels like implementing it?

That is: any link starting with /hardware should be prepended with /documentation first.

Nah, that wouldn't work in this scenario. For the repo in question we need all links to be relative, because the documentation can be browsed from both https://github.com/raspberrypi/documentation and from https://www.raspberrypi.org/documentation/

@fulldecent
Copy link
Collaborator

Does this solve the problem?

url_swap: { "^/": "http://NONEXISTANTDOMAIN.COM/" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants