@docusaurus/core 3.7.0-canary-6200 → 3.7.0-canary-6201

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.
@@ -12,7 +12,8 @@ import { renderToHtml } from './renderToHtml';
12
12
  import preload from './preload';
13
13
  import App from './App';
14
14
  import { createStatefulBrokenLinks, BrokenLinksProvider, } from './BrokenLinksContext';
15
- const render = async ({ pathname }) => {
15
+ import { toPageCollectedMetadata } from './serverHelmetUtils';
16
+ const render = async ({ pathname, v4RemoveLegacyPostBuildHeadAttribute, }) => {
16
17
  await preload(pathname);
17
18
  const modules = new Set();
18
19
  const routerContext = {};
@@ -30,10 +31,15 @@ const render = async ({ pathname }) => {
30
31
  </HelmetProvider>
31
32
  </Loadable.Capture>);
32
33
  const html = await renderToHtml(app);
34
+ const { helmet } = helmetContext;
35
+ const metadata = toPageCollectedMetadata({ helmet });
36
+ // TODO Docusaurus v4 remove with deprecated postBuild({head}) API
37
+ // the returned collectedData must be serializable to run in workers
38
+ if (v4RemoveLegacyPostBuildHeadAttribute) {
39
+ metadata.helmet = null;
40
+ }
33
41
  const collectedData = {
34
- // TODO Docusaurus v4 refactor: helmet state is non-serializable
35
- // this makes it impossible to run SSG in a worker thread
36
- helmet: helmetContext.helmet,
42
+ metadata,
37
43
  anchors: statefulBrokenLinks.getCollectedAnchors(),
38
44
  links: statefulBrokenLinks.getCollectedLinks(),
39
45
  modules: Array.from(modules),
@@ -0,0 +1,11 @@
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 { PageCollectedMetadata } from '../common';
8
+ import type { HelmetServerState } from 'react-helmet-async';
9
+ export declare function toPageCollectedMetadata({ helmet, }: {
10
+ helmet: HelmetServerState;
11
+ }): PageCollectedMetadata;
@@ -0,0 +1,39 @@
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
+ function getBuildMetaTags(helmet) {
8
+ // @ts-expect-error: see https://github.com/staylor/react-helmet-async/pull/167
9
+ const metaElements = helmet.meta.toComponent() ?? [];
10
+ return metaElements.map((el) => el.props);
11
+ }
12
+ function isNoIndexTag(tag) {
13
+ if (!tag.name || !tag.content) {
14
+ return false;
15
+ }
16
+ return (
17
+ // meta name is not case-sensitive
18
+ tag.name.toLowerCase() === 'robots' &&
19
+ // Robots directives are not case-sensitive
20
+ tag.content.toLowerCase().includes('noindex'));
21
+ }
22
+ export function toPageCollectedMetadata({ helmet, }) {
23
+ const tags = getBuildMetaTags(helmet);
24
+ const noIndex = tags.some(isNoIndexTag);
25
+ return {
26
+ helmet, // TODO Docusaurus v4 remove
27
+ public: {
28
+ noIndex,
29
+ },
30
+ internal: {
31
+ htmlAttributes: helmet.htmlAttributes.toString(),
32
+ bodyAttributes: helmet.bodyAttributes.toString(),
33
+ title: helmet.title.toString(),
34
+ meta: helmet.meta.toString(),
35
+ link: helmet.link.toString(),
36
+ script: helmet.script.toString(),
37
+ },
38
+ };
39
+ }
@@ -71,7 +71,10 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
71
71
  logger_1.default.success `Generated static files in path=${path_1.default.relative(process.cwd(), outDir)}.`;
72
72
  }
73
73
  async function executePluginsPostBuild({ plugins, props, collectedData, }) {
74
- const head = lodash_1.default.mapValues(collectedData, (d) => d.helmet);
74
+ const head = props.siteConfig.future.v4.removeLegacyPostBuildHeadAttribute
75
+ ? {}
76
+ : lodash_1.default.mapValues(collectedData, (d) => d.metadata.helmet);
77
+ const routesBuildMetadata = lodash_1.default.mapValues(collectedData, (d) => d.metadata.public);
75
78
  await Promise.all(plugins.map(async (plugin) => {
76
79
  if (!plugin.postBuild) {
77
80
  return;
@@ -79,6 +82,7 @@ async function executePluginsPostBuild({ plugins, props, collectedData, }) {
79
82
  await plugin.postBuild({
80
83
  ...props,
81
84
  head,
85
+ routesBuildMetadata,
82
86
  content: plugin.content,
83
87
  });
84
88
  }));
@@ -5,12 +5,14 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { Joi } from '@docusaurus/utils-validation';
8
- import type { FasterConfig, FutureConfig, StorageConfig } from '@docusaurus/types/src/config';
8
+ import type { FasterConfig, FutureConfig, FutureV4Config, StorageConfig } from '@docusaurus/types/src/config';
9
9
  import type { DocusaurusConfig, I18nConfig, MarkdownConfig } from '@docusaurus/types';
10
10
  export declare const DEFAULT_I18N_CONFIG: I18nConfig;
11
11
  export declare const DEFAULT_STORAGE_CONFIG: StorageConfig;
12
12
  export declare const DEFAULT_FASTER_CONFIG: FasterConfig;
13
13
  export declare const DEFAULT_FASTER_CONFIG_TRUE: FasterConfig;
14
+ export declare const DEFAULT_FUTURE_V4_CONFIG: FutureV4Config;
15
+ export declare const DEFAULT_FUTURE_V4_CONFIG_TRUE: FutureV4Config;
14
16
  export declare const DEFAULT_FUTURE_CONFIG: FutureConfig;
15
17
  export declare const DEFAULT_MARKDOWN_CONFIG: MarkdownConfig;
16
18
  export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'future' | 'onBrokenLinks' | 'onBrokenAnchors' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'headTags' | 'stylesheets' | 'scripts' | 'clientModules' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'tagline' | 'baseUrlIssueBanner' | 'staticDirectories' | 'markdown'>;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_FASTER_CONFIG_TRUE = exports.DEFAULT_FASTER_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
9
+ exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_FUTURE_V4_CONFIG_TRUE = exports.DEFAULT_FUTURE_V4_CONFIG = exports.DEFAULT_FASTER_CONFIG_TRUE = exports.DEFAULT_FASTER_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
10
10
  exports.validateConfig = validateConfig;
11
11
  const utils_1 = require("@docusaurus/utils");
12
12
  const utils_validation_1 = require("@docusaurus/utils-validation");
@@ -39,7 +39,15 @@ exports.DEFAULT_FASTER_CONFIG_TRUE = {
39
39
  mdxCrossCompilerCache: true,
40
40
  rspackBundler: true,
41
41
  };
42
+ exports.DEFAULT_FUTURE_V4_CONFIG = {
43
+ removeLegacyPostBuildHeadAttribute: false,
44
+ };
45
+ // When using the "v4: true" shortcut
46
+ exports.DEFAULT_FUTURE_V4_CONFIG_TRUE = {
47
+ removeLegacyPostBuildHeadAttribute: true,
48
+ };
42
49
  exports.DEFAULT_FUTURE_CONFIG = {
50
+ v4: exports.DEFAULT_FUTURE_V4_CONFIG,
43
51
  experimental_faster: exports.DEFAULT_FASTER_CONFIG,
44
52
  experimental_storage: exports.DEFAULT_STORAGE_CONFIG,
45
53
  experimental_router: 'browser',
@@ -160,6 +168,14 @@ const FASTER_CONFIG_SCHEMA = utils_validation_1.Joi.alternatives()
160
168
  .custom((bool) => bool ? exports.DEFAULT_FASTER_CONFIG_TRUE : exports.DEFAULT_FASTER_CONFIG))
161
169
  .optional()
162
170
  .default(exports.DEFAULT_FASTER_CONFIG);
171
+ const FUTURE_V4_SCHEMA = utils_validation_1.Joi.alternatives()
172
+ .try(utils_validation_1.Joi.object({
173
+ removeLegacyPostBuildHeadAttribute: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FUTURE_V4_CONFIG.removeLegacyPostBuildHeadAttribute),
174
+ }), utils_validation_1.Joi.boolean()
175
+ .required()
176
+ .custom((bool) => bool ? exports.DEFAULT_FUTURE_V4_CONFIG_TRUE : exports.DEFAULT_FUTURE_V4_CONFIG))
177
+ .optional()
178
+ .default(exports.DEFAULT_FUTURE_V4_CONFIG);
163
179
  const STORAGE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
164
180
  type: utils_validation_1.Joi.string()
165
181
  .equal('localStorage', 'sessionStorage')
@@ -171,6 +187,7 @@ const STORAGE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
171
187
  .optional()
172
188
  .default(exports.DEFAULT_STORAGE_CONFIG);
173
189
  const FUTURE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
190
+ v4: FUTURE_V4_SCHEMA,
174
191
  experimental_faster: FASTER_CONFIG_SCHEMA,
175
192
  experimental_storage: STORAGE_CONFIG_SCHEMA,
176
193
  experimental_router: utils_validation_1.Joi.string()
package/lib/ssg/ssg.js CHANGED
@@ -141,6 +141,7 @@ async function generateStaticFile({ pathname, renderer, params, htmlMinifier, ss
141
141
  // This only renders the app HTML
142
142
  const result = await renderer.render({
143
143
  pathname,
144
+ v4RemoveLegacyPostBuildHeadAttribute: params.v4RemoveLegacyPostBuildHeadAttribute,
144
145
  });
145
146
  // This renders the full page HTML, including head tags...
146
147
  const fullPageHtml = (0, ssgTemplate_1.renderSSGTemplate)({
@@ -20,6 +20,7 @@ export type SSGParams = {
20
20
  htmlMinifierType: HtmlMinifierType;
21
21
  serverBundlePath: string;
22
22
  ssgTemplateContent: string;
23
+ v4RemoveLegacyPostBuildHeadAttribute: boolean;
23
24
  };
24
25
  export declare function createSSGParams({ props, serverBundlePath, clientManifestPath, }: {
25
26
  props: Props;
@@ -30,6 +30,7 @@ async function createSSGParams({ props, serverBundlePath, clientManifestPath, })
30
30
  .swcHtmlMinimizer
31
31
  ? 'swc'
32
32
  : 'terser',
33
+ v4RemoveLegacyPostBuildHeadAttribute: props.siteConfig.future.v4.removeLegacyPostBuildHeadAttribute,
33
34
  };
34
35
  // Useless but ensures that SSG params remain serializable
35
36
  return structuredClone(params);
@@ -35,15 +35,14 @@ function getScriptsAndStylesheets({ modules, manifest, }) {
35
35
  }
36
36
  function renderSSGTemplate({ params, result, ssgTemplate, }) {
37
37
  const { baseUrl, headTags, preBodyTags, postBodyTags, manifest, noIndex, DOCUSAURUS_VERSION, } = params;
38
- const { html: appHtml, collectedData: { modules, helmet }, } = result;
38
+ const { html: appHtml, collectedData: { modules, metadata }, } = result;
39
39
  const { scripts, stylesheets } = getScriptsAndStylesheets({ manifest, modules });
40
- const htmlAttributes = helmet.htmlAttributes.toString();
41
- const bodyAttributes = helmet.bodyAttributes.toString();
40
+ const { htmlAttributes, bodyAttributes } = metadata.internal;
42
41
  const metaStrings = [
43
- helmet.title.toString(),
44
- helmet.meta.toString(),
45
- helmet.link.toString(),
46
- helmet.script.toString(),
42
+ metadata.internal.title,
43
+ metadata.internal.meta,
44
+ metadata.internal.link,
45
+ metadata.internal.script,
47
46
  ];
48
47
  const metaAttributes = metaStrings.filter(Boolean);
49
48
  const data = {
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": "3.7.0-canary-6200",
4
+ "version": "3.7.0-canary-6201",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -33,13 +33,13 @@
33
33
  "url": "https://github.com/facebook/docusaurus/issues"
34
34
  },
35
35
  "dependencies": {
36
- "@docusaurus/babel": "3.7.0-canary-6200",
37
- "@docusaurus/bundler": "3.7.0-canary-6200",
38
- "@docusaurus/logger": "3.7.0-canary-6200",
39
- "@docusaurus/mdx-loader": "3.7.0-canary-6200",
40
- "@docusaurus/utils": "3.7.0-canary-6200",
41
- "@docusaurus/utils-common": "3.7.0-canary-6200",
42
- "@docusaurus/utils-validation": "3.7.0-canary-6200",
36
+ "@docusaurus/babel": "3.7.0-canary-6201",
37
+ "@docusaurus/bundler": "3.7.0-canary-6201",
38
+ "@docusaurus/logger": "3.7.0-canary-6201",
39
+ "@docusaurus/mdx-loader": "3.7.0-canary-6201",
40
+ "@docusaurus/utils": "3.7.0-canary-6201",
41
+ "@docusaurus/utils-common": "3.7.0-canary-6201",
42
+ "@docusaurus/utils-validation": "3.7.0-canary-6201",
43
43
  "boxen": "^6.2.1",
44
44
  "chalk": "^4.1.2",
45
45
  "chokidar": "^3.5.3",
@@ -77,8 +77,8 @@
77
77
  "webpack-merge": "^6.0.1"
78
78
  },
79
79
  "devDependencies": {
80
- "@docusaurus/module-type-aliases": "3.7.0-canary-6200",
81
- "@docusaurus/types": "3.7.0-canary-6200",
80
+ "@docusaurus/module-type-aliases": "3.7.0-canary-6201",
81
+ "@docusaurus/types": "3.7.0-canary-6201",
82
82
  "@total-typescript/shoehorn": "^0.1.2",
83
83
  "@types/detect-port": "^1.3.3",
84
84
  "@types/react-dom": "^18.2.7",
@@ -98,5 +98,5 @@
98
98
  "engines": {
99
99
  "node": ">=18.0"
100
100
  },
101
- "gitHead": "0fcaaf4f7747ba0367cf5474089365fd0ec0455f"
101
+ "gitHead": "a725f9f911c011198014536ce5d7049d0cefd46d"
102
102
  }