@docusaurus/core 0.0.0-4353 → 0.0.0-4355

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { Locals } from '@slorber/static-site-generator-webpack-plugin';
8
+ export default function render(locals: Locals & {
9
+ path: string;
10
+ }): Promise<string>;
@@ -4,143 +4,109 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
-
8
- // @ts-check
9
-
10
7
  import * as eta from 'eta';
11
8
  import React from 'react';
12
- import {StaticRouter} from 'react-router-dom';
9
+ import { StaticRouter } from 'react-router-dom';
13
10
  import ReactDOMServer from 'react-dom/server';
14
- import {Helmet} from 'react-helmet';
15
- import {getBundles} from 'react-loadable-ssr-addon-v5-slorber';
11
+ import { Helmet } from 'react-helmet';
12
+ import { getBundles } from 'react-loadable-ssr-addon-v5-slorber';
16
13
  import Loadable from 'react-loadable';
17
-
18
- import {minify} from 'html-minifier-terser';
14
+ import { minify } from 'html-minifier-terser';
19
15
  import path from 'path';
20
16
  import fs from 'fs-extra';
21
17
  import routes from '@generated/routes';
22
- import packageJson from '../../package.json';
23
18
  import preload from './preload';
24
19
  import App from './App';
25
- import {
26
- createStatefulLinksCollector,
27
- ProvideLinksCollector,
28
- } from './LinksCollector';
20
+ import { createStatefulLinksCollector, ProvideLinksCollector, } from './LinksCollector';
29
21
  import logger from '@docusaurus/logger';
30
22
  // eslint-disable-next-line no-restricted-imports
31
- import {memoize} from 'lodash';
32
-
33
- const getCompiledSSRTemplate = memoize((template) =>
34
- eta.compile(template.trim(), {
23
+ import { memoize } from 'lodash';
24
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
25
+ const packageJson = require('../../package.json');
26
+ const getCompiledSSRTemplate = memoize((template) => eta.compile(template.trim(), {
35
27
  rmWhitespace: true,
36
- }),
37
- );
38
-
28
+ }));
39
29
  function renderSSRTemplate(ssrTemplate, data) {
40
- const compiled = getCompiledSSRTemplate(ssrTemplate);
41
- return compiled(data, eta.defaultConfig);
30
+ const compiled = getCompiledSSRTemplate(ssrTemplate);
31
+ return compiled(data, eta.defaultConfig);
42
32
  }
43
-
44
33
  export default async function render(locals) {
45
- try {
46
- return await doRender(locals);
47
- } catch (e) {
48
- logger.error`Docusaurus Node/SSR could not render static page with path path=${locals.path} because of following error:
34
+ try {
35
+ return await doRender(locals);
36
+ }
37
+ catch (e) {
38
+ logger.error `Docusaurus Node/SSR could not render static page with path path=${locals.path} because of following error:
49
39
  ${e.stack}`;
50
-
51
- const isNotDefinedErrorRegex =
52
- /(window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
53
-
54
- if (isNotDefinedErrorRegex.test(e.message)) {
55
- logger.info`It looks like you are using code that should run on the client-side only.
40
+ const isNotDefinedErrorRegex = /(window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
41
+ if (isNotDefinedErrorRegex.test(e.message)) {
42
+ logger.info `It looks like you are using code that should run on the client-side only.
56
43
  To get around it, try using code=${'<BrowserOnly>'} (path=${'https://docusaurus.io/docs/docusaurus-core/#browseronly'}) or code=${'ExecutionEnvironment'} (path=${'https://docusaurus.io/docs/docusaurus-core/#executionenvironment'}).
57
44
  It might also require to wrap your client code in code=${'useEffect'} hook and/or import a third-party library dynamically (if any).`;
45
+ }
46
+ throw new Error('Server-side rendering fails due to the error above.');
58
47
  }
59
-
60
- throw new Error('Server-side rendering fails due to the error above.');
61
- }
62
48
  }
63
-
64
49
  // Renderer for static-site-generator-webpack-plugin (async rendering via promises).
65
50
  async function doRender(locals) {
66
- const {
67
- routesLocation,
68
- headTags,
69
- preBodyTags,
70
- postBodyTags,
71
- onLinksCollected,
72
- baseUrl,
73
- ssrTemplate,
74
- noIndex,
75
- } = locals;
76
- const location = routesLocation[locals.path];
77
- await preload(routes, location);
78
- const modules = new Set();
79
- const context = {};
80
-
81
- const linksCollector = createStatefulLinksCollector();
82
- const appHtml = ReactDOMServer.renderToString(
83
- <Loadable.Capture report={(moduleName) => modules.add(moduleName)}>
84
- <StaticRouter location={location} context={context}>
85
- <ProvideLinksCollector linksCollector={linksCollector}>
86
- <App />
87
- </ProvideLinksCollector>
88
- </StaticRouter>
89
- </Loadable.Capture>,
90
- );
91
- onLinksCollected(location, linksCollector.getCollectedLinks());
92
-
93
- const helmet = Helmet.renderStatic();
94
- const htmlAttributes = helmet.htmlAttributes.toString();
95
- const bodyAttributes = helmet.bodyAttributes.toString();
96
- const metaStrings = [
97
- helmet.title.toString(),
98
- helmet.meta.toString(),
99
- helmet.link.toString(),
100
- helmet.script.toString(),
101
- ];
102
- const metaAttributes = metaStrings.filter(Boolean);
103
-
104
- const {generatedFilesDir} = locals;
105
- const manifestPath = path.join(generatedFilesDir, 'client-manifest.json');
106
- const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
107
-
108
- // Get all required assets for this particular page based on client
109
- // manifest information.
110
- const modulesToBeLoaded = [...manifest.entrypoints, ...Array.from(modules)];
111
- const bundles = getBundles(manifest, modulesToBeLoaded);
112
- const stylesheets = (bundles.css || []).map((b) => b.file);
113
- const scripts = (bundles.js || []).map((b) => b.file);
114
-
115
- const renderedHtml = renderSSRTemplate(ssrTemplate, {
116
- appHtml,
117
- baseUrl,
118
- htmlAttributes: htmlAttributes || '',
119
- bodyAttributes: bodyAttributes || '',
120
- headTags,
121
- preBodyTags,
122
- postBodyTags,
123
- metaAttributes,
124
- scripts,
125
- stylesheets,
126
- noIndex,
127
- version: packageJson.version,
128
- });
129
-
130
- try {
131
- // Minify html with https://github.com/DanielRuf/html-minifier-terser
132
- return await minify(renderedHtml, {
133
- removeComments: false,
134
- removeRedundantAttributes: true,
135
- removeEmptyAttributes: true,
136
- removeScriptTypeAttributes: true,
137
- removeStyleLinkTypeAttributes: true,
138
- useShortDoctype: true,
139
- minifyJS: true,
51
+ const { routesLocation, headTags, preBodyTags, postBodyTags, onLinksCollected, baseUrl, ssrTemplate, noIndex, } = locals;
52
+ const location = routesLocation[locals.path];
53
+ await preload(routes, location);
54
+ const modules = new Set();
55
+ const context = {};
56
+ const linksCollector = createStatefulLinksCollector();
57
+ const appHtml = ReactDOMServer.renderToString(React.createElement(Loadable.Capture, { report: (moduleName) => modules.add(moduleName) },
58
+ React.createElement(StaticRouter, { location: location, context: context },
59
+ React.createElement(ProvideLinksCollector, { linksCollector: linksCollector },
60
+ React.createElement(App, null)))));
61
+ onLinksCollected(location, linksCollector.getCollectedLinks());
62
+ const helmet = Helmet.renderStatic();
63
+ const htmlAttributes = helmet.htmlAttributes.toString();
64
+ const bodyAttributes = helmet.bodyAttributes.toString();
65
+ const metaStrings = [
66
+ helmet.title.toString(),
67
+ helmet.meta.toString(),
68
+ helmet.link.toString(),
69
+ helmet.script.toString(),
70
+ ];
71
+ const metaAttributes = metaStrings.filter(Boolean);
72
+ const { generatedFilesDir } = locals;
73
+ const manifestPath = path.join(generatedFilesDir, 'client-manifest.json');
74
+ const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
75
+ // Get all required assets for this particular page based on client
76
+ // manifest information.
77
+ const modulesToBeLoaded = [...manifest.entrypoints, ...Array.from(modules)];
78
+ const bundles = getBundles(manifest, modulesToBeLoaded);
79
+ const stylesheets = (bundles.css || []).map((b) => b.file);
80
+ const scripts = (bundles.js || []).map((b) => b.file);
81
+ const renderedHtml = renderSSRTemplate(ssrTemplate, {
82
+ appHtml,
83
+ baseUrl,
84
+ htmlAttributes: htmlAttributes || '',
85
+ bodyAttributes: bodyAttributes || '',
86
+ headTags,
87
+ preBodyTags,
88
+ postBodyTags,
89
+ metaAttributes,
90
+ scripts,
91
+ stylesheets,
92
+ noIndex,
93
+ version: packageJson.version,
140
94
  });
141
- } catch (e) {
142
- logger.error`Minification of page path=${locals.path} failed because of following error:
95
+ try {
96
+ // Minify html with https://github.com/DanielRuf/html-minifier-terser
97
+ return await minify(renderedHtml, {
98
+ removeComments: false,
99
+ removeRedundantAttributes: true,
100
+ removeEmptyAttributes: true,
101
+ removeScriptTypeAttributes: true,
102
+ removeStyleLinkTypeAttributes: true,
103
+ useShortDoctype: true,
104
+ minifyJS: true,
105
+ });
106
+ }
107
+ catch (e) {
108
+ logger.error `Minification of page path=${locals.path} failed because of following error:
143
109
  ${e.stack}`;
144
- throw e;
145
- }
110
+ throw e;
111
+ }
146
112
  }
@@ -101,7 +101,7 @@ async function start(siteDir, cliOptions) {
101
101
  plugins: [
102
102
  // Generates an `index.html` file with the <script> injected.
103
103
  new html_webpack_plugin_1.default({
104
- template: path_1.default.resolve(__dirname, '../client/templates/index.html.template.ejs'),
104
+ template: path_1.default.resolve(__dirname, '../webpack/templates/index.html.template.ejs'),
105
105
  // So we can define the position where the scripts are injected.
106
106
  inject: false,
107
107
  filename: 'index.html',
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
11
11
  const utils_1 = require("@docusaurus/utils");
12
12
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
13
  const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
14
- const ssr_html_template_1 = (0, tslib_1.__importDefault)(require("../client/templates/ssr.html.template"));
14
+ const ssr_html_template_1 = (0, tslib_1.__importDefault)(require("../webpack/templates/ssr.html.template"));
15
15
  const client_modules_1 = (0, tslib_1.__importDefault)(require("./client-modules"));
16
16
  const config_1 = (0, tslib_1.__importDefault)(require("./config"));
17
17
  const plugins_1 = require("./plugins");
@@ -77,7 +77,7 @@ async function loadContext(siteDir, options = {}) {
77
77
  outDir,
78
78
  baseUrl,
79
79
  i18n,
80
- ssrTemplate,
80
+ ssrTemplate: ssrTemplate !== null && ssrTemplate !== void 0 ? ssrTemplate : ssr_html_template_1.default,
81
81
  codeTranslations,
82
82
  };
83
83
  }
@@ -277,7 +277,7 @@ ${Object.keys(registry)
277
277
  headTags,
278
278
  preBodyTags,
279
279
  postBodyTags,
280
- ssrTemplate: ssrTemplate || ssr_html_template_1.default,
280
+ ssrTemplate,
281
281
  codeTranslations,
282
282
  };
283
283
  return props;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ declare const _default: "\n<!DOCTYPE html>\n<html <%~ it.htmlAttributes %>>\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"generator\" content=\"Docusaurus v<%= it.version %>\">\n <% if (it.noIndex) { %>\n <meta name=\"robots\" content=\"noindex, nofollow\" />\n <% } %>\n <%~ it.headTags %>\n <% it.metaAttributes.forEach((metaAttribute) => { %>\n <%~ metaAttribute %>\n <% }); %>\n <% it.stylesheets.forEach((stylesheet) => { %>\n <link rel=\"stylesheet\" href=\"<%= it.baseUrl %><%= stylesheet %>\" />\n <% }); %>\n <% it.scripts.forEach((script) => { %>\n <link rel=\"preload\" href=\"<%= it.baseUrl %><%= script %>\" as=\"script\">\n <% }); %>\n </head>\n <body <%~ it.bodyAttributes %>>\n <%~ it.preBodyTags %>\n <div id=\"__docusaurus\">\n <%~ it.appHtml %>\n </div>\n <% it.scripts.forEach((script) => { %>\n <script src=\"<%= it.baseUrl %><%= script %>\"></script>\n <% }); %>\n <%~ it.postBodyTags %>\n </body>\n</html>\n";
8
+ export default _default;
@@ -1,11 +1,12 @@
1
+ "use strict";
1
2
  /**
2
3
  * Copyright (c) Facebook, Inc. and its affiliates.
3
4
  *
4
5
  * This source code is licensed under the MIT license found in the
5
6
  * LICENSE file in the root directory of this source tree.
6
7
  */
7
-
8
- module.exports = `
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.default = `
9
10
  <!DOCTYPE html>
10
11
  <html <%~ it.htmlAttributes %>>
11
12
  <head>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "0.0.0-4353",
4
+ "version": "0.0.0-4355",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -41,13 +41,13 @@
41
41
  "@babel/runtime": "^7.16.3",
42
42
  "@babel/runtime-corejs3": "^7.16.3",
43
43
  "@babel/traverse": "^7.16.3",
44
- "@docusaurus/cssnano-preset": "0.0.0-4353",
45
- "@docusaurus/logger": "0.0.0-4353",
46
- "@docusaurus/mdx-loader": "0.0.0-4353",
44
+ "@docusaurus/cssnano-preset": "0.0.0-4355",
45
+ "@docusaurus/logger": "0.0.0-4355",
46
+ "@docusaurus/mdx-loader": "0.0.0-4355",
47
47
  "@docusaurus/react-loadable": "5.5.2",
48
- "@docusaurus/utils": "0.0.0-4353",
49
- "@docusaurus/utils-common": "0.0.0-4353",
50
- "@docusaurus/utils-validation": "0.0.0-4353",
48
+ "@docusaurus/utils": "0.0.0-4355",
49
+ "@docusaurus/utils-common": "0.0.0-4355",
50
+ "@docusaurus/utils-validation": "0.0.0-4355",
51
51
  "@slorber/static-site-generator-webpack-plugin": "^4.0.0",
52
52
  "@svgr/webpack": "^6.0.0",
53
53
  "autoprefixer": "^10.3.5",
@@ -108,8 +108,8 @@
108
108
  "webpackbar": "^5.0.0-3"
109
109
  },
110
110
  "devDependencies": {
111
- "@docusaurus/module-type-aliases": "0.0.0-4353",
112
- "@docusaurus/types": "0.0.0-4353",
111
+ "@docusaurus/module-type-aliases": "0.0.0-4355",
112
+ "@docusaurus/types": "0.0.0-4355",
113
113
  "@types/copy-webpack-plugin": "^8.0.1",
114
114
  "@types/css-minimizer-webpack-plugin": "^3.0.2",
115
115
  "@types/detect-port": "^1.3.0",
@@ -128,5 +128,5 @@
128
128
  "engines": {
129
129
  "node": ">=14"
130
130
  },
131
- "gitHead": "be63846065f268c1867ff53bcfe29275a496f09b"
131
+ "gitHead": "4ad639a600a7aa5415733d798ed53a5a99ac7da0"
132
132
  }