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

Add pagefind #2477

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft

Add pagefind #2477

wants to merge 29 commits into from

Conversation

jingting1412
Copy link
Contributor

@jingting1412 jingting1412 commented Mar 27, 2024

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • 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: ☑️

  • 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).

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.11%. Comparing base (ff1a738) to head (c198553).

❗ 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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jingting1412
Copy link
Contributor Author

jingting1412 commented Mar 29, 2024

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!

@yucheng11122017
Copy link
Contributor

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

@Tim-Siu
Copy link
Contributor

Tim-Siu commented Apr 19, 2024

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!

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"
  }
}

@gerteck
Copy link
Contributor

gerteck commented Jul 9, 2024

I found this useful when I was looking through this issue.

TS Module Resolution

TS Module Reference

{
  "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!

@jingting1412
Copy link
Contributor Author

Hello! Yes this looks great, any work refining this PR would be greatly appreciated

@gerteck gerteck mentioned this pull request Aug 12, 2024
14 tasks
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 this pull request may close these issues.

5 participants