-
Notifications
You must be signed in to change notification settings - Fork 52
rewrite "external" urls pointing to the current domain into internal urls #719
Conversation
✅ Deploy Preview for apollo-monodocs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
src/utils/index.js
Outdated
@@ -7,7 +7,13 @@ import {withPrefix} from 'gatsby'; | |||
export const NavContext = createContext(); | |||
export const PathContext = createContext(); | |||
|
|||
export const isUrl = string => /^https?:\/\//.test(string); | |||
const urlRegex = /^https?:\/\//; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved those out into constants to the regex is not recreated for every call and can be optimized by the engine.
I've double-checked this and it will need another fix - see https://deploy-preview-719--apollo-monodocs.netlify.app/react/api/core/ApolloClient#ApolloClientOptions This link currently ends up as |
05ee41b
to
f59f877
Compare
Okay, fixed up and requesting a re-review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
As we are reusing comments between source code and docs, our linked urls are absolute (otherwise they couldn't be used from the IDE), not relative.
The currentisExternal
check recognizes these links to the docs as "external" and opens them in a new tab - this PR aims to fix that.See apollographql/apollo-client#11381 (comment)
This now rewrites urls into domain-absolute urls that will correctly be picked up by the
GatsbyLink
component for internal documentation.See the deploy preview at https://65b114d41ee09600089b6792--apollo-monodocs.netlify.app/react/api/core/ApolloClient/#ApolloClientOptions