markbind
markbind copied to clipboard
Add pagefind
What is the purpose of this pull request?
- [ ] Documentation update
- [ ] Bug fix
- [x] Feature addition or enhancement
- [ ] Code maintenance
- [ ] DevOps
- [ ] Improve developer experience
- [ ] Others, please explain:
Overview of changes: To track the addition of pagefind for full-text search. Welcome anyone to help look through.
Anything you'd like to highlight/discuss:
Testing instructions:
Proposed commit message: (wrap lines at 72 characters) Add pagefind for search
Checklist: :ballot_box_with_check:
- [ ] Updated the documentation for feature additions and enhancements
- [ ] Added tests for bug fixes or features
- [ ] Linked all related issues
- [ ] No unrelated changes
Reviewer checklist:
Indicate the SEMVER impact of the PR:
- [ ] Major (when you make incompatible API changes)
- [ ] Minor (when you add functionality in a backward compatible manner)
- [ ] Patch (when you make backward compatible bug fixes)
At the end of the review, please label the PR with the appropriate label: r.Major
, r.Minor
, r.Patch
.
Breaking change release note preparation (if applicable):
- To be included in the release note for any feature that is made obsolete/breaking
Give a brief explanation note about:
- what was the old feature that was made obsolete
- any replacement feature (if any), and
- how the author should modify his website to migrate from the old feature to the replacement feature (if possible).
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 51.11%. Comparing base (
ff1a738
) to head (c198553
).
:exclamation: Current head c198553 differs from pull request most recent head fe5407e. Consider uploading reports for the commit fe5407e to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## master #2477 +/- ##
==========================================
+ Coverage 50.99% 51.11% +0.11%
==========================================
Files 124 124
Lines 5383 5355 -28
Branches 1160 1152 -8
==========================================
- Hits 2745 2737 -8
+ Misses 2348 2328 -20
Partials 290 290
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hello! I'm trying to implement this but I'm having trouble with indexing the generated HTML pages using the methods provided by the Plugins, so any tips or comments to point me in the right direction would be greatly appreciated!
I'm also investigating adding pagefind as a dependency, adding it to the current build process (index.ts
) so that an index can be created after the site is built. However, I'm having issues importing the NodeJS API package. Currently Pagefind's npm interface only supports being used as an ESM module via import
, rather than as a CJS package through require
. So import * as pagefind from 'pagefind'
would be acceptable, but const pagefind = require('pagefind')
would result in the following error:
message=No "exports" main defined in /Users/wangjingting/markbind/node_modules/pagefind/package.json, stack=Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/wangjingting/markbind/node_modules/pagefind/package.json
at exportsNotFound (node:internal/modules/esm/resolve:303:10)
at packageExportsResolve (node:internal/modules/esm/resolve:593:13)
at resolveExports (node:internal/modules/cjs/loader:591:36)
at Module._findPath (node:internal/modules/cjs/loader:668:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1130:27)
at Module._load (node:internal/modules/cjs/loader:985:27)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at /Users/wangjingting/markbind/packages/core/src/Site/index.js:509:92, code=ERR_PACKAGE_PATH_NOT_EXPORTED
This issue can be resolved using async import, and I've used it in Site.ts
to import the functions with no issue. However, the generated Site.js
file would then still convert the import to require('pagefind')
, which results in the import issue.
More specifics can be found in this discussion., and here on cjs-esm import compatibility
If anyone has any ideas on how best to continue, or if I've missed something, please help me out. Thank you!
Hello! I'm trying to implement this but I'm having trouble with indexing the generated HTML pages using the methods provided by the Plugins, so any tips or comments to point me in the right direction would be greatly appreciated!
Ok not too sure about the dependency issue but you could try using postRender instead of processNode? The functionality might be similiar to that in the Mermaid PR #2475
Hello! I'm trying to implement this but I'm having trouble with indexing the generated HTML pages using the methods provided by the Plugins, so any tips or comments to point me in the right direction would be greatly appreciated!
I'm also investigating adding pagefind as a dependency, adding it to the current build process (
index.ts
) so that an index can be created after the site is built. However, I'm having issues importing the NodeJS API package. Currently Pagefind's npm interface only supports being used as an ESM module viaimport
, rather than as a CJS package throughrequire
. Soimport * as pagefind from 'pagefind'
would be acceptable, butconst pagefind = require('pagefind')
would result in the following error:message=No "exports" main defined in /Users/wangjingting/markbind/node_modules/pagefind/package.json, stack=Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/wangjingting/markbind/node_modules/pagefind/package.json at exportsNotFound (node:internal/modules/esm/resolve:303:10) at packageExportsResolve (node:internal/modules/esm/resolve:593:13) at resolveExports (node:internal/modules/cjs/loader:591:36) at Module._findPath (node:internal/modules/cjs/loader:668:31) at Module._resolveFilename (node:internal/modules/cjs/loader:1130:27) at Module._load (node:internal/modules/cjs/loader:985:27) at Module.require (node:internal/modules/cjs/loader:1235:19) at require (node:internal/modules/helpers:176:18) at /Users/wangjingting/markbind/packages/core/src/Site/index.js:509:92, code=ERR_PACKAGE_PATH_NOT_EXPORTED
This issue can be resolved using async import, and I've used it in
Site.ts
to import the functions with no issue. However, the generatedSite.js
file would then still convert the import torequire('pagefind')
, which results in the import issue.More specifics can be found in this discussion., and here on cjs-esm import compatibility
If anyone has any ideas on how best to continue, or if I've missed something, please help me out. Thank you!
From my perspectives, the Pull Request is on the right track to bring in Pagefind
.
I think to ensure TypeScript configuration is set up to output ESM code, you can modify the tsconfig.json
file to include the following options:
{
"compilerOptions": {
// ... other options ...
"module": "esnext",
"moduleResolution": "node"
}
}
I found this useful when I was looking through this issue.
{
"extends": "../../tsconfig_base.json",
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
},
"exclude": ["node_modules"]
}
Specify the module resolution strategy: 'node16' or 'nodenext' for modern versions of Node.js. Node.js v12 and later supports both ECMAScript imports and CommonJS require, which resolve using different algorithms. These moduleResolution values, when combined with the corresponding module values, picks the right algorithm for each resolution based on whether Node.js will see an import or require in the output JavaScript code.
Tried it, and it correctly converts the .ts to the appropriate .js code for module resolution.
I will also try and work on refining this PR. Cheers!
Hello! Yes this looks great, any work refining this PR would be greatly appreciated