Skip to content

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

Merged
slorber merged 1 commit into
facebook:mainfrom
semoal:semoal/feat-external-url-algolia
Oct 29, 2021
Merged

feat(search-algolia): algolia externalUrl regex to navigate with window.href#5795
slorber merged 1 commit into
facebook:mainfrom
semoal:semoal/feat-external-url-algolia

Conversation

@semoal

@semoal semoal commented Oct 27, 2021

Copy link
Copy Markdown
Contributor

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.)

@semoal
semoal requested review from lex111 and slorber as code owners October 27, 2021 11:03
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 27, 2021
@netlify

netlify Bot commented Oct 27, 2021

Copy link
Copy Markdown

✔️ [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

github-actions Bot commented Oct 27, 2021

Copy link
Copy Markdown

⚡️ 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/

@slorber slorber left a comment

Copy link
Copy Markdown
Collaborator

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

Comment thread packages/docusaurus-theme-search-algolia/src/theme/utils/index.js Outdated
Comment thread packages/docusaurus-theme-search-algolia/src/validateThemeConfig.js Outdated
@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
Copy Markdown
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
Copy Markdown
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 :)

@Josh-Cena Josh-Cena Oct 28, 2021

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread packages/docusaurus-theme-classic/src/theme/NavbarItem/DefaultNavbarItem.tsx Outdated
Comment thread packages/docusaurus-theme-common/src/utils/regexpUtils.ts Outdated
@semoal
semoal force-pushed the semoal/feat-external-url-algolia branch from 59ccd9f to d528cc3 Compare October 29, 2021 15:08
Comment thread website/docs/search.md Outdated
@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
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