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

feat(search-algolia): algolia externalUrl regex to navigate with window.href #5795

Merged
merged 1 commit into from Oct 29, 2021

Conversation

semoal
Copy link
Contributor

@semoal semoal commented Oct 27, 2021

Motivation

Will close #5631, now will be possible to use Algolia native SearchBar with multiple domains on the same Algolia config.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  • Just add to docusaurus.config.js:
 algolia: {
        appId: 'X1Z85QJPUV',
        apiKey: 'bf7211c161e8205da2f933a02534105a',
        indexName: 'docusaurus-2',
        contextualSearch: true,
        externalUrlRegex: 'docusaurus.io'
      },

And immediately after, link hrefs will be converted to absolute and will navigate with window.location instead of history.push

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 27, 2021
@netlify
Copy link

netlify bot commented Oct 27, 2021

✔️ [V2]
Built without sensitive environment variables

🔨 Explore the source changes: ac03ee2

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/617c2ad000377700086e9e9a

😎 Browse the preview: https://deploy-preview-5795--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Oct 27, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 91
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-5795--docusaurus-2.netlify.app/

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just not a fan of withRegex

@semoal semoal force-pushed the semoal/feat-external-url-algolia branch from 63a78a8 to c033ec9 Compare October 27, 2021 17:32
@Josh-Cena Josh-Cena changed the title feat(): algolia externalUrl regex to navigate with window feat(search-algolia): algolia externalUrl regex to navigate with window.href Oct 28, 2021
@Josh-Cena Josh-Cena added the pr: new feature This PR adds a new API or behavior. label Oct 28, 2021
* @param {string} regexAsString
* @returns { {test: () => boolean }}
*/
export function isRegexpStringMatch(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving this to jsUtils. We shouldn't keep on adding more files, especially for these general-purpose utilities

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho, it's easier to keep it separated on files for an easier search on the editor. (At least for me)
But as @slorber considers :)

Copy link
Collaborator

@Josh-Cena Josh-Cena Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That really depends on the editor:D Most decent editors allow you to search globally, but navigating in one file is always easier than in a giant directory. If there are more regex tools to come that we can envision, keeping it seperated can be a good idea, but... I'm not sure if there are many painpoints with regex that need utility functions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care too much about the filename as long as the import name is understandable: it's an implementation detail that we can easily refactor later.

Not a fan of a fn with signature RegExp | {test: () => boolean}, what about returning the boolean and calling test() inside directly?

And "" should not be handled like undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that makes snse to me too, refactored to be much cleaner.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have used a simpler isRegexpStringMatch(regex,str) rather than a higher order function, but it's not too important

* @param {string} regexAsString
* @returns { {test: () => boolean }}
*/
export function isRegexpStringMatch(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care too much about the filename as long as the import name is understandable: it's an implementation detail that we can easily refactor later.

Not a fan of a fn with signature RegExp | {test: () => boolean}, what about returning the boolean and calling test() inside directly?

And "" should not be handled like undefined

@semoal semoal force-pushed the semoal/feat-external-url-algolia branch from c033ec9 to 59ccd9f Compare October 29, 2021 14:38
@semoal semoal force-pushed the semoal/feat-external-url-algolia branch from 59ccd9f to d528cc3 Compare October 29, 2021 15:08
website/docs/search.md Outdated Show resolved Hide resolved
@semoal semoal force-pushed the semoal/feat-external-url-algolia branch from d528cc3 to d844682 Compare October 29, 2021 16:33
regexAsString?: string,
): (valueToTest?: string | undefined) => boolean {
return (valueToTest?: string) => {
if (!valueToTest || !regexAsString) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasn't this been reverted? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, force-pushed with --ammend from another computer and forgot to pull.. doing 30 things at the same time isn't good. Should be fixed now

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D LGTM

@semoal semoal force-pushed the semoal/feat-external-url-algolia branch from d844682 to ac03ee2 Compare October 29, 2021 17:09
@slorber slorber merged commit adbc02e into facebook:main Oct 29, 2021
@Josh-Cena Josh-Cena mentioned this pull request Jan 2, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Algolia DocSearch component transforms to relative instead of absolute
4 participants