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

catch broken links #1727

Closed
johann-sonntagbauer opened this issue Aug 5, 2017 · 13 comments
Closed

catch broken links #1727

johann-sonntagbauer opened this issue Aug 5, 2017 · 13 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more.

Comments

@johann-sonntagbauer
Copy link
Contributor

It would be great to have some feedback if internal links are reachable or not.

At least for Markdown files it would be doable to analyse the links and check if there are pages registered in the system. If not, a meaningfull error message with some context would be great.

example.md

# Example
[some broken link](/destinations)

error message

Broken Link detected in  example.md
 1:  # Example
 2:  [some broken link](/destinations)
------------------------------^ 

I started a simple proof of concept for that, but need some support on how to access the internal data structures in the right way. So please if the idea is valid I could finalize a PR for that feature.

@KyleAMathews
Copy link
Contributor

👍

window. ___loader.getPage() should do it.

getPage: pathname => findPage(pathname),

@johann-sonntagbauer
Copy link
Contributor Author

After getting the basics going, I face a conceptual problem. There is no way to report errors in a standardized way.

The build is split in a bootstrap phase and a webpack based build phase. The webpack build uses the friendly-webpack-error-plugin to format error messages, clear the console and print webpack status information.

So for the usecase of catching and reporting broken links, there would be two strategies of reporting the problems.
Introduce error boundaries in the bootstrapping phase and in friendly-webpack-plugin. Drawback here is to implement the message formatting and so forth in both places.
or
Simply print out the information during transformation of the markdown files. This has the drawback, that the messages could not get accumulated and will be cleared in the development console.

My personal preferred way would be to introduce the error boundaries. So please let me know what you think.

@KyleAMathews
Copy link
Contributor

I'm not entirely sure what you mean by "error boundaries" but it sounds intriguing :-)

@jquense is actually disabling friendly-webpack-plugin in #1746 as like you said, it clears all the errors from the bootstrap which hasn't been ideal.

Would love to hear more of your thoughts on how this could work! I'd definitely agree that the current error/warning story isn't great.

@jquense
Copy link
Contributor

jquense commented Aug 10, 2017

I'm hoping eventually we can use our own webpack error reporting system. or at least customize the FWE plugin a bit more. I bet they would open contributions so I might take that route. I'd love to get all the webpack stuff running through the same reporter as the rest of Gatsby

@johann-sonntagbauer
Copy link
Contributor Author

johann-sonntagbauer commented Aug 10, 2017

@jquense nice work! I will try to rebase my work onto your PR.
So the plan is to have the reporter to report any output. The reporter can decide how to deal with all the information, like print errors, update status information, progress indicators and so forth.
The FWE plugin is flexible in that case. We could provide our own Error Formatters which use the reporter infrastructure. With that we have all errors piped through the reporter.

@KyleAMathews
Copy link
Contributor

@johann-sonntagbauer or anyone else, this would be great to add still!

@johann-sonntagbauer
Copy link
Contributor Author

@KyleAMathews sorry forgot about that one. Will try to find some time to consolidate with the work @jquense did. It should make the error reporting much smoother.
THX for the reminder

@jlengstorf
Copy link
Contributor

Following up on this — is there a WIP anywhere that we can pick up, @johann-sonntagbauer? (No pressure, I just really want this feature. 😂)

Also, it looks like this is only catching links at the same origin. Is there any issue open to check all links? I didn't find one in my search. I imagine that won't be very performant, so maybe it would make more sense as a plugin so it's an opt-in thing. (Let me know if that seems like the right idea and I'll open a separate issue for the plugin dev.)

@johann-sonntagbauer
Copy link
Contributor Author

@jlengstorf this work is currently only checking same origin links. Hope to bring it to a somehow useable state.

@gatsbot
Copy link

gatsbot bot commented Dec 26, 2018

Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open!

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Dec 26, 2018
@gatsbot
Copy link

gatsbot bot commented Jan 6, 2019

This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.

@gatsbot gatsbot bot closed this as completed Jan 6, 2019
@ivanoats
Copy link
Contributor

Maybe a plugin that uses the programatic interface of https://www.npmjs.com/package/broken-link-checker ? Any interest?

@jlengstorf
Copy link
Contributor

@ivanoats I'd love to see that — let me know if you get one rolling and I'll happily help you test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more.
Projects
None yet
Development

No branches or pull requests

6 participants