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

trying to implement ldita-bootstrap.lunr in the bootstrap ditaot plugin but facing some error #23

Closed
Gurushesh-Metapercept opened this issue Oct 19, 2023 · 5 comments · Fixed by #28

Comments

@Gurushesh-Metapercept
Copy link

[gen-index-json] Result: 1
[gen-index-json] node:internal/modules/cjs/loader:1325
[gen-index-json] throw err;
[gen-index-json] ^
[gen-index-json]
[gen-index-json] SyntaxError: C:\Users\Admin\AppData\Local\Temp\temp20231019184255754\lunr.json: Unexpected token G in JSON at position 38
[gen-index-json] at parse ()
[gen-index-json] at Module._extensions..json (node:internal/modules/cjs/loader:1322:39)
[gen-index-json] at Module.load (node:internal/modules/cjs/loader:1117:32)
[gen-index-json] at Module._load (node:internal/modules/cjs/loader:958:12)
[gen-index-json] at Module.require (node:internal/modules/cjs/loader:1141:19)
[gen-index-json] at require (node:internal/modules/cjs/helpers:110:18)
[gen-index-json] at Object. (C:\Users\Admin\AppData\Local\Temp\temp20231019184255754\null10407635299677372326:10:19)
[gen-index-json] at Module._compile (node:internal/modules/cjs/loader:1254:14)
[gen-index-json] at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
[gen-index-json] at Module.load (node:internal/modules/cjs/loader:1117:32)
[gen-index-json]
[gen-index-json] Node.js v18.15.0
Error: Lunr.js failed to generate search index

@lakokkonen
Copy link

Hi Gurushesh,

Did you figure this out already? I have encountered the same issue, and been trying to debug it.

I suspect this has something to do with the file paths created by the plugin. They contain a mix of forward and backslashes, and when a backslash is combined with a certain letter (G in your case, for me it was S), the JSON parsing fails and the index is not created. It's a case of JSON escape characters.

Here's a screenshot of the invalid JSON file in my test case. You can see that all first level file paths are correct, but more than one level deep all the slashes are backslashes, which the JSON parser tries to interpret as escape characters:

jsonfail

If you want to confirm this, try building a simple test map with topics in only one folder. The build should work ok.

@jason-fox
Copy link
Collaborator

jason-fox commented Nov 19, 2023

I suspect this is a combination of two things:

  1. Building an index on Windows.
  2. Building an index with deeply embedded folders.

That would leave JSON \ within the link elements, which would be interpreted as escape codes as @lakokkonen described.

Would a simple ANT <replace> and/or XSL replace() be sufficient to fix this? See: develop...jason-fox:dita-bootstrap.lunr:feature/slash

dita uninstall dita-bootstrap.lunr
dita install https://github.com/jason-fox/dita-bootstrap.lunr/archive/feature/slash.zip

Since I don't run on Windows, I can't reproduce this test case.

@lakokkonen
Copy link

lakokkonen commented Nov 20, 2023

With the fix @jason-fox provided the build doesn't fail.

However, the file paths in preview.json still contain the \, so the JSON contains errors:

jsonfail2

In this case, the search is unable to find the topic with the corrupted link.

@jason-fox
Copy link
Collaborator

That just requires the same fix to be applied to the other file. see here - try pulling again.

@lakokkonen
Copy link

Works like a charm now. The JSON is valid and the search is working.

infotexture pushed a commit that referenced this issue Nov 20, 2023
* bb8d4bd Fix windows backslash
* f549157 Replace slash
* da497f6 Remove ANT replace (reverts bb8d4bd)
* 8eb1695 Switch slash
infotexture added a commit that referenced this issue Feb 7, 2024
* release/5.3.4: (21 commits)
  Bump plug-in version attribute to 5.3.4
  Bump prettier from 3.1.1 to 3.2.5 (#42)
  Migrate Husky to v9
  Bump husky from 8.0.3 to 9.0.10 (#41)
  Use depend.preprocess.post endpoint (#40)
  Bump lint-staged from 15.2.0 to 15.2.1 (#37)
  Convert Prettier runtime config to YAML
  Bump prettier from 3.1.0 to 3.1.1 (#36)
  Preserve unstaged changes with the --no-stash flag
  Bump lint-staged from 15.0.2 to 15.2.0 (#35)
  Bump prettier from 3.0.3 to 3.1.0 (#33)
  Fix close button (#31)
  Reverse backslashes for Windows Filepath (#30)
  Add Greek language (#29)
  Fix #23 - Switch link backslash to forward slash (#28)
  Bump @prettier/plugin-xml from 3.2.1 to 3.2.2 (#27)
  Bump lint-staged from 14.0.1 to 15.0.2 (#26)
  Bump lunr-languages from 1.13.0 to 1.14.0 (#25)
  Bump actions/setup-node from 3 to 4 (#24)
  Bump actions/checkout from 3 to 4 (#22)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants