@docusaurus/plugin-content-docs 0.0.0-5865 → 0.0.0-5868

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.
package/lib/docs.js CHANGED
@@ -12,42 +12,10 @@ const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
13
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
- const lastUpdate_1 = require("./lastUpdate");
15
+ const frontMatter_1 = require("./frontMatter");
16
16
  const slug_1 = tslib_1.__importDefault(require("./slug"));
17
17
  const numberPrefix_1 = require("./numberPrefix");
18
- const frontMatter_1 = require("./frontMatter");
19
18
  const utils_2 = require("./sidebars/utils");
20
- async function readLastUpdateData(filePath, options, lastUpdateFrontMatter) {
21
- const { showLastUpdateAuthor, showLastUpdateTime } = options;
22
- if (showLastUpdateAuthor || showLastUpdateTime) {
23
- const frontMatterTimestamp = lastUpdateFrontMatter?.date
24
- ? new Date(lastUpdateFrontMatter.date).getTime() / 1000
25
- : undefined;
26
- if (lastUpdateFrontMatter?.author && lastUpdateFrontMatter.date) {
27
- return {
28
- lastUpdatedAt: frontMatterTimestamp,
29
- lastUpdatedBy: lastUpdateFrontMatter.author,
30
- };
31
- }
32
- // Use fake data in dev for faster development.
33
- const fileLastUpdateData = process.env.NODE_ENV === 'production'
34
- ? await (0, lastUpdate_1.getFileLastUpdate)(filePath)
35
- : {
36
- author: 'Author',
37
- timestamp: 1539502055,
38
- };
39
- const { author, timestamp } = fileLastUpdateData ?? {};
40
- return {
41
- lastUpdatedBy: showLastUpdateAuthor
42
- ? lastUpdateFrontMatter?.author ?? author
43
- : undefined,
44
- lastUpdatedAt: showLastUpdateTime
45
- ? frontMatterTimestamp ?? timestamp
46
- : undefined,
47
- };
48
- }
49
- return {};
50
- }
51
19
  async function readDocFile(versionMetadata, source) {
52
20
  const contentPath = await (0, utils_1.getFolderContainingFile)((0, utils_1.getContentPathList)(versionMetadata), source);
53
21
  const filePath = path_1.default.join(contentPath, source);
@@ -77,7 +45,7 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
77
45
  // (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc)
78
46
  // but allow to disable this behavior with front matter
79
47
  parse_number_prefixes: parseNumberPrefixes = true, last_update: lastUpdateFrontMatter, } = frontMatter;
80
- const lastUpdate = await readLastUpdateData(filePath, options, lastUpdateFrontMatter);
48
+ const lastUpdate = await (0, utils_1.readLastUpdateData)(filePath, options, lastUpdateFrontMatter);
81
49
  // E.g. api/plugins/myDoc -> myDoc; myDoc -> myDoc
82
50
  const sourceFileNameWithoutExtension = path_1.default.basename(source, path_1.default.extname(source));
83
51
  // E.g. api/plugins/myDoc -> api/plugins; myDoc -> .
@@ -1,10 +1,5 @@
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
1
  import type { DocFrontMatter } from '@docusaurus/plugin-content-docs';
2
+ export declare const DocFrontMatterSchema: import("joi").ObjectSchema<DocFrontMatter>;
8
3
  export declare function validateDocFrontMatter(frontMatter: {
9
4
  [key: string]: unknown;
10
5
  }): DocFrontMatter;
@@ -1,19 +1,18 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateDocFrontMatter = exports.DocFrontMatterSchema = void 0;
2
4
  /**
3
5
  * Copyright (c) Facebook, Inc. and its affiliates.
4
6
  *
5
7
  * This source code is licensed under the MIT license found in the
6
8
  * LICENSE file in the root directory of this source tree.
7
9
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.validateDocFrontMatter = void 0;
10
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
- const FrontMatterLastUpdateErrorMessage = '{{#label}} does not look like a valid front matter FileChange object. Please use a FileChange object (with an author and/or date).';
12
11
  // NOTE: we don't add any default value on purpose here
13
12
  // We don't want default values to magically appear in doc metadata and props
14
13
  // While the user did not provide those values explicitly
15
14
  // We use default values in code instead
16
- const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
15
+ exports.DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
17
16
  id: utils_validation_1.JoiFrontMatter.string(),
18
17
  // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
19
18
  title: utils_validation_1.JoiFrontMatter.string().allow(''),
@@ -36,19 +35,11 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
36
35
  pagination_next: utils_validation_1.JoiFrontMatter.string().allow(null),
37
36
  pagination_prev: utils_validation_1.JoiFrontMatter.string().allow(null),
38
37
  ...utils_validation_1.FrontMatterTOCHeadingLevels,
39
- last_update: utils_validation_1.JoiFrontMatter.object({
40
- author: utils_validation_1.JoiFrontMatter.string(),
41
- date: utils_validation_1.JoiFrontMatter.date().raw(),
42
- })
43
- .or('author', 'date')
44
- .messages({
45
- 'object.missing': FrontMatterLastUpdateErrorMessage,
46
- 'object.base': FrontMatterLastUpdateErrorMessage,
47
- }),
38
+ last_update: utils_validation_1.FrontMatterLastUpdateSchema,
48
39
  })
49
40
  .unknown()
50
41
  .concat(utils_validation_1.ContentVisibilitySchema);
51
42
  function validateDocFrontMatter(frontMatter) {
52
- return (0, utils_validation_1.validateFrontMatter)(frontMatter, DocFrontMatterSchema);
43
+ return (0, utils_validation_1.validateFrontMatter)(frontMatter, exports.DocFrontMatterSchema);
53
44
  }
54
45
  exports.validateDocFrontMatter = validateDocFrontMatter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-5865",
3
+ "version": "0.0.0-5868",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -35,13 +35,13 @@
35
35
  },
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@docusaurus/core": "0.0.0-5865",
39
- "@docusaurus/logger": "0.0.0-5865",
40
- "@docusaurus/mdx-loader": "0.0.0-5865",
41
- "@docusaurus/module-type-aliases": "0.0.0-5865",
42
- "@docusaurus/types": "0.0.0-5865",
43
- "@docusaurus/utils": "0.0.0-5865",
44
- "@docusaurus/utils-validation": "0.0.0-5865",
38
+ "@docusaurus/core": "0.0.0-5868",
39
+ "@docusaurus/logger": "0.0.0-5868",
40
+ "@docusaurus/mdx-loader": "0.0.0-5868",
41
+ "@docusaurus/module-type-aliases": "0.0.0-5868",
42
+ "@docusaurus/types": "0.0.0-5868",
43
+ "@docusaurus/utils": "0.0.0-5868",
44
+ "@docusaurus/utils-validation": "0.0.0-5868",
45
45
  "@types/react-router-config": "^5.0.7",
46
46
  "combine-promises": "^1.1.0",
47
47
  "fs-extra": "^11.1.1",
@@ -65,5 +65,5 @@
65
65
  "engines": {
66
66
  "node": ">=18.0"
67
67
  },
68
- "gitHead": "0ce2912136d682daeb3abe9d1284a49f9c011efa"
68
+ "gitHead": "82bedf4154c3c66e27563a6735763c5b08518820"
69
69
  }
package/src/docs.ts CHANGED
@@ -20,12 +20,11 @@ import {
20
20
  normalizeFrontMatterTags,
21
21
  isUnlisted,
22
22
  isDraft,
23
+ readLastUpdateData,
23
24
  } from '@docusaurus/utils';
24
-
25
- import {getFileLastUpdate} from './lastUpdate';
25
+ import {validateDocFrontMatter} from './frontMatter';
26
26
  import getSlug from './slug';
27
27
  import {stripPathNumberPrefixes} from './numberPrefix';
28
- import {validateDocFrontMatter} from './frontMatter';
29
28
  import {toDocNavigationLink, toNavigationLink} from './sidebars/utils';
30
29
  import type {
31
30
  MetadataOptions,
@@ -34,61 +33,13 @@ import type {
34
33
  DocMetadataBase,
35
34
  DocMetadata,
36
35
  PropNavigationLink,
37
- LastUpdateData,
38
36
  VersionMetadata,
39
37
  LoadedVersion,
40
- FileChange,
41
38
  } from '@docusaurus/plugin-content-docs';
42
39
  import type {LoadContext} from '@docusaurus/types';
43
40
  import type {SidebarsUtils} from './sidebars/utils';
44
41
  import type {DocFile} from './types';
45
42
 
46
- type LastUpdateOptions = Pick<
47
- PluginOptions,
48
- 'showLastUpdateAuthor' | 'showLastUpdateTime'
49
- >;
50
-
51
- async function readLastUpdateData(
52
- filePath: string,
53
- options: LastUpdateOptions,
54
- lastUpdateFrontMatter: FileChange | undefined,
55
- ): Promise<LastUpdateData> {
56
- const {showLastUpdateAuthor, showLastUpdateTime} = options;
57
- if (showLastUpdateAuthor || showLastUpdateTime) {
58
- const frontMatterTimestamp = lastUpdateFrontMatter?.date
59
- ? new Date(lastUpdateFrontMatter.date).getTime() / 1000
60
- : undefined;
61
-
62
- if (lastUpdateFrontMatter?.author && lastUpdateFrontMatter.date) {
63
- return {
64
- lastUpdatedAt: frontMatterTimestamp,
65
- lastUpdatedBy: lastUpdateFrontMatter.author,
66
- };
67
- }
68
-
69
- // Use fake data in dev for faster development.
70
- const fileLastUpdateData =
71
- process.env.NODE_ENV === 'production'
72
- ? await getFileLastUpdate(filePath)
73
- : {
74
- author: 'Author',
75
- timestamp: 1539502055,
76
- };
77
- const {author, timestamp} = fileLastUpdateData ?? {};
78
-
79
- return {
80
- lastUpdatedBy: showLastUpdateAuthor
81
- ? lastUpdateFrontMatter?.author ?? author
82
- : undefined,
83
- lastUpdatedAt: showLastUpdateTime
84
- ? frontMatterTimestamp ?? timestamp
85
- : undefined,
86
- };
87
- }
88
-
89
- return {};
90
- }
91
-
92
43
  export async function readDocFile(
93
44
  versionMetadata: Pick<
94
45
  VersionMetadata,
@@ -4,7 +4,6 @@
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
7
  import {
9
8
  JoiFrontMatter as Joi, // Custom instance for front matter
10
9
  URISchema,
@@ -12,17 +11,15 @@ import {
12
11
  FrontMatterTOCHeadingLevels,
13
12
  validateFrontMatter,
14
13
  ContentVisibilitySchema,
14
+ FrontMatterLastUpdateSchema,
15
15
  } from '@docusaurus/utils-validation';
16
16
  import type {DocFrontMatter} from '@docusaurus/plugin-content-docs';
17
17
 
18
- const FrontMatterLastUpdateErrorMessage =
19
- '{{#label}} does not look like a valid front matter FileChange object. Please use a FileChange object (with an author and/or date).';
20
-
21
18
  // NOTE: we don't add any default value on purpose here
22
19
  // We don't want default values to magically appear in doc metadata and props
23
20
  // While the user did not provide those values explicitly
24
21
  // We use default values in code instead
25
- const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
22
+ export const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
26
23
  id: Joi.string(),
27
24
  // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
28
25
  title: Joi.string().allow(''),
@@ -45,15 +42,7 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
45
42
  pagination_next: Joi.string().allow(null),
46
43
  pagination_prev: Joi.string().allow(null),
47
44
  ...FrontMatterTOCHeadingLevels,
48
- last_update: Joi.object({
49
- author: Joi.string(),
50
- date: Joi.date().raw(),
51
- })
52
- .or('author', 'date')
53
- .messages({
54
- 'object.missing': FrontMatterLastUpdateErrorMessage,
55
- 'object.base': FrontMatterLastUpdateErrorMessage,
56
- }),
45
+ last_update: FrontMatterLastUpdateSchema,
57
46
  })
58
47
  .unknown()
59
48
  .concat(ContentVisibilitySchema);
@@ -16,6 +16,7 @@ declare module '@docusaurus/plugin-content-docs' {
16
16
  TagsListItem,
17
17
  TagModule,
18
18
  Tag,
19
+ FrontMatterLastUpdate,
19
20
  } from '@docusaurus/utils';
20
21
  import type {Plugin, LoadContext} from '@docusaurus/types';
21
22
  import type {Overwrite, Required} from 'utility-types';
@@ -24,14 +25,6 @@ declare module '@docusaurus/plugin-content-docs' {
24
25
  image?: string;
25
26
  };
26
27
 
27
- export type FileChange = {
28
- author?: string;
29
- /** Date can be any
30
- * [parsable date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).
31
- */
32
- date?: Date | string;
33
- };
34
-
35
28
  /**
36
29
  * Custom callback for parsing number prefixes from file/folder names.
37
30
  */
@@ -93,9 +86,9 @@ declare module '@docusaurus/plugin-content-docs' {
93
86
  */
94
87
  editLocalizedFiles: boolean;
95
88
  /** Whether to display the last date the doc was updated. */
96
- showLastUpdateTime?: boolean;
89
+ showLastUpdateTime: boolean;
97
90
  /** Whether to display the author who last updated the doc. */
98
- showLastUpdateAuthor?: boolean;
91
+ showLastUpdateAuthor: boolean;
99
92
  /**
100
93
  * Custom parsing logic to extract number prefixes from file names. Use
101
94
  * `false` to disable this behavior and leave the docs untouched, and `true`
@@ -401,7 +394,7 @@ declare module '@docusaurus/plugin-content-docs' {
401
394
  /** Should this doc be accessible but hidden in production builds? */
402
395
  unlisted?: boolean;
403
396
  /** Allows overriding the last updated author and/or date. */
404
- last_update?: FileChange;
397
+ last_update?: FrontMatterLastUpdate;
405
398
  };
406
399
 
407
400
  export type LastUpdateData = {
@@ -1,10 +0,0 @@
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
- export declare function getFileLastUpdate(filePath: string): Promise<{
8
- timestamp: number;
9
- author: string;
10
- } | null>;
package/lib/lastUpdate.js DELETED
@@ -1,47 +0,0 @@
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.getFileLastUpdate = void 0;
10
- const tslib_1 = require("tslib");
11
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
- const utils_1 = require("@docusaurus/utils");
13
- let showedGitRequirementError = false;
14
- let showedFileNotTrackedError = false;
15
- async function getFileLastUpdate(filePath) {
16
- if (!filePath) {
17
- return null;
18
- }
19
- // Wrap in try/catch in case the shell commands fail
20
- // (e.g. project doesn't use Git, etc).
21
- try {
22
- const result = await (0, utils_1.getFileCommitDate)(filePath, {
23
- age: 'newest',
24
- includeAuthor: true,
25
- });
26
- return { timestamp: result.timestamp, author: result.author };
27
- }
28
- catch (err) {
29
- if (err instanceof utils_1.GitNotFoundError) {
30
- if (!showedGitRequirementError) {
31
- logger_1.default.warn('Sorry, the docs plugin last update options require Git.');
32
- showedGitRequirementError = true;
33
- }
34
- }
35
- else if (err instanceof utils_1.FileNotTrackedError) {
36
- if (!showedFileNotTrackedError) {
37
- logger_1.default.warn('Cannot infer the update date for some files, as they are not tracked by git.');
38
- showedFileNotTrackedError = true;
39
- }
40
- }
41
- else {
42
- logger_1.default.warn(err);
43
- }
44
- return null;
45
- }
46
- }
47
- exports.getFileLastUpdate = getFileLastUpdate;
package/src/lastUpdate.ts DELETED
@@ -1,52 +0,0 @@
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
-
8
- import logger from '@docusaurus/logger';
9
- import {
10
- getFileCommitDate,
11
- FileNotTrackedError,
12
- GitNotFoundError,
13
- } from '@docusaurus/utils';
14
-
15
- let showedGitRequirementError = false;
16
- let showedFileNotTrackedError = false;
17
-
18
- export async function getFileLastUpdate(
19
- filePath: string,
20
- ): Promise<{timestamp: number; author: string} | null> {
21
- if (!filePath) {
22
- return null;
23
- }
24
-
25
- // Wrap in try/catch in case the shell commands fail
26
- // (e.g. project doesn't use Git, etc).
27
- try {
28
- const result = await getFileCommitDate(filePath, {
29
- age: 'newest',
30
- includeAuthor: true,
31
- });
32
-
33
- return {timestamp: result.timestamp, author: result.author};
34
- } catch (err) {
35
- if (err instanceof GitNotFoundError) {
36
- if (!showedGitRequirementError) {
37
- logger.warn('Sorry, the docs plugin last update options require Git.');
38
- showedGitRequirementError = true;
39
- }
40
- } else if (err instanceof FileNotTrackedError) {
41
- if (!showedFileNotTrackedError) {
42
- logger.warn(
43
- 'Cannot infer the update date for some files, as they are not tracked by git.',
44
- );
45
- showedFileNotTrackedError = true;
46
- }
47
- } else {
48
- logger.warn(err);
49
- }
50
- return null;
51
- }
52
- }