Skip to content

feat(web): add web generator #285

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

feat(web): add web generator #285

wants to merge 5 commits into from

Conversation

avivkeller
Copy link
Member

@avivkeller avivkeller commented May 28, 2025

Fixes #7.

This PR adds the web generator, and some of its components. A few of the components are yet to be implemented.

To Implement

  • ChangeHistory (Assignee: Unassigned)

Get a preview

node bin/cli.mjs generate -t orama-db -i "/node/doc/api/*.md" -o "./out" # If you want search functionality
node bin/cli.mjs generate -t web -i "/node/doc/api/*.md" -o "./out"
npx serve out # You can serve the output, or just open one of the files in your browser

@codecov-commenter
Copy link

codecov-commenter commented May 28, 2025

Codecov Report

Attention: Patch coverage is 79.11765% with 142 lines in your changes missing coverage. Please review.

Project coverage is 54.08%. Comparing base (276687e) to head (6e9acc4).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/generators/web/index.mjs 79.03% 26 Missing ⚠️
src/generators/jsx-ast/index.mjs 0.00% 24 Missing ⚠️
src/generators/jsx-ast/utils/buildContent.mjs 56.86% 22 Missing ⚠️
src/generators/orama-db/index.mjs 57.14% 18 Missing ⚠️
src/generators/jsx-ast/utils/transformer.mjs 20.00% 12 Missing ⚠️
src/generators/web/build/bundle.mjs 91.02% 7 Missing ⚠️
src/generators/jsx-ast/utils/buildBarProps.mjs 50.00% 5 Missing and 1 partial ⚠️
src/generators/index.mjs 0.00% 5 Missing ⚠️
src/generators/web/build/plugins.mjs 95.18% 4 Missing ⚠️
src/releases.mjs 0.00% 4 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #285      +/-   ##
==========================================
+ Coverage   48.90%   54.08%   +5.18%     
==========================================
  Files          82       88       +6     
  Lines        6825     7105     +280     
  Branches      277      302      +25     
==========================================
+ Hits         3338     3843     +505     
+ Misses       3484     3258     -226     
- Partials        3        4       +1     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@avivkeller avivkeller marked this pull request as ready for review May 28, 2025 22:13
@avivkeller avivkeller requested a review from a team as a code owner May 28, 2025 22:13
@avivkeller avivkeller marked this pull request as draft May 29, 2025 16:36
const language = matches?.groups?.language ?? '';
const [copyText, setCopyText] = useState('Copy to clipboard');

const handleCopy = async text => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not including useCopyToClipord in ui lib ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC I didn't include it since it didn't fall under the "UI Component" category, it's a hook, however, if you disagree, I won't block.

"estree-util-value-to-estree": "^3.4.0",
"estree-util-visit": "^2.0.0",
"github-slugger": "^2.0.0",
"glob": "^11.0.2",
"hast-util-to-string": "^3.0.1",
"hastscript": "^9.0.1",
"html-minifier-terser": "^7.2.0",
"mustache": "^4.2.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use __<VARIABLE>__ like in the other generators, however, the JavaScript I was trying to add to the HTML broke the structure of the file. Using a library like Mustache properly escapes anything injected.

Copy link
Member

@AugustinMauroy AugustinMauroy May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export const TEMPLATE = ({...props}) => dedent`
<html>
 ${props.foo}
</html>
`; 

this can work

Copy link
Member Author

@avivkeller avivkeller May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I wasn’t clear, the compiled JavaScript broke the HTML structure because it contained characters that need to be escaped to be in an HTML script.

For example, in your scenario, if props.foo contains a </html>, it’ll escape the sandbox.

Mustache performs all the needed escaping.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we're using yet another layer of whatever freakery here. Mustache is great, but it feels like you're throing a nuke at an ant's sized problem. Not to mention adding yet another engine here will make things even more complex and costly-performance wise. Let's try to avoid throwing npm packages to any problem we encounter, shall we?

@avivkeller
Copy link
Member Author

avivkeller commented May 30, 2025

🎉 The code now dehydrates to the client so it can render without JavaScript!

@AugustinMauroy
Copy link
Member

🎉 The code now dehydrates to the client so it run without JavaScript!

Wow 😵‍💫 and what about codetab

@avivkeller
Copy link
Member Author

avivkeller commented May 30, 2025

It rehydrates and runs with JS, but if you don't have JS, you can still view the docs. I used React's SSRing

@avivkeller
Copy link
Member Author

@AugustinMauroy and I got search to finally work 🎉
image

@avivkeller avivkeller force-pushed the feat/web/gen branch 2 times, most recently from 024bbea to dbfe55d Compare June 3, 2025 21:40
@avivkeller
Copy link
Member Author

@nodejs/nodejs-website @nodejs/web-infra ChangeHistory and SideBar aren't implemented yet, so this is still a draft, but it's ready for you to take a look, so feel free to review :-)

@avivkeller avivkeller linked an issue Jun 6, 2025 that may be closed by this pull request
@AugustinMauroy
Copy link
Member

IDK how next-themes do but on this implementation at loading time there are a big flash

@AugustinMauroy
Copy link
Member

When using Toc it's focus the header and it's have the default focus style. We should probaly disable that

@avivkeller
Copy link
Member Author

@AugustinMauroy I've resolved the flickering, can you confirm?

@AugustinMauroy
Copy link
Member

Flashing I fixed

@AugustinMauroy
Copy link
Member

Link in a stability index isn't parsed as link it's just text so it's not clickable.

@avivkeller
Copy link
Member Author

I've fixed that, I'm pushing the commit now

@AugustinMauroy
Copy link
Member

Do we need reading time. that not make a lot of sense for a doc, because docs isn't continue text it's punctual information.

@AugustinMauroy
Copy link
Member

AugustinMauroy commented Jun 7, 2025

I think we should fix this on the node/nodejs.org side, but shouldn't the numerical index of the StabilityIndex component be at the top left?

@AugustinMauroy
Copy link
Member

“About,” “Synopsis,” and ‘Index’ must be hard-coded values so that they appear first in the sidebar. Currently, “Synopsis,” which has the title “Usage and Example,” appears near the end of the navigation, which is not logical.

setCopyText('Copied to clipboard!');
setTimeout(() => {
setCopyText('Copy to clipboard');
}, 500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}, 500);
}, 1000);

you can give the user time to see that the action has taken place

@flakey5
Copy link
Member

flakey5 commented Jun 8, 2025

Do we need reading time

I think we should keep it in, I don't see a reason to have it everywhere else except docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write React Components Add react-web generator
5 participants