freeCodeCamp / devdocs

API Documentation Browser
https://devdocs.io
Mozilla Public License 2.0
34.85k stars 2.32k forks source link

Intercept links to known documentation #234

Open gpgekko opened 9 years ago

gpgekko commented 9 years ago

I wonder if it would be possible to intercept (either during scraping or when clicked) links to known documentation. For example, the Backbone documentation contains quite a few links to Underscore documentation pages. It would be nice if these would open within DevDocs, since both are available.

This would be an improvement for offline use, and would be a nice enhancement for online use too.

Thibaut commented 9 years ago

Thanks for the suggestion. This is quite a difficult thing to implement but I agree it would be a nice enhancement. I have no time to work on it at the moment (given my long list of todos and other high-impact features), but maybe in the future.

Hipska commented 9 years ago

I think this could also solve #36, #41, #71, #89 and #187.

orionlee commented 7 years ago

514 is also a specific case for this request.

JesseTG commented 7 years ago

What would make this difficult, exactly?

Thibaut commented 7 years ago

See my comments in https://github.com/Thibaut/devdocs/issues/524

JesseTG commented 7 years ago

What if, while parsing server-side, we maintained a map of old links to transformed links, and then exposed this map to other docs?

Thibaut commented 7 years ago

@JesseTG that would be quite complex and difficult to maintain. I agree fixing/improving this would be great, but if it comes at the cost of increased maintenance burden (I'm already maxed out) and dependencies between docs/scrapers, then I don't think it's a good trade-off.

j-f1 commented 6 years ago

Here’s what I’m thinking:

  1. When parsing docs from URLs, include the original URL somewhere in the Entry object.
  2. Add a key to the generated JSON file with a mapping of originalURL => slug.
  3. When loading a documentation page on the client side, go through all of the external links and check if their domain and path are contained in the merged mapping of URLs for all enabled documentations. If they are, change them to an internal link.

Schema idea:

"url_mapping": {
  "developer.mozilla.org": {
    // ...
    // note that the URL’s path and domain are lowercased for case-insensitive matching.
    "/en-us/docs/web/javascript/reference/global_objects/string/endswith": "javascript/global_objects/string/endswith",
    // ...
  }
}

Why check the path and domain separately? by narrowing down the results to a particular domain by searching through a small set of domain names, the number of paths to check can be significantly decreased.

Kaijiro commented 6 years ago

I think you can apply this with enabled docs, not only installed.

j-f1 commented 6 years ago

@Kaijiro

I think you can apply this with enabled docs, not only installed.

Good point! Fixed.