@docusaurus/core 0.0.0-5934 → 0.0.0-5938

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.
@@ -4,7 +4,7 @@
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
- import type { CodeTranslations, DocusaurusConfig, GlobalData, I18n, PluginRouteConfig, SiteMetadata } from '@docusaurus/types';
7
+ import type { CodeTranslations, DocusaurusConfig, GlobalData, I18n, PluginRouteConfig, SiteMetadata, SiteStorage } from '@docusaurus/types';
8
8
  type CodegenParams = {
9
9
  generatedFilesDir: string;
10
10
  siteConfig: DocusaurusConfig;
@@ -14,6 +14,7 @@ type CodegenParams = {
14
14
  i18n: I18n;
15
15
  codeTranslations: CodeTranslations;
16
16
  siteMetadata: SiteMetadata;
17
+ siteStorage: SiteStorage;
17
18
  routes: PluginRouteConfig[];
18
19
  };
19
20
  export declare function generateSiteFiles(params: CodegenParams): Promise<void>;
@@ -50,6 +50,9 @@ function genCodeTranslations({ generatedFilesDir, codeTranslations, }) {
50
50
  function genSiteMetadata({ generatedFilesDir, siteMetadata, }) {
51
51
  return (0, utils_1.generate)(generatedFilesDir, 'site-metadata.json', JSON.stringify(siteMetadata, null, 2));
52
52
  }
53
+ function genSiteStorage({ generatedFilesDir, siteStorage, }) {
54
+ return (0, utils_1.generate)(generatedFilesDir, 'site-storage.json', JSON.stringify(siteStorage, null, 2));
55
+ }
53
56
  async function generateSiteFiles(params) {
54
57
  await Promise.all([
55
58
  genWarning(params),
@@ -58,6 +61,7 @@ async function generateSiteFiles(params) {
58
61
  (0, codegenRoutes_1.generateRouteFiles)(params),
59
62
  genGlobalData(params),
60
63
  genSiteMetadata(params),
64
+ genSiteStorage(params),
61
65
  genI18n(params),
62
66
  genCodeTranslations(params),
63
67
  ]);
@@ -5,9 +5,12 @@
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 { FutureConfig, StorageConfig } from '@docusaurus/types/src/config';
8
9
  import type { DocusaurusConfig, I18nConfig, MarkdownConfig } from '@docusaurus/types';
9
10
  export declare const DEFAULT_I18N_CONFIG: I18nConfig;
11
+ export declare const DEFAULT_STORAGE_CONFIG: StorageConfig;
12
+ export declare const DEFAULT_FUTURE_CONFIG: FutureConfig;
10
13
  export declare const DEFAULT_MARKDOWN_CONFIG: MarkdownConfig;
11
- export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenAnchors' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'headTags' | 'stylesheets' | 'scripts' | 'clientModules' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'tagline' | 'baseUrlIssueBanner' | 'staticDirectories' | 'markdown'>;
14
+ 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'>;
12
15
  export declare const ConfigSchema: Joi.ObjectSchema<DocusaurusConfig>;
13
16
  export declare function validateConfig(config: unknown, siteConfigPath: string): DocusaurusConfig;
@@ -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.validateConfig = exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
9
+ exports.validateConfig = exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
10
10
  const utils_1 = require("@docusaurus/utils");
11
11
  const utils_validation_1 = require("@docusaurus/utils-validation");
12
12
  const utils_common_1 = require("@docusaurus/utils-common");
@@ -17,6 +17,13 @@ exports.DEFAULT_I18N_CONFIG = {
17
17
  locales: [DEFAULT_I18N_LOCALE],
18
18
  localeConfigs: {},
19
19
  };
20
+ exports.DEFAULT_STORAGE_CONFIG = {
21
+ type: 'localStorage',
22
+ namespace: false,
23
+ };
24
+ exports.DEFAULT_FUTURE_CONFIG = {
25
+ experimental_storage: exports.DEFAULT_STORAGE_CONFIG,
26
+ };
20
27
  exports.DEFAULT_MARKDOWN_CONFIG = {
21
28
  format: 'mdx', // TODO change this to "detect" in Docusaurus v4?
22
29
  mermaid: false,
@@ -34,6 +41,7 @@ exports.DEFAULT_MARKDOWN_CONFIG = {
34
41
  };
35
42
  exports.DEFAULT_CONFIG = {
36
43
  i18n: exports.DEFAULT_I18N_CONFIG,
44
+ future: exports.DEFAULT_FUTURE_CONFIG,
37
45
  onBrokenLinks: 'throw',
38
46
  onBrokenAnchors: 'warn', // TODO Docusaurus v4: change to throw
39
47
  onBrokenMarkdownLinks: 'warn',
@@ -120,6 +128,21 @@ const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
120
128
  })
121
129
  .optional()
122
130
  .default(exports.DEFAULT_I18N_CONFIG);
131
+ const STORAGE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
132
+ type: utils_validation_1.Joi.string()
133
+ .equal('localStorage', 'sessionStorage')
134
+ .default(exports.DEFAULT_STORAGE_CONFIG.type),
135
+ namespace: utils_validation_1.Joi.alternatives()
136
+ .try(utils_validation_1.Joi.string(), utils_validation_1.Joi.boolean())
137
+ .default(exports.DEFAULT_STORAGE_CONFIG.namespace),
138
+ })
139
+ .optional()
140
+ .default(exports.DEFAULT_STORAGE_CONFIG);
141
+ const FUTURE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
142
+ experimental_storage: STORAGE_CONFIG_SCHEMA,
143
+ })
144
+ .optional()
145
+ .default(exports.DEFAULT_FUTURE_CONFIG);
123
146
  const SiteUrlSchema = utils_validation_1.Joi.string()
124
147
  .required()
125
148
  .custom((value, helpers) => {
@@ -152,6 +175,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
152
175
  url: SiteUrlSchema,
153
176
  trailingSlash: utils_validation_1.Joi.boolean(), // No default value! undefined = retrocompatible legacy behavior!
154
177
  i18n: I18N_CONFIG_SCHEMA,
178
+ future: FUTURE_CONFIG_SCHEMA,
155
179
  onBrokenLinks: utils_validation_1.Joi.string()
156
180
  .equal('ignore', 'log', 'warn', 'throw')
157
181
  .default(exports.DEFAULT_CONFIG.onBrokenLinks),
@@ -10,8 +10,32 @@ exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
12
  const rtl_detect_1 = require("rtl-detect");
13
+ function inferLanguageDisplayName(locale) {
14
+ const tryLocale = (l) => {
15
+ try {
16
+ return new Intl.DisplayNames(l, {
17
+ type: 'language',
18
+ fallback: 'code',
19
+ }).of(l);
20
+ }
21
+ catch (e) {
22
+ // This is to compensate "of()" that is a bit strict
23
+ // Looks like starting Node 22, this locale throws: "en-US-u-ca-buddhist"
24
+ // RangeError: invalid_argument
25
+ return null;
26
+ }
27
+ };
28
+ const parts = locale.split('-');
29
+ // This is a best effort, we try various locale forms that could give a result
30
+ return (tryLocale(locale) ??
31
+ tryLocale(`${parts[0]}-${parts[1]}`) ??
32
+ tryLocale(parts[0]));
33
+ }
13
34
  function getDefaultLocaleLabel(locale) {
14
- const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
35
+ const languageName = inferLanguageDisplayName(locale);
36
+ if (!languageName) {
37
+ return locale;
38
+ }
15
39
  return (languageName.charAt(0).toLocaleUpperCase(locale) + languageName.substring(1));
16
40
  }
17
41
  function getDefaultCalendar(localeStr) {
@@ -34,13 +58,18 @@ function getDefaultCalendar(localeStr) {
34
58
  return 'gregory';
35
59
  }
36
60
  function getDefaultLocaleConfig(locale) {
37
- return {
38
- label: getDefaultLocaleLabel(locale),
39
- direction: (0, rtl_detect_1.getLangDir)(locale),
40
- htmlLang: locale,
41
- calendar: getDefaultCalendar(locale),
42
- path: locale,
43
- };
61
+ try {
62
+ return {
63
+ label: getDefaultLocaleLabel(locale),
64
+ direction: (0, rtl_detect_1.getLangDir)(locale),
65
+ htmlLang: locale,
66
+ calendar: getDefaultCalendar(locale),
67
+ path: locale,
68
+ };
69
+ }
70
+ catch (e) {
71
+ throw new Error(`Docusaurus couldn't get default locale config for ${locale}`, { cause: e });
72
+ }
44
73
  }
45
74
  exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
46
75
  async function loadI18n(config, options) {
@@ -21,6 +21,7 @@ const translations_1 = require("./translations/translations");
21
21
  const utils_2 = require("../utils");
22
22
  const codegen_1 = require("./codegen/codegen");
23
23
  const routes_1 = require("./routes");
24
+ const storage_1 = require("./storage");
24
25
  /**
25
26
  * Loading context is the very first step in site building. Its params are
26
27
  * directly acquired from CLI options. It mainly loads `siteConfig` and the i18n
@@ -53,9 +54,11 @@ async function loadContext(params) {
53
54
  const localizationDir = path_1.default.resolve(siteDir, i18n.path, i18n.localeConfigs[i18n.currentLocale].path);
54
55
  const siteConfig = { ...initialSiteConfig, baseUrl };
55
56
  const codeTranslations = await (0, translations_1.loadSiteCodeTranslations)({ localizationDir });
57
+ const siteStorage = (0, storage_1.createSiteStorage)(siteConfig);
56
58
  return {
57
59
  siteDir,
58
60
  siteVersion,
61
+ siteStorage,
59
62
  generatedFilesDir,
60
63
  localizationDir,
61
64
  siteConfig,
@@ -69,7 +72,7 @@ async function loadContext(params) {
69
72
  exports.loadContext = loadContext;
70
73
  function createSiteProps(params) {
71
74
  const { plugins, routes, context } = params;
72
- const { generatedFilesDir, siteDir, siteVersion, siteConfig, siteConfigPath, outDir, baseUrl, i18n, localizationDir, codeTranslations: siteCodeTranslations, } = context;
75
+ const { generatedFilesDir, siteDir, siteVersion, siteConfig, siteConfigPath, siteStorage, outDir, baseUrl, i18n, localizationDir, codeTranslations: siteCodeTranslations, } = context;
73
76
  const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)(plugins);
74
77
  const siteMetadata = (0, siteMetadata_1.createSiteMetadata)({ plugins, siteVersion });
75
78
  const codeTranslations = {
@@ -83,6 +86,7 @@ function createSiteProps(params) {
83
86
  siteConfigPath,
84
87
  siteMetadata,
85
88
  siteVersion,
89
+ siteStorage,
86
90
  siteDir,
87
91
  outDir,
88
92
  baseUrl,
@@ -101,13 +105,14 @@ function createSiteProps(params) {
101
105
  // TODO global data should be part of site props?
102
106
  async function createSiteFiles({ site, globalData, }) {
103
107
  return utils_2.PerfLogger.async('Create site files', async () => {
104
- const { props: { plugins, generatedFilesDir, siteConfig, siteMetadata, i18n, codeTranslations, routes, baseUrl, }, } = site;
108
+ const { props: { plugins, generatedFilesDir, siteConfig, siteMetadata, siteStorage, i18n, codeTranslations, routes, baseUrl, }, } = site;
105
109
  const clientModules = (0, clientModules_1.getAllClientModules)(plugins);
106
110
  await (0, codegen_1.generateSiteFiles)({
107
111
  generatedFilesDir,
108
112
  clientModules,
109
113
  siteConfig,
110
114
  siteMetadata,
115
+ siteStorage,
111
116
  i18n,
112
117
  codeTranslations,
113
118
  globalData,
@@ -125,7 +130,7 @@ async function createSiteFiles({ site, globalData, }) {
125
130
  async function loadSite(params) {
126
131
  const context = await utils_2.PerfLogger.async('Load context', () => loadContext(params));
127
132
  const { plugins, routes, globalData } = await (0, plugins_1.loadPlugins)(context);
128
- const props = await createSiteProps({ plugins, routes, globalData, context });
133
+ const props = createSiteProps({ plugins, routes, globalData, context });
129
134
  const site = { props, params };
130
135
  await createSiteFiles({
131
136
  site,
@@ -147,7 +152,7 @@ async function reloadSitePlugin(site, pluginIdentifier) {
147
152
  plugins: site.props.plugins,
148
153
  context: site.props,
149
154
  });
150
- const newProps = await createSiteProps({
155
+ const newProps = createSiteProps({
151
156
  plugins,
152
157
  routes,
153
158
  globalData,
@@ -0,0 +1,13 @@
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 { DocusaurusConfig, SiteStorage } from '@docusaurus/types';
8
+ type PartialFuture = Pick<DocusaurusConfig['future'], 'experimental_storage'>;
9
+ type PartialConfig = Pick<DocusaurusConfig, 'url' | 'baseUrl'> & {
10
+ future: PartialFuture;
11
+ };
12
+ export declare function createSiteStorage(config: PartialConfig): SiteStorage;
13
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createSiteStorage = void 0;
10
+ const utils_1 = require("@docusaurus/utils");
11
+ const utils_common_1 = require("@docusaurus/utils-common");
12
+ function automaticNamespace(config) {
13
+ const normalizedUrl = (0, utils_common_1.addTrailingSlash)((0, utils_1.normalizeUrl)([config.url, config.baseUrl]));
14
+ return (0, utils_1.simpleHash)(normalizedUrl, 3);
15
+ }
16
+ function getNamespaceString(config) {
17
+ if (config.future.experimental_storage.namespace === true) {
18
+ return automaticNamespace(config);
19
+ }
20
+ else if (config.future.experimental_storage.namespace === false) {
21
+ return null;
22
+ }
23
+ else {
24
+ return config.future.experimental_storage.namespace;
25
+ }
26
+ }
27
+ function createSiteStorage(config) {
28
+ const { type } = config.future.experimental_storage;
29
+ const namespaceString = getNamespaceString(config);
30
+ const namespace = namespaceString ? `-${namespaceString}` : '';
31
+ return {
32
+ type,
33
+ namespace,
34
+ };
35
+ }
36
+ exports.createSiteStorage = createSiteStorage;
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-5934",
4
+ "version": "0.0.0-5938",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -43,12 +43,12 @@
43
43
  "@babel/runtime": "^7.22.6",
44
44
  "@babel/runtime-corejs3": "^7.22.6",
45
45
  "@babel/traverse": "^7.22.8",
46
- "@docusaurus/cssnano-preset": "0.0.0-5934",
47
- "@docusaurus/logger": "0.0.0-5934",
48
- "@docusaurus/mdx-loader": "0.0.0-5934",
49
- "@docusaurus/utils": "0.0.0-5934",
50
- "@docusaurus/utils-common": "0.0.0-5934",
51
- "@docusaurus/utils-validation": "0.0.0-5934",
46
+ "@docusaurus/cssnano-preset": "0.0.0-5938",
47
+ "@docusaurus/logger": "0.0.0-5938",
48
+ "@docusaurus/mdx-loader": "0.0.0-5938",
49
+ "@docusaurus/utils": "0.0.0-5938",
50
+ "@docusaurus/utils-common": "0.0.0-5938",
51
+ "@docusaurus/utils-validation": "0.0.0-5938",
52
52
  "autoprefixer": "^10.4.14",
53
53
  "babel-loader": "^9.1.3",
54
54
  "babel-plugin-dynamic-import-node": "^2.3.3",
@@ -103,8 +103,8 @@
103
103
  "webpackbar": "^5.0.2"
104
104
  },
105
105
  "devDependencies": {
106
- "@docusaurus/module-type-aliases": "0.0.0-5934",
107
- "@docusaurus/types": "0.0.0-5934",
106
+ "@docusaurus/module-type-aliases": "0.0.0-5938",
107
+ "@docusaurus/types": "0.0.0-5938",
108
108
  "@total-typescript/shoehorn": "^0.1.2",
109
109
  "@types/detect-port": "^1.3.3",
110
110
  "@types/react-dom": "^18.2.7",
@@ -124,5 +124,5 @@
124
124
  "engines": {
125
125
  "node": ">=18.0"
126
126
  },
127
- "gitHead": "e5fc3801fc9b646c2dbaab6ae024a74344be0bb4"
127
+ "gitHead": "05801ec2481c5f73abb6085e50dda53aa70bbac9"
128
128
  }