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

Algolia search redirects with duplicated base url #1802

Closed
1 task done
zowe-robot opened this issue Aug 26, 2019 · 9 comments · Fixed by #2007
Closed
1 task done

Algolia search redirects with duplicated base url #1802

zowe-robot opened this issue Aug 26, 2019 · 9 comments · Fixed by #2007
Labels
topic: plugins Relates to VuePress plugins type: bug Something isn't working

Comments

@zowe-robot
Copy link

  • I confirm that this is an issue rather than a question.

Bug report

Steps to reproduce

  • Have Algolia search setup
  • The document website has site config base configured, for example, /docs.
  • Search any keyword and click on a search result
  • The page will try to navigate to a Url with duplicated base url, In the above, example, will be '/docs/docs/path/to/result.html`.

What is expected?

  • The page should navigate to a correct url.
  • Or allow user to configure handleSelected as algolia config to overwrite default build-in behavior.

What is actually happening?

On lines around https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/theme-default/components/AlgoliaSearchBox.vue#L41

            handleSelected: (input, event, suggestion) => {
              const { pathname, hash } = new URL(suggestion.url)
              this.$router.push(`${pathname}${hash}`)
            }

If the suggestion url is https://my-domain.com/docs/path/to/result.html`, pathname will be /docs/path/to/result.html. When we use $router.push, the $router will also prepend /docs base url to the path which results in double base url.

Also the handleSelected handling overwrites any configurations on site level algolia config of handleSelected.

Other relevant information

  • Output of npx vuepress info in my VuePress project:
Environment Info:

  System:
    OS: macOS 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
  Binaries:
    Node: 8.11.2 - ~/.nvm/versions/node/v8.11.2/bin/node
    Yarn: 1.10.1 - ~/.nvm/versions/node/v8.11.2/bin/yarn
    npm: 6.4.0 - ~/.nvm/versions/node/v8.11.2/bin/npm
  Browsers:
    Chrome: 76.0.3809.100
    Firefox: 60.8.0
    Safari: 12.1.2
  npmPackages:
    @vuepress/core:  1.0.3 
    @vuepress/theme-default:  1.0.3 
    vuepress: ^1.0.3 => 1.0.3 
  npmGlobalPackages:
    vuepress: Not Found
@luohuidong
Copy link

I also encountered the same problem.

@flozero flozero added topic: plugins Relates to VuePress plugins type: bug Something isn't working labels Sep 6, 2019
@koskimas
Copy link

I also have this problem. Has anyone found a way to fix this?

koskimas added a commit to Vincit/objection.js that referenced this issue Sep 21, 2019
koskimas added a commit to Vincit/objection.js that referenced this issue Sep 22, 2019
@ulivz
Copy link
Member

ulivz commented Sep 22, 2019

Algolia Search doesn't know that you're redeploying your site under a sub directory, which causes this issue. the unique solution is the search plugin providing a new option to let you intuitively pass it in. Contribution welcome!

@koskimas
Copy link

koskimas commented Sep 22, 2019

@ulivz Thank you for a quick answer! Now that you're "here" I'd just like to say how amazing vuepress is! It's by far the best tool for what it does. Thank you so much for your hard work 🙇‍♂️

Your answer might be exactly right, but what confuses me is that it used to work like that. I use vuepress with algolia search here and it has worked for months just fine. It just recently stopped working for whatever reason. Probably because I updated vuepress. I didn't change the configs, or the sub directory. I can dig around to find out what the last working version was if you want?

(now it works because I implemented the fix other people in this thread have implemented)

@koskimas
Copy link

koskimas commented Sep 22, 2019

Also even without the fix, the algolia links point to the correct URL (if I look at the anchor tags using dev tools). It goes wrong in the custom handler that calls the router. And that's the thing the workaround "fixes". You can see the "fix" here
Vincit/objection.js@5ba3fc7#diff-6c801fd144e12dcf6f3f4bdd0ec4c280R38

@koskimas
Copy link

If the implemented fix makes sense, I'm happy to create a PR for it. If there's a better way to fix it, I'm happy to implement that also, but I'll need some pointers, since I'm new to vuepress's code,

ProTip added a commit to rundeck/docs that referenced this issue Oct 9, 2019
@anibalsanchez
Copy link

I have the same issue.

I asked Algolia's DocSearch team, and they answered that the pages are correctly indexed with the right URLs.

@s-pace
Copy link
Contributor

s-pace commented Oct 15, 2019

First of all, thank you for Vuepress. This is a great project. Really helpful!

I am part of the DocSearch team which feature Algolia for vuepress.

Just to add on top of that, prepending /docs base url to the path is required for edge cases where the crawl is not made against the final website. A common use case would be to edit the result's URL to make sure your staging website redirect to your production one while the crawl is not against the production website (this require an update of your DocSearch configuration available from algolia/docsearch-configs). This is not the main use case and a temporary situation.

The default behaviour of vuepress should not mute the URL since the DocSearch crawler is making sure this URL is available by crawling it (200). Editing the URL should not be the default behaviour.

Happy to provide more details if needed. Thanks for handling that.

@nie7321
Copy link
Contributor

nie7321 commented Oct 17, 2019

I think @koskimas's fix is correct.

It's not changing the URL so much as working around the in-this-instance-undesirable Vue router behaviour. The URL people end up on remains the same as what DocSearch suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: plugins Relates to VuePress plugins type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants