cmfcmf / docusaurus-search-local

Offline / Local Search for Docusaurus v2. Try it live at:
https://cmfcmf.github.io/OpenWeatherMap-PHP-API/
MIT License
431 stars 67 forks source link

Search result path not correct #214

Open h3nkk44 opened 2 weeks ago

h3nkk44 commented 2 weeks ago

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

sibelius commented 1 week ago

it is duplicating somehow

Rob-Purbrick commented 1 week ago

Seeing same behaviour in previously working docs

olganaumenko commented 1 week ago
Снимок экрана 2024-07-12 в 12 11 03

I see the same problem for my website :(

clainchoupi commented 2 days ago

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 commented 1 day ago

This https://github.com/cmfcmf/docusaurus-search-local/pull/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 commented 21 hours ago

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