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

Search result path not correct #214

Open
h3nkk44 opened this issue Jul 5, 2024 · 9 comments · May be fixed by #216
Open

Search result path not correct #214

h3nkk44 opened this issue Jul 5, 2024 · 9 comments · May be fixed by #216
Labels
bug Something isn't working

Comments

@h3nkk44
Copy link

h3nkk44 commented Jul 5, 2024

Please describe the bug you are seeing

Hi,

I installed this plugin to an empty docusaurus project and run all the command without any customization or modifications. When i build and serve the project the search works and shows results fine, but the path where the result is pointing is not working correct.

I dont know if this is a undocumentened config or bug.

Screenshot 2024-07-05 113950

As you can see from the image the path is duplicating after the docs part.

"https://symmetrical-space-doodle-x5rrrgx9pq4hv74v-3000.app.github.dev/docs/tutorial-extras/translate-your-site/docs/tutorial-extras/translate-your-site#start-your-localized-site"

When it should be:

"https://symmetrical-space-doodle-x5rrrgx9pq4hv74v-3000.app.github.dev/docs/tutorial-extras/translate-your-site#start-your-localized-site"

Thanks!

How can we best reproduce the bug?

  1. Install docusaurus
  2. Install plugin with default settings
  3. Test

Which version of Docusaurus and @cmfcmf/docusaurus-search-local are you using?

Latest that are available

Which Node.js version are you using?

22.3.0

Which theme are you using?

Yes, I am using @docusaurus/theme-classic

How does your plugin config look like?

Default config

Additional context

No response

@h3nkk44 h3nkk44 added the bug Something isn't working label Jul 5, 2024
@sibelius
Copy link

sibelius commented Jul 7, 2024

it is duplicating somehow

@Rob-Purbrick
Copy link

Seeing same behaviour in previously working docs

@olganaumenko
Copy link

Снимок экрана 2024-07-12 в 12 11 03

I see the same problem for my website :(

@clainchoupi
Copy link

I have the same problem since a few weeks.

I wonder how that could be related to an incompatibility between Node, Docusaurus and CMFCMFSearchLocal.
In my package-lock.json file I have the following :

{ "name": "myDoc", "version": "0.0.0", "dependencies": { "@cmfcmf/docusaurus-search-local": "^0.11.0", "@docusaurus/core": "^3.4.0", "@docusaurus/preset-classic": "^3.4.0", "@docusaurus/theme-mermaid": "^3.4.0", "@mdx-js/react": "^3.0.0", "clsx": "^1.2.1", "prism-react-renderer": "^1.3.5", "react": "^18.2.0", "react-dom": "^18.2.0", "reveal.js": "^5.0.0", "swagger-ui-react": "^4.18.1" }, "devDependencies": { "@docusaurus/module-type-aliases": "^3.4.0", "@tsconfig/docusaurus": "^2.0.2" }, "engines": { "node": ">=16.14" } }

CMF and React are locked, but not Node, so there might be something happening here ?

@fxamauri fxamauri linked a pull request Jul 18, 2024 that will close this issue
@fxamauri
Copy link

fxamauri commented Jul 18, 2024

This #216 should resolve, can you test applying patch?

diff --git a/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js b/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js
index bf41fa2..50bf040 100644
--- a/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js
+++ b/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js
@@ -109,7 +109,9 @@ function html2text(html, type, url = "?") {
                 // <a class="hash-link" href="#first-header" title="Direct link to heading">#</a>
                 .not("a[aria-hidden=true], a.hash-link")
                 .text();
-            const hash = $(heading).find("a.hash-link").attr("href") || "";
+            const linkHash = $(heading).find("a.hash-link").attr("href") || ""
+            const [, hashPart] = linkHash.split("#")
+            const hash = hashPart ? `#${hashPart}` : "";
             let $sectionElements;
             if ($(heading).parents(".markdown").length === 0) {
                 // $(heading) is the page title

how apply patch?

1 - copy patch above
2 - In the root of your docsaurus project run command: pbpaste | git apply

or use patch-package

@leandrucarvalho
Copy link

Este problema #216 deve ser resolvido. Você pode testar a aplicação do patch?

diff --git a/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js b/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js
index bf41fa2..50bf040 100644
--- a/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js
+++ b/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js
@@ -109,7 +109,9 @@ function html2text(html, type, url = "?") {
                 // <a class="hash-link" href="#first-header" title="Direct link to heading">#</a>
                 .not("a[aria-hidden=true], a.hash-link")
                 .text();
-            const hash = $(heading).find("a.hash-link").attr("href") || "";
+            const linkHash = $(heading).find("a.hash-link").attr("href") || ""
+            const [, hashPart] = linkHash.split("#")
+            const hash = hashPart ? `#${hashPart}` : "";
             let $sectionElements;
             if ($(heading).parents(".markdown").length === 0) {
                 // $(heading) is the page title

como aplicar o patch?

1 - copie o patch acima 2 - Na raiz do seu projeto docsaurus execute o comando:pbpaste | git apply

ou use patch-package

I just tried @fxamauri solution and it worked, thanks @fxamauri

image

schuellerf added a commit to schuellerf/osbuild.github.io that referenced this issue Jul 18, 2024
schuellerf added a commit to schuellerf/osbuild.github.io that referenced this issue Jul 18, 2024
schuellerf added a commit to schuellerf/osbuild.github.io that referenced this issue Jul 19, 2024
@h3nkk44
Copy link
Author

h3nkk44 commented Jul 26, 2024

This #216 should resolve, can you test applying patch?

diff --git a/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js b/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js
index bf41fa2..50bf040 100644
--- a/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js
+++ b/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js
@@ -109,7 +109,9 @@ function html2text(html, type, url = "?") {
                 // <a class="hash-link" href="#first-header" title="Direct link to heading">#</a>
                 .not("a[aria-hidden=true], a.hash-link")
                 .text();
-            const hash = $(heading).find("a.hash-link").attr("href") || "";
+            const linkHash = $(heading).find("a.hash-link").attr("href") || ""
+            const [, hashPart] = linkHash.split("#")
+            const hash = hashPart ? `#${hashPart}` : "";
             let $sectionElements;
             if ($(heading).parents(".markdown").length === 0) {
                 // $(heading) is the page title

how apply patch?

1 - copy patch above 2 - In the root of your docsaurus project run command: pbpaste | git apply

or use patch-package

I tested this fix on an latest docusaurus version with javascript and latest search + the fix provided.
Still getting the same problem for the search result URL.

ondrejbudai pushed a commit to schuellerf/osbuild.github.io that referenced this issue Jul 30, 2024
schuellerf added a commit to osbuild/osbuild.github.io that referenced this issue Jul 30, 2024
@slorber
Copy link

slorber commented Aug 12, 2024

Note: I reverted the Docusaurus v3.4 change to unbreak search plugins in v3.5.

Although you should still apply a fix on your side. See reasons here:

But v3.5 has another issue, please wait until I publish v3.5.2 with a fix for #217

@slorber
Copy link

slorber commented Aug 13, 2024

Docusaurus v3.5.2 has been released and should work fine with this plugin (I tried with v1.2)


Note: you may get another error while building your site.

[ERROR] Error: Unable to build website for locale en.
  ...
  [cause]: TypeError: Cannot read properties of undefined (reading 'load')
      at getDocusaurusTag (.../@cmfcmf/docusaurus-search-local/lib/server/parse.js:194:33)
      at .../@cmfcmf/docusaurus-search-local/lib/server/index.js:288:60

It is a different issue, related to a recent release of Cheerio v1.0 that did unexpected breaking changes. See my PR for details and workarounds: #218

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

Successfully merging a pull request may close this issue.

8 participants