-
Notifications
You must be signed in to change notification settings - Fork 1
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
WIP, updating server.js to use JSDOM to fix isExternal, but also some… #3
WIP, updating server.js to use JSDOM to fix isExternal, but also some… #3
Conversation
// transforms: { | ||
// generator: false, | ||
// }, | ||
// }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output is nice without this. async functions and generators work great in newer Node.
|
||
console.log(dest) | ||
console.log(dest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto formatting based on the repo's eslint/prettier config files.
@@ -48,7 +48,7 @@ | |||
"pub": "sh build/release.sh", | |||
"postinstall": "opencollective-postinstall" | |||
}, | |||
"husky": { | |||
"husky-OFF": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temporary. if we accept any changes, they should all be formatted.
Actually we should just go ahead and format the whole code base all in one PR and get it out of the way if we're going to have the eslint/prettier configs in the repo.
|
||
function cwd(...args) { | ||
return resolve(process.cwd(), ...args); | ||
} | ||
|
||
// Borrowed from https://j11y.io/snippets/getting-a-fully-qualified-url. | ||
function qualifyURL(url) { | ||
// TODO this doesn't work in Node, passing in / results in /. It doesn't know the origin. Maybe we should update `location` globally first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind this comment. I fixed it by configuring JSDom.
this.html = template; | ||
this.config = config = Object.assign({}, config, { | ||
routerMode: 'history', | ||
}); | ||
this.cache = cache; | ||
|
||
// this.cache = cache; // not used for anything? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem to be used for anything.
<!--inject-config--> | ||
<script src="/lib/docsify.js"></script> | ||
</body> | ||
</html>`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to a separate HTML file so it can be re-used (f.e. here, and in the test code).
}, | ||
path: './' | ||
}) | ||
// path: './', // not used for anything? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused? The Renderer
constructor doesn't use this option for anything, unless I missed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I found out because I add // @ts-check
at the top of any JS file and have TypeScript do live type checking in VS Code, and it complained that the option was unused (which appears to be the case).
Looks like we have some cleanup to do.
// path: './', // not used for anything? | ||
}); | ||
|
||
expect(renderer).to.be.an.instanceof(Renderer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A starting point to officially test the server code.
server.js
Outdated
const { initJSDOM } = require('./test/_helper'); | ||
|
||
const dom = initJSDOM(); | ||
dom.reconfigure({ url: 'https://127.0.0.1:3000' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most important change. This makes isExternal
work.
Renderer
already needs to use DOM APIs anyways, so it's not a big deal to set up JSDom here. I'm not sure how the DOM APIs were being set up before though... Unless this server.js
never worked? What is it used for?
const { | ||
Renderer, | ||
getDefaultTemplate, | ||
} = require('./packages/docsify-server-renderer/index'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import the ES Modules. Much nicer experience in the debugger (Chrome devtools).
Try it:
npm i -g ndb
SSR=true ndb server.js
Once you run it, you should see an error inside the compiler.path()
method. Pause devtools on uncaught exceptions in the Sources
tab.
getDefaultTemplate, | ||
} = require('./packages/docsify-server-renderer/index'); | ||
|
||
debugger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temporary. I will delete this commit and recreate the branch all cleaned up. We just need to decide what to do.
I didnt give a deep look but it looks great. I will check this locally. we can support node v10 as a minimum. also, for this docsifyjs#1128, I was thinking we can create a separate PR with your implement just to reduce the complexity? It will help you as well to work in that better. we can open the PR just for the reference. what do you think? |
Sure. 👍 Probably we should open any new branches in the main repo, that way if we do pull requests onto each others' branches we can view them all in the main repo and other people can chime in too (instead of opening PRs in my or your personal repos). |
great 👍 |
45023a4
to
1e3dd13
Compare
This takes a string input, and converts it into a fully-qualified URL. For example, `./foo` becomes `http://example.com/current/path/foo`. Then we can compare it to other fully-qualified `URL` instances.
20e735a
to
329120f
Compare
…rk. Need to make a test to test that DOMPurify is working, and also isExternal is working using <img> API
329120f
to
f18b994
Compare
Moving this to a PR in the main repo for visibility; docsifyjs#1227 |
This is a "draft" pull request, for discussion. Let's figure out what we want to do.