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

question: How do i force html proofer to check for broken image links locally within a github PR on travis - external link failed #527

Closed
lwasser opened this issue Jul 25, 2019 · 3 comments

Comments

@lwasser
Copy link

lwasser commented Jul 25, 2019

Hey all,
I hope this is the right place to ask this question. ive got a very basic build in travisCI on our github pages / jekyll website - CI BUILD HERE.

Essentially the way the build is setup, by default it looks for images in a new page added to the site at our url: https://www.earthdatascience.org/images/image-name-here.png. However i'd prefer that it tests the build locally on travis because in some instances, a PR contains new images from a branch or fork that are not yet on master where the site gets built.

Locally, this would look like: http://localhost:4000 however i tried that on travis and it didn't work perhaps because jekyll serve isn't running actively?

i've tried the following

  1. setting the config file to https://earthdatascience.org (this fails as expected given the images are in the PR not on master yet)
  2. setting the config file url to localhost:4000 (also fails)
  3. leaving the url in the config file blank

None of these approaches work for me. returning errors like this:External link http://images/courses/earth-analytics-bootcamp/00-course-overview/2018-07-16-co-09-final-project_13_0.png failed: response code 0 means something's wrong.

how do i test image links on html pages within a PR on a local site build rather than the live site?
Many thanks in advance for any guidance and please tell me if this is not the correct place to post this question.

@lwasser lwasser changed the title question: How do i force html proofer to check for broken image links locally on travis question: How do i force html proofer to check for broken image links locally within a github PR on travis Jul 25, 2019
@lwasser lwasser changed the title question: How do i force html proofer to check for broken image links locally within a github PR on travis question: How do i force html proofer to check for broken image links locally within a github PR on travis - external link failed Jul 25, 2019
@KirstieJane
Copy link

Commenting here because I think my question is really similar.

I've got html-proofer running nicely on my website which is powered by jekyll and GitHub pages: https://github.com/WhitakerLab/whitakerlab.github.io. Here's a link to the .travis.yml file.

When I open a pull request to add a new blog post html-proofer says that the blog post doesn't exist. Which is exactly right. I'm trying to check it first before merging to master 😆. It feels like a super circular problem.

Here's a link to the failure on travis: https://travis-ci.org/WhitakerLab/whitakerlab.github.io/builds/563645832#L401.

Ditto @lwasser, thank you so much for the great tool, and please let me know if there is a better place to ask these types of questions 😸

@gjtorikian
Copy link
Owner

how do i test image links on html pages within a PR on a local site build rather than the live site?

Hi. I believe you can fix this in one of two ways:

  1. Don't include {{ site.url }} in your text. For example, in this PR, instead of linking to {{ site.url }}/images/blog/2019-07-23-art-of-science-blog/art-of-science-blog-infographic.jpg, you can just link to /images/blog/2019-07-23-art-of-science-blog/art-of-science-blog-infographic.jpg. The relative path (/ at the start) is used by browers and html-proofer to look for a file starting at the root, so you do not need to provide it a full URL.

  2. If you don't want to change these pages, you can use the url_swap option to remove that starting text. That might look something like this: url_swap "\{\{ site.url \}\}/images:/images" (The README has more information on this command, but essentially you are replacing {{ site.url }}/images with just /images.


It feels like a super circular problem.

This is, in fact, the same issue! On the page where your tags are being generated, the <a href points to {{ site.url }}. The two solutions above should also apply to you.


To make a more clear example, here are two links:

However, both links end up going to the same place.

This is a similar pattern which html-proofer follows. Since both builds are using {{ site.url }} links in the output, html-proofer is trying to go out to the Internet and fetch those pages. But if you drop the prefix and just use relative-style / links, html-proofer will use the root folder build output.

Hope this helps, please let me know.

@lwasser
Copy link
Author

lwasser commented Jul 30, 2019

hey @gjtorikian and @KirstieJane this fix worked well for me!!
please ignore the fact that my pr is failing... lessons are still full of bad links BUT it's assuming a local build now on PRs.

https://github.com/earthlab/earthlab.github.io/pull/732/files

i ended up using the full url of our site as it was building off of the config file which was populating {{ site.url }} with the full url. anyway thank you again. i'm happy to close this issue as the url_swap + regex solution worked wonders!! many thanks!!!

@lwasser lwasser closed this as completed Jul 30, 2019
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