@docusaurus/plugin-content-docs 0.0.0-4562 → 0.0.0-4567

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.
@@ -24,6 +24,7 @@ const DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
24
24
  sidebar_label: utils_validation_1.JoiFrontMatter.string(),
25
25
  sidebar_position: utils_validation_1.JoiFrontMatter.number(),
26
26
  sidebar_class_name: utils_validation_1.JoiFrontMatter.string(),
27
+ sidebar_custom_props: utils_validation_1.JoiFrontMatter.object().unknown(),
27
28
  displayed_sidebar: utils_validation_1.JoiFrontMatter.string().allow(null),
28
29
  tags: utils_validation_1.FrontMatterTagsSchema,
29
30
  pagination_label: utils_validation_1.JoiFrontMatter.string(),
package/lib/lastUpdate.js CHANGED
@@ -8,52 +8,31 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getFileLastUpdate = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const shelljs_1 = (0, tslib_1.__importDefault)(require("shelljs"));
12
11
  const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
13
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
14
- const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(?<timestamp>\d+),(?<author>.+)$/;
12
+ const utils_1 = require("@docusaurus/utils");
15
13
  let showedGitRequirementError = false;
16
14
  async function getFileLastUpdate(filePath) {
17
15
  if (!filePath) {
18
16
  return null;
19
17
  }
20
- function getTimestampAndAuthor(str) {
21
- var _a;
22
- if (!str) {
23
- return null;
24
- }
25
- const temp = (_a = str.match(GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX)) === null || _a === void 0 ? void 0 : _a.groups;
26
- return temp
27
- ? { timestamp: Number(temp.timestamp), author: temp.author }
28
- : null;
29
- }
30
18
  // Wrap in try/catch in case the shell commands fail
31
19
  // (e.g. project doesn't use Git, etc).
32
20
  try {
33
- if (!shelljs_1.default.which('git')) {
34
- if (!showedGitRequirementError) {
35
- showedGitRequirementError = true;
36
- logger_1.default.warn('Sorry, the docs plugin last update options require Git.');
37
- }
38
- return null;
39
- }
40
- if (!shelljs_1.default.test('-f', filePath)) {
41
- throw new Error(`Retrieval of git history failed at "${filePath}" because the file does not exist.`);
42
- }
43
- const fileBasename = path_1.default.basename(filePath);
44
- const fileDirname = path_1.default.dirname(filePath);
45
- const result = shelljs_1.default.exec(`git log --max-count=1 --format=%ct,%an -- "${fileBasename}"`, {
46
- cwd: fileDirname,
47
- silent: true,
21
+ const result = (0, utils_1.getFileCommitDate)(filePath, {
22
+ age: 'newest',
23
+ includeAuthor: true,
48
24
  });
49
- if (result.code !== 0) {
50
- throw new Error(`Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`);
51
- }
52
- return getTimestampAndAuthor(result.stdout.trim());
25
+ return { timestamp: result.timestamp, author: result.author };
53
26
  }
54
27
  catch (e) {
55
- logger_1.default.error(e);
28
+ if (e instanceof utils_1.GitNotFoundError && !showedGitRequirementError) {
29
+ logger_1.default.warn('Sorry, the docs plugin last update options require Git.');
30
+ showedGitRequirementError = true;
31
+ }
32
+ else {
33
+ logger_1.default.error(e);
34
+ }
35
+ return null;
56
36
  }
57
- return null;
58
37
  }
59
38
  exports.getFileLastUpdate = getFileLastUpdate;
package/lib/props.js CHANGED
@@ -21,6 +21,7 @@ Available document ids are:
21
21
  return docMetadata;
22
22
  }
23
23
  const convertDocLink = (item) => {
24
+ var _a;
24
25
  const docMetadata = getDocById(item.id);
25
26
  const { title, permalink, frontMatter: { sidebar_label: sidebarLabel }, } = docMetadata;
26
27
  return {
@@ -28,7 +29,7 @@ Available document ids are:
28
29
  label: sidebarLabel || item.label || title,
29
30
  href: permalink,
30
31
  className: item.className,
31
- customProps: item.customProps,
32
+ customProps: (_a = item.customProps) !== null && _a !== void 0 ? _a : docMetadata.frontMatter.sidebar_custom_props,
32
33
  docId: docMetadata.unversionedId,
33
34
  };
34
35
  };
package/lib/types.d.ts CHANGED
@@ -47,6 +47,7 @@ export declare type DocFrontMatter = {
47
47
  sidebar_label?: string;
48
48
  sidebar_position?: number;
49
49
  sidebar_class_name?: string;
50
+ sidebar_custom_props?: Record<string, unknown>;
50
51
  displayed_sidebar?: string | null;
51
52
  pagination_label?: string;
52
53
  custom_edit_url?: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4562",
3
+ "version": "0.0.0-4567",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -23,30 +23,30 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@docusaurus/core": "0.0.0-4562",
27
- "@docusaurus/logger": "0.0.0-4562",
28
- "@docusaurus/mdx-loader": "0.0.0-4562",
29
- "@docusaurus/utils": "0.0.0-4562",
30
- "@docusaurus/utils-validation": "0.0.0-4562",
26
+ "@docusaurus/core": "0.0.0-4567",
27
+ "@docusaurus/logger": "0.0.0-4567",
28
+ "@docusaurus/mdx-loader": "0.0.0-4567",
29
+ "@docusaurus/utils": "0.0.0-4567",
30
+ "@docusaurus/utils-validation": "0.0.0-4567",
31
31
  "combine-promises": "^1.1.0",
32
32
  "fs-extra": "^10.0.0",
33
33
  "import-fresh": "^3.2.2",
34
34
  "js-yaml": "^4.0.0",
35
35
  "lodash": "^4.17.20",
36
36
  "remark-admonitions": "^1.2.1",
37
- "shelljs": "^0.8.4",
38
37
  "tslib": "^2.3.1",
39
38
  "utility-types": "^3.10.0",
40
39
  "webpack": "^5.68.0"
41
40
  },
42
41
  "devDependencies": {
43
- "@docusaurus/module-type-aliases": "0.0.0-4562",
44
- "@docusaurus/types": "0.0.0-4562",
42
+ "@docusaurus/module-type-aliases": "0.0.0-4567",
43
+ "@docusaurus/types": "0.0.0-4567",
45
44
  "@types/js-yaml": "^4.0.0",
46
45
  "@types/picomatch": "^2.2.1",
47
46
  "commander": "^5.1.0",
48
47
  "escape-string-regexp": "^4.0.0",
49
48
  "picomatch": "^2.1.1",
49
+ "shelljs": "^0.8.4",
50
50
  "utility-types": "^3.10.0"
51
51
  },
52
52
  "peerDependencies": {
@@ -56,5 +56,5 @@
56
56
  "engines": {
57
57
  "node": ">=14"
58
58
  },
59
- "gitHead": "dc4c1950adae154c00ca528229510f2c91222656"
59
+ "gitHead": "15e2d5d421b0ec0018e98853dd2958974e87c5c0"
60
60
  }
@@ -30,6 +30,7 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
30
30
  sidebar_label: Joi.string(),
31
31
  sidebar_position: Joi.number(),
32
32
  sidebar_class_name: Joi.string(),
33
+ sidebar_custom_props: Joi.object().unknown(),
33
34
  displayed_sidebar: Joi.string().allow(null),
34
35
  tags: FrontMatterTagsSchema,
35
36
  pagination_label: Joi.string(),
package/src/lastUpdate.ts CHANGED
@@ -5,14 +5,11 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import shell from 'shelljs';
9
8
  import logger from '@docusaurus/logger';
10
- import path from 'path';
9
+ import {getFileCommitDate, GitNotFoundError} from '@docusaurus/utils';
11
10
 
12
11
  type FileLastUpdateData = {timestamp?: number; author?: string};
13
12
 
14
- const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(?<timestamp>\d+),(?<author>.+)$/;
15
-
16
13
  let showedGitRequirementError = false;
17
14
 
18
15
  export async function getFileLastUpdate(
@@ -21,53 +18,22 @@ export async function getFileLastUpdate(
21
18
  if (!filePath) {
22
19
  return null;
23
20
  }
24
- function getTimestampAndAuthor(str: string): FileLastUpdateData | null {
25
- if (!str) {
26
- return null;
27
- }
28
-
29
- const temp = str.match(GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX)?.groups;
30
- return temp
31
- ? {timestamp: Number(temp.timestamp), author: temp.author}
32
- : null;
33
- }
34
21
 
35
22
  // Wrap in try/catch in case the shell commands fail
36
23
  // (e.g. project doesn't use Git, etc).
37
24
  try {
38
- if (!shell.which('git')) {
39
- if (!showedGitRequirementError) {
40
- showedGitRequirementError = true;
41
- logger.warn('Sorry, the docs plugin last update options require Git.');
42
- }
43
-
44
- return null;
45
- }
46
-
47
- if (!shell.test('-f', filePath)) {
48
- throw new Error(
49
- `Retrieval of git history failed at "${filePath}" because the file does not exist.`,
50
- );
51
- }
52
-
53
- const fileBasename = path.basename(filePath);
54
- const fileDirname = path.dirname(filePath);
55
- const result = shell.exec(
56
- `git log --max-count=1 --format=%ct,%an -- "${fileBasename}"`,
57
- {
58
- cwd: fileDirname, // this is needed: https://github.com/facebook/docusaurus/pull/5048
59
- silent: true,
60
- },
61
- );
62
- if (result.code !== 0) {
63
- throw new Error(
64
- `Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`,
65
- );
66
- }
67
- return getTimestampAndAuthor(result.stdout.trim());
25
+ const result = getFileCommitDate(filePath, {
26
+ age: 'newest',
27
+ includeAuthor: true,
28
+ });
29
+ return {timestamp: result.timestamp, author: result.author};
68
30
  } catch (e) {
69
- logger.error(e);
31
+ if (e instanceof GitNotFoundError && !showedGitRequirementError) {
32
+ logger.warn('Sorry, the docs plugin last update options require Git.');
33
+ showedGitRequirementError = true;
34
+ } else {
35
+ logger.error(e);
36
+ }
37
+ return null;
70
38
  }
71
-
72
- return null;
73
39
  }
package/src/props.ts CHANGED
@@ -52,7 +52,8 @@ Available document ids are:
52
52
  label: sidebarLabel || item.label || title,
53
53
  href: permalink,
54
54
  className: item.className,
55
- customProps: item.customProps,
55
+ customProps:
56
+ item.customProps ?? docMetadata.frontMatter.sidebar_custom_props,
56
57
  docId: docMetadata.unversionedId,
57
58
  };
58
59
  };
package/src/types.ts CHANGED
@@ -58,6 +58,7 @@ export type DocFrontMatter = {
58
58
  sidebar_label?: string;
59
59
  sidebar_position?: number;
60
60
  sidebar_class_name?: string;
61
+ sidebar_custom_props?: Record<string, unknown>;
61
62
  displayed_sidebar?: string | null;
62
63
  pagination_label?: string;
63
64
  custom_edit_url?: string | null;