-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
fix #1101, #704 #1311
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
fix #1101, #704 #1311
Conversation
- For SSR, there is no location object in Node.js
- Fix external path test - Use `README.md` as default homepage
- Introduced new `baseUrl` config entry
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/docsify-core/docsify-preview/7pmavtza0 |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 363548a:
|
Known problem:
|
New stuff added:
|
A simple SSR using packages const Express = require('express');
const Fs = require('fs');
const DocsifyServerRenderer = require('docsify-server-renderer');
const router = Express.Router();
const DocBase = '/tmp/doc';
// Expose `.md` file to server url for `history` mode loading
router.use('', Express.static(DocBase));
router.get('/:url(.{0,})', async function(req, res, next) {
let url = req.params.url || '';
let renderConfig = {
loadNavbar: false,
loadSidebar: true,
name: 'docsify',
basePath: DocBase, // This is local server location, and will be replaced by `baseUrl` when SSR
baseUrl: '' // This is for overriding `basePath` if `basePath` is local path in server
};
let tplContent = Fs.readFileSync('./tpl.html', 'utf8');
let tplConfig = {template: tplContent, config: renderConfig};
let tplRenderer = new DocsifyServerRenderer(tplConfig);
let tplRendered = await tplRenderer.renderToString(url);
return res.send(tplRendered);
});
module.exports = router; |
I do not think it is common procedure for an SSR engine to fetch Markdown (parsing resource) remotely via url. |
this.html = this.html.replace(new RegExp(`<!--${match}-->`, 'g'), content); | ||
_getWebConfig() { | ||
let config = Object.assign({}, this.config); | ||
config.routerMode = 'abstract'; |
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.
why assigning router to abstract ? is it for the default ?
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.
Since the page is rendered in the server-side, there is no need for web page javascripts to deal sidebar links as 'history' or 'hash' mode, it is directly an <a>
link. Thus, I uses 'abstract' as the mode to avoid any js on-
hooks.
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.
cc @docsifyjs/reviewers
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.
@anikethsaha
I found that e2e tests runs through both hash and history modes. Thus, I am going to change this as following:
- Since SSR only goes an
<a>
link, and no need foronchange
actions, I will useabstract
as routerMode in injected config. - Since SSR is in node, which does not have
window
object, I will use defaultgetBasePath
,getCurrentPath
andnormalize
methods fromHistory
class. - Since
parse
andtoURL
methods are required for generating links, I will use corresponding methods from eitherHashHistory
orHTML5History
class'es prototype.
Note: SSR config is slightly different from injected config. Injected one has routerMode 'abstract' to avoid onchange
hooks. SSR config has routerMode 'hash' or 'history' to make sure the links are rendered correctly.
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.
We are not doing e2e for SSR I suppose, Also I would recommend to not change the current tests as it is being completely re-written #1276
@boxsnake thanks for having attempted this. The SSR is too incomplete and experimental, as we recently added to README (plugins and various features of Docsify not working, etc). I have a plan for a solid implementation of SSR that I will prototype soon, and it will remove SSR code from Docsify and delegate to a framework that specializes in SSR (Solid.js). |
Summary
This fix solved:
This fix introduced:
baseUrl
config entry to allow user overridebasePath
whenbasePath
is local location for SSRWhat kind of change does this PR introduce? (check at least one)
If changing the UI of default theme, please provide the before/after screenshot:
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
fix #xxx[,#xxx]
, where "xxx" is the issue number)You have tested in the following browsers: (Providing a detailed version will be better.)
If adding a new feature, the PR's description includes:
To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.