@docusaurus/utils 2.0.0-beta.15d451942 → 2.0.0-beta.16

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.
Files changed (88) hide show
  1. package/README.md +1 -1
  2. package/lib/constants.d.ts +20 -0
  3. package/lib/constants.d.ts.map +1 -0
  4. package/lib/constants.js +27 -0
  5. package/lib/constants.js.map +1 -0
  6. package/lib/dataFileUtils.d.ts +24 -0
  7. package/lib/dataFileUtils.d.ts.map +1 -0
  8. package/lib/dataFileUtils.js +65 -0
  9. package/lib/dataFileUtils.js.map +1 -0
  10. package/lib/gitUtils.d.ts +17 -0
  11. package/lib/gitUtils.d.ts.map +1 -0
  12. package/lib/gitUtils.js +63 -0
  13. package/lib/gitUtils.js.map +1 -0
  14. package/lib/globUtils.d.ts +12 -0
  15. package/lib/globUtils.d.ts.map +1 -0
  16. package/lib/globUtils.js +48 -0
  17. package/lib/globUtils.js.map +1 -0
  18. package/lib/hashUtils.d.ts +16 -0
  19. package/lib/hashUtils.d.ts.map +1 -0
  20. package/lib/hashUtils.js +41 -0
  21. package/lib/hashUtils.js.map +1 -0
  22. package/lib/index.d.ts +30 -52
  23. package/lib/index.d.ts.map +1 -0
  24. package/lib/index.js +126 -247
  25. package/lib/index.js.map +1 -0
  26. package/lib/markdownLinks.d.ts +1 -0
  27. package/lib/markdownLinks.d.ts.map +1 -0
  28. package/lib/markdownLinks.js +36 -11
  29. package/lib/markdownLinks.js.map +1 -0
  30. package/lib/markdownParser.d.ts +7 -3
  31. package/lib/markdownParser.d.ts.map +1 -0
  32. package/lib/markdownParser.js +77 -48
  33. package/lib/markdownParser.js.map +1 -0
  34. package/lib/pathUtils.d.ts +51 -0
  35. package/lib/pathUtils.d.ts.map +1 -0
  36. package/lib/pathUtils.js +106 -0
  37. package/lib/pathUtils.js.map +1 -0
  38. package/lib/slugger.d.ts +14 -0
  39. package/lib/slugger.d.ts.map +1 -0
  40. package/lib/slugger.js +19 -0
  41. package/lib/slugger.js.map +1 -0
  42. package/lib/tags.d.ts +27 -0
  43. package/lib/tags.d.ts.map +1 -0
  44. package/lib/tags.js +77 -0
  45. package/lib/tags.js.map +1 -0
  46. package/lib/urlUtils.d.ts +9 -0
  47. package/lib/urlUtils.d.ts.map +1 -0
  48. package/lib/urlUtils.js +81 -0
  49. package/lib/urlUtils.js.map +1 -0
  50. package/lib/webpackUtils.d.ts +30 -0
  51. package/lib/webpackUtils.d.ts.map +1 -0
  52. package/lib/webpackUtils.js +112 -0
  53. package/lib/webpackUtils.js.map +1 -0
  54. package/package.json +20 -10
  55. package/src/constants.ts +38 -0
  56. package/src/dataFileUtils.ts +90 -0
  57. package/src/deps.d.ts +10 -0
  58. package/src/gitUtils.ts +93 -0
  59. package/src/globUtils.ts +64 -0
  60. package/src/hashUtils.ts +37 -0
  61. package/src/index.ts +135 -294
  62. package/src/markdownLinks.ts +35 -13
  63. package/src/markdownParser.ts +86 -62
  64. package/src/pathUtils.ts +115 -0
  65. package/src/slugger.ts +24 -0
  66. package/src/tags.ts +105 -0
  67. package/src/urlUtils.ts +96 -0
  68. package/src/webpackUtils.ts +146 -0
  69. package/lib/.tsbuildinfo +0 -3972
  70. package/lib/codeTranslationsUtils.d.ts +0 -11
  71. package/lib/codeTranslationsUtils.js +0 -50
  72. package/lib/escapePath.d.ts +0 -17
  73. package/lib/escapePath.js +0 -25
  74. package/lib/posixPath.d.ts +0 -14
  75. package/lib/posixPath.js +0 -28
  76. package/src/__tests__/__fixtures__/defaultCodeTranslations/en.json +0 -4
  77. package/src/__tests__/__fixtures__/defaultCodeTranslations/fr-FR.json +0 -5
  78. package/src/__tests__/__fixtures__/defaultCodeTranslations/fr.json +0 -4
  79. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
  80. package/src/__tests__/codeTranslationsUtils.test.ts +0 -112
  81. package/src/__tests__/escapePath.test.ts +0 -25
  82. package/src/__tests__/index.test.ts +0 -681
  83. package/src/__tests__/markdownParser.test.ts +0 -772
  84. package/src/__tests__/posixPath.test.ts +0 -25
  85. package/src/codeTranslationsUtils.ts +0 -56
  86. package/src/escapePath.ts +0 -23
  87. package/src/posixPath.ts +0 -27
  88. package/tsconfig.json +0 -9
@@ -4,13 +4,17 @@
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
+ export declare function parseMarkdownHeadingId(heading: string): {
8
+ text: string;
9
+ id?: string;
10
+ };
7
11
  export declare function createExcerpt(fileString: string): string | undefined;
8
12
  export declare function parseFrontMatter(markdownFileContent: string): {
9
13
  frontMatter: Record<string, unknown>;
10
14
  content: string;
11
15
  };
12
16
  export declare function parseMarkdownContentTitle(contentUntrimmed: string, options?: {
13
- keepContentTitle?: boolean;
17
+ removeContentTitle?: boolean;
14
18
  }): {
15
19
  content: string;
16
20
  contentTitle: string | undefined;
@@ -22,7 +26,7 @@ declare type ParsedMarkdown = {
22
26
  excerpt: string | undefined;
23
27
  };
24
28
  export declare function parseMarkdownString(markdownFileContent: string, options?: {
25
- keepContentTitle?: boolean;
29
+ removeContentTitle?: boolean;
26
30
  }): ParsedMarkdown;
27
- export declare function parseMarkdownFile(source: string): Promise<ParsedMarkdown>;
28
31
  export {};
32
+ //# sourceMappingURL=markdownParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdownParser.d.ts","sourceRoot":"","sources":["../src/markdownParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAUA;AAKD,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAyEpE;AAED,wBAAgB,gBAAgB,CAAC,mBAAmB,EAAE,MAAM,GAAG;IAC7D,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB,CAMA;AAcD,wBAAgB,yBAAyB,CACvC,gBAAgB,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE;IAAC,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAC,GACvC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;CAAC,CAkCrD;AAED,aAAK,cAAc,GAAG;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,mBAAmB,EAAE,MAAM,EAC3B,OAAO,CAAC,EAAE;IAAC,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAC,GACvC,cAAc,CAuBhB"}
@@ -6,11 +6,24 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.parseMarkdownFile = exports.parseMarkdownString = exports.parseMarkdownContentTitle = exports.parseFrontMatter = exports.createExcerpt = void 0;
9
+ exports.parseMarkdownString = exports.parseMarkdownContentTitle = exports.parseFrontMatter = exports.createExcerpt = exports.parseMarkdownHeadingId = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
12
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
- const gray_matter_1 = tslib_1.__importDefault(require("gray-matter"));
11
+ const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
12
+ const gray_matter_1 = (0, tslib_1.__importDefault)(require("gray-matter"));
13
+ // Input: ## Some heading {#some-heading}
14
+ // Output: {text: "## Some heading", id: "some-heading"}
15
+ function parseMarkdownHeadingId(heading) {
16
+ const customHeadingIdRegex = /^(?<text>.*?)\s*\{#(?<id>[\w-]+)\}$/;
17
+ const matches = customHeadingIdRegex.exec(heading);
18
+ if (matches) {
19
+ return {
20
+ text: matches.groups.text,
21
+ id: matches.groups.id,
22
+ };
23
+ }
24
+ return { text: heading, id: undefined };
25
+ }
26
+ exports.parseMarkdownHeadingId = parseMarkdownHeadingId;
14
27
  // Hacky way of stripping out import statements from the excerpt
15
28
  // TODO: Find a better way to do so, possibly by compiling the Markdown content,
16
29
  // stripping out HTML tags and obtaining the first line.
@@ -20,40 +33,61 @@ function createExcerpt(fileString) {
20
33
  // Remove Markdown alternate title
21
34
  .replace(/^[^\n]*\n[=]+/g, '')
22
35
  .split('\n');
36
+ let inCode = false;
37
+ let lastCodeFence = '';
23
38
  /* eslint-disable no-continue */
24
- // eslint-disable-next-line no-restricted-syntax
25
39
  for (const fileLine of fileLines) {
26
40
  // Skip empty line.
27
41
  if (!fileLine.trim()) {
28
42
  continue;
29
43
  }
30
44
  // Skip import/export declaration.
31
- if (/^\s*?import\s.*(from.*)?;?|export\s.*{.*};?/.test(fileLine)) {
45
+ if (/^(?:import|export)\s.*/.test(fileLine)) {
46
+ continue;
47
+ }
48
+ // Skip code block line.
49
+ if (fileLine.trim().startsWith('```')) {
50
+ if (!inCode) {
51
+ inCode = true;
52
+ [lastCodeFence] = fileLine.trim().match(/^`+/);
53
+ // If we are in a ````-fenced block, all ``` would be plain text instead
54
+ // of fences
55
+ }
56
+ else if (fileLine.trim().match(/^`+/)[0].length >= lastCodeFence.length) {
57
+ inCode = false;
58
+ }
59
+ continue;
60
+ }
61
+ else if (inCode) {
32
62
  continue;
33
63
  }
34
64
  const cleanedLine = fileLine
35
65
  // Remove HTML tags.
36
66
  .replace(/<[^>]*>/g, '')
37
67
  // Remove Title headers
38
- .replace(/^\#\s*([^#]*)\s*\#?/gm, '')
68
+ .replace(/^#\s*[^#]*\s*#?/gm, '')
39
69
  // Remove Markdown + ATX-style headers
40
- .replace(/^\#{1,6}\s*([^#]*)\s*(\#{1,6})?/gm, '$1')
41
- // Remove emphasis and strikethroughs.
42
- .replace(/([\*_~]{1,3})(\S.*?\S{0,1})\1/g, '$2')
70
+ .replace(/^#{1,6}\s*(?<text>[^#]*)\s*(?:#{1,6})?/gm, '$1')
71
+ // Remove emphasis.
72
+ .replace(/(?<opening>[*_]{1,3})(?<text>.*?)\1/g, '$2')
73
+ // Remove strikethroughs.
74
+ .replace(/~~(?<text>\S.*\S)~~/g, '$1')
43
75
  // Remove images.
44
- .replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
76
+ .replace(/!\[(?<alt>.*?)\][[(].*?[\])]/g, '$1')
45
77
  // Remove footnotes.
46
- .replace(/\[\^.+?\](\: .*?$)?/g, '')
78
+ .replace(/\[\^.+?\](?:: .*?$)?/g, '')
47
79
  // Remove inline links.
48
- .replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
80
+ .replace(/\[(?<alt>.*?)\][[(].*?[\])]/g, '$1')
49
81
  // Remove inline code.
50
- .replace(/`(.+?)`/g, '$1')
82
+ .replace(/`(?<text>.+?)`/g, '$1')
51
83
  // Remove blockquotes.
52
84
  .replace(/^\s{0,3}>\s?/g, '')
53
85
  // Remove admonition definition.
54
- .replace(/(:{3}.*)/, '')
86
+ .replace(/:::.*/, '')
55
87
  // Remove Emoji names within colons include preceding whitespace.
56
- .replace(/\s?(:(::|[^:\n])+:)/g, '')
88
+ .replace(/\s?:(?:::|[^:\n])+:/g, '')
89
+ // Remove custom Markdown heading id.
90
+ .replace(/{#*[\w-]+}/, '')
57
91
  .trim();
58
92
  if (cleanedLine) {
59
93
  return cleanedLine;
@@ -63,21 +97,30 @@ function createExcerpt(fileString) {
63
97
  }
64
98
  exports.createExcerpt = createExcerpt;
65
99
  function parseFrontMatter(markdownFileContent) {
66
- var _a;
67
- const { data, content } = gray_matter_1.default(markdownFileContent);
100
+ const { data, content } = (0, gray_matter_1.default)(markdownFileContent);
68
101
  return {
69
- frontMatter: data !== null && data !== void 0 ? data : {},
70
- content: (_a = content === null || content === void 0 ? void 0 : content.trim()) !== null && _a !== void 0 ? _a : '',
102
+ frontMatter: data,
103
+ content: content.trim(),
71
104
  };
72
105
  }
73
106
  exports.parseFrontMatter = parseFrontMatter;
107
+ /**
108
+ * Try to convert markdown heading to text. Does not need to be perfect, it is
109
+ * only used as a fallback when frontMatter.title is not provided. For now, we
110
+ * just unwrap possible inline code blocks (# `config.js`)
111
+ */
112
+ function toTextContentTitle(contentTitle) {
113
+ if (contentTitle.startsWith('`') && contentTitle.endsWith('`')) {
114
+ return contentTitle.substring(1, contentTitle.length - 1);
115
+ }
116
+ return contentTitle;
117
+ }
74
118
  function parseMarkdownContentTitle(contentUntrimmed, options) {
75
119
  var _a, _b;
76
- const keepContentTitleOption = (_a = options === null || options === void 0 ? void 0 : options.keepContentTitle) !== null && _a !== void 0 ? _a : false;
120
+ const removeContentTitleOption = (_a = options === null || options === void 0 ? void 0 : options.removeContentTitle) !== null && _a !== void 0 ? _a : false;
77
121
  const content = contentUntrimmed.trim();
78
- const IMPORT_STATEMENT = /import\s+(([\w*{}\s\n,]+)from\s+)?["'\s]([@\w/_.-]+)["'\s];?|\n/
79
- .source;
80
- const REGULAR_TITLE = /(?<pattern>#\s*(?<title>[^#\n{]*)+[ \t]*(?<suffix>({#*[\w-]+})|#)?\n*?)/
122
+ const IMPORT_STATEMENT = /import\s+(?:[\w*{}\s\n,]+from\s+)?["'\s][@\w/_.-]+["'\s];?|\n/.source;
123
+ const REGULAR_TITLE = /(?<pattern>#\s*(?<title>[^#\n{]*)+[ \t]*(?<suffix>(?:{#*[\w-]+})|#)?\n*?)/
81
124
  .source;
82
125
  const ALTERNATE_TITLE = /(?<pattern>\s*(?<title>[^\n]*)\s*\n[=]+)/.source;
83
126
  const regularTitleMatch = new RegExp(`^(?:${IMPORT_STATEMENT})*?${REGULAR_TITLE}`, 'g').exec(content);
@@ -87,23 +130,19 @@ function parseMarkdownContentTitle(contentUntrimmed, options) {
87
130
  if (!pattern || !title) {
88
131
  return { content, contentTitle: undefined };
89
132
  }
90
- const newContent = keepContentTitleOption
91
- ? content
92
- : content.replace(pattern, '');
133
+ const newContent = removeContentTitleOption
134
+ ? content.replace(pattern, '')
135
+ : content;
93
136
  return {
94
137
  content: newContent.trim(),
95
- contentTitle: title.trim(),
138
+ contentTitle: toTextContentTitle(title.trim()).trim(),
96
139
  };
97
140
  }
98
141
  exports.parseMarkdownContentTitle = parseMarkdownContentTitle;
99
142
  function parseMarkdownString(markdownFileContent, options) {
100
- var _a;
101
143
  try {
102
- const keepContentTitle = (_a = options === null || options === void 0 ? void 0 : options.keepContentTitle) !== null && _a !== void 0 ? _a : false;
103
144
  const { frontMatter, content: contentWithoutFrontMatter } = parseFrontMatter(markdownFileContent);
104
- const { content, contentTitle } = parseMarkdownContentTitle(contentWithoutFrontMatter, {
105
- keepContentTitle,
106
- });
145
+ const { content, contentTitle } = parseMarkdownContentTitle(contentWithoutFrontMatter, options);
107
146
  const excerpt = createExcerpt(content);
108
147
  return {
109
148
  frontMatter,
@@ -112,21 +151,11 @@ function parseMarkdownString(markdownFileContent, options) {
112
151
  excerpt,
113
152
  };
114
153
  }
115
- catch (e) {
116
- console.error(chalk_1.default.red(`Error while parsing markdown front matter.
117
- This can happen if you use special characters like : in frontmatter values (try using "" around that value)`));
118
- throw e;
154
+ catch (err) {
155
+ logger_1.default.error(`Error while parsing Markdown front matter.
156
+ This can happen if you use special characters in front matter values (try using double quotes around that value).`);
157
+ throw err;
119
158
  }
120
159
  }
121
160
  exports.parseMarkdownString = parseMarkdownString;
122
- async function parseMarkdownFile(source) {
123
- const markdownString = await fs_extra_1.default.readFile(source, 'utf-8');
124
- try {
125
- return parseMarkdownString(markdownString);
126
- }
127
- catch (e) {
128
- throw new Error(`Error while parsing markdown file ${source}
129
- ${e.message}`);
130
- }
131
- }
132
- exports.parseMarkdownFile = parseMarkdownFile;
161
+ //# sourceMappingURL=markdownParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdownParser.js","sourceRoot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AE,KAAK,EAAC,GAAG,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,mCAAI,EAAE,CAAC;IAElD,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,EAAE;QACtB,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAC,CAAC;KAC3C;IACD,MAAM,UAAU,GAAG,wBAAwB;QACzC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAC9B,CAAC,CAAC,OAAO,CAAC;IACZ,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,IAAI,EAAE;QAC1B,YAAY,EAAE,kBAAkB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;KACtD,CAAC;AACJ,CAAC;AArCD,8DAqCC;AASD,SAAgB,mBAAmB,CACjC,mBAA2B,EAC3B,OAAwC;IAExC,IAAI;QACF,MAAM,EAAC,WAAW,EAAE,OAAO,EAAE,yBAAyB,EAAC,GACrD,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;QAExC,MAAM,EAAC,OAAO,EAAE,YAAY,EAAC,GAAG,yBAAyB,CACvD,yBAAyB,EACzB,OAAO,CACR,CAAC;QAEF,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QAEvC,OAAO;YACL,WAAW;YACX,OAAO;YACP,YAAY;YACZ,OAAO;SACR,CAAC;KACH;IAAC,OAAO,GAAG,EAAE;QACZ,gBAAM,CAAC,KAAK,CAAC;kHACiG,CAAC,CAAC;QAChH,MAAM,GAAG,CAAC;KACX;AACH,CAAC;AA1BD,kDA0BC"}
@@ -0,0 +1,51 @@
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 const isNameTooLong: (str: string) => boolean;
8
+ export declare const shortName: (str: string) => string;
9
+ /**
10
+ * Convert Windows backslash paths to posix style paths.
11
+ * E.g: endi\lie -> endi/lie
12
+ *
13
+ * Returns original path if the posix counterpart is not valid Windows path.
14
+ * This makes the legacy code that uses posixPath safe; but also makes it less
15
+ * useful when you actually want a path with forward slashes (e.g. for URL)
16
+ *
17
+ * Adopted from https://github.com/sindresorhus/slash/blob/main/index.js
18
+ */
19
+ export declare function posixPath(str: string): string;
20
+ /**
21
+ * When you want to display a path in a message/warning/error, it's more
22
+ * convenient to:
23
+ *
24
+ * - make it relative to `cwd()`
25
+ * - convert to posix (ie not using windows \ path separator)
26
+ *
27
+ * This way, Jest tests can run more reliably on any computer/CI on both
28
+ * Unix/Windows
29
+ * For Windows users this is not perfect (as they see / instead of \) but it's
30
+ * probably good enough
31
+ */
32
+ export declare function toMessageRelativeFilePath(filePath: string): string;
33
+ /**
34
+ * Alias filepath relative to site directory, very useful so that we
35
+ * don't expose user's site structure.
36
+ * Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
37
+ */
38
+ export declare function aliasedSitePath(filePath: string, siteDir: string): string;
39
+ /**
40
+ * When you have a path like C:\X\Y
41
+ * It is not safe to use directly when generating code
42
+ * For example, this would fail due to unescaped \:
43
+ * `<img src={require('${filePath}')} />`
44
+ * But this would work: `<img src={require('${escapePath(filePath)}')} />`
45
+ *
46
+ * posixPath can't be used in all cases, because forward slashes are only valid
47
+ * Windows paths when they don't contain non-ascii characters, and posixPath
48
+ * doesn't escape those that fail to be converted.
49
+ */
50
+ export declare function escapePath(str: string): string;
51
+ //# sourceMappingURL=pathUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,eAAO,MAAM,aAAa,QAAS,MAAM,KAAG,OAIgC,CAAC;AAE7E,eAAO,MAAM,SAAS,QAAS,MAAM,KAAG,MAiBvC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAY7C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKzE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK9C"}
@@ -0,0 +1,106 @@
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.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = void 0;
10
+ const tslib_1 = require("tslib");
11
+ // Based on https://github.com/gatsbyjs/gatsby/pull/21518/files
12
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
+ // MacOS (APFS) and Windows (NTFS) filename length limit = 255 chars,
14
+ // Others = 255 bytes
15
+ const MAX_PATH_SEGMENT_CHARS = 255;
16
+ const MAX_PATH_SEGMENT_BYTES = 255;
17
+ // Space for appending things to the string like file extensions and so on
18
+ const SPACE_FOR_APPENDING = 10;
19
+ const isMacOs = () => process.platform === 'darwin';
20
+ const isWindows = () => process.platform === 'win32';
21
+ const isNameTooLong = (str) =>
22
+ // Not entirely correct: we can't assume FS from OS. But good enough?
23
+ isMacOs() || isWindows()
24
+ ? str.length + SPACE_FOR_APPENDING > MAX_PATH_SEGMENT_CHARS // MacOS (APFS) and Windows (NTFS) filename length limit (255 chars)
25
+ : Buffer.from(str).length + SPACE_FOR_APPENDING > MAX_PATH_SEGMENT_BYTES; // Other (255 bytes)
26
+ exports.isNameTooLong = isNameTooLong;
27
+ const shortName = (str) => {
28
+ if (isMacOs() || isWindows()) {
29
+ const overflowingChars = str.length - MAX_PATH_SEGMENT_CHARS;
30
+ return str.slice(0, str.length - overflowingChars - SPACE_FOR_APPENDING - 1);
31
+ }
32
+ const strBuffer = Buffer.from(str);
33
+ const overflowingBytes = Buffer.byteLength(strBuffer) - MAX_PATH_SEGMENT_BYTES;
34
+ return strBuffer
35
+ .slice(0, Buffer.byteLength(strBuffer) - overflowingBytes - SPACE_FOR_APPENDING - 1)
36
+ .toString();
37
+ };
38
+ exports.shortName = shortName;
39
+ /**
40
+ * Convert Windows backslash paths to posix style paths.
41
+ * E.g: endi\lie -> endi/lie
42
+ *
43
+ * Returns original path if the posix counterpart is not valid Windows path.
44
+ * This makes the legacy code that uses posixPath safe; but also makes it less
45
+ * useful when you actually want a path with forward slashes (e.g. for URL)
46
+ *
47
+ * Adopted from https://github.com/sindresorhus/slash/blob/main/index.js
48
+ */
49
+ function posixPath(str) {
50
+ const isExtendedLengthPath = /^\\\\\?\\/.test(str);
51
+ // Forward slashes are only valid Windows paths when they don't contain non-
52
+ // ascii characters.
53
+ // eslint-disable-next-line no-control-regex
54
+ const hasNonAscii = /[^\u0000-\u0080]+/.test(str);
55
+ if (isExtendedLengthPath || hasNonAscii) {
56
+ return str;
57
+ }
58
+ return str.replace(/\\/g, '/');
59
+ }
60
+ exports.posixPath = posixPath;
61
+ /**
62
+ * When you want to display a path in a message/warning/error, it's more
63
+ * convenient to:
64
+ *
65
+ * - make it relative to `cwd()`
66
+ * - convert to posix (ie not using windows \ path separator)
67
+ *
68
+ * This way, Jest tests can run more reliably on any computer/CI on both
69
+ * Unix/Windows
70
+ * For Windows users this is not perfect (as they see / instead of \) but it's
71
+ * probably good enough
72
+ */
73
+ function toMessageRelativeFilePath(filePath) {
74
+ return posixPath(path_1.default.relative(process.cwd(), filePath));
75
+ }
76
+ exports.toMessageRelativeFilePath = toMessageRelativeFilePath;
77
+ /**
78
+ * Alias filepath relative to site directory, very useful so that we
79
+ * don't expose user's site structure.
80
+ * Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
81
+ */
82
+ function aliasedSitePath(filePath, siteDir) {
83
+ const relativePath = posixPath(path_1.default.relative(siteDir, filePath));
84
+ // Cannot use path.join() as it resolves '../' and removes
85
+ // the '@site'. Let webpack loader resolve it.
86
+ return `@site/${relativePath}`;
87
+ }
88
+ exports.aliasedSitePath = aliasedSitePath;
89
+ /**
90
+ * When you have a path like C:\X\Y
91
+ * It is not safe to use directly when generating code
92
+ * For example, this would fail due to unescaped \:
93
+ * `<img src={require('${filePath}')} />`
94
+ * But this would work: `<img src={require('${escapePath(filePath)}')} />`
95
+ *
96
+ * posixPath can't be used in all cases, because forward slashes are only valid
97
+ * Windows paths when they don't contain non-ascii characters, and posixPath
98
+ * doesn't escape those that fail to be converted.
99
+ */
100
+ function escapePath(str) {
101
+ const escaped = JSON.stringify(str);
102
+ // Remove the " around the json string;
103
+ return escaped.substring(1, escaped.length - 1);
104
+ }
105
+ exports.escapePath = escapePath;
106
+ //# sourceMappingURL=pathUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathUtils.js","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,+DAA+D;AAE/D,6DAAwB;AAExB,qEAAqE;AACrE,qBAAqB;AACrB,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,0EAA0E;AAC1E,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC;AACpD,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAE9C,MAAM,aAAa,GAAG,CAAC,GAAW,EAAW,EAAE;AACpD,qEAAqE;AACrE,OAAO,EAAE,IAAI,SAAS,EAAE;IACtB,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,m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H,SAAgB,yBAAyB,CAAC,QAAgB;IACxD,OAAO,SAAS,CAAC,cAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC3D,CAAC;AAFD,8DAEC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,QAAgB,EAAE,OAAe;IAC/D,MAAM,YAAY,GAAG,SAAS,CAAC,cAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IACjE,0DAA0D;IAC1D,8CAA8C;IAC9C,OAAO,SAAS,YAAY,EAAE,CAAC;AACjC,CAAC;AALD,0CAKC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CAAC,GAAW;IACpC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAEpC,uCAAuC;IACvC,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC;AALD,gCAKC"}
@@ -0,0 +1,14 @@
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 type SluggerOptions = {
8
+ maintainCase?: boolean;
9
+ };
10
+ export declare type Slugger = {
11
+ slug: (value: string, options?: SluggerOptions) => string;
12
+ };
13
+ export declare function createSlugger(): Slugger;
14
+ //# sourceMappingURL=slugger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slugger.d.ts","sourceRoot":"","sources":["../src/slugger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,oBAAY,cAAc,GAAG;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAC,CAAC;AAEtD,oBAAY,OAAO,GAAG;IACpB,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,MAAM,CAAC;CAC3D,CAAC;AAEF,wBAAgB,aAAa,IAAI,OAAO,CAKvC"}
package/lib/slugger.js ADDED
@@ -0,0 +1,19 @@
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.createSlugger = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const github_slugger_1 = (0, tslib_1.__importDefault)(require("github-slugger"));
12
+ function createSlugger() {
13
+ const githubSlugger = new github_slugger_1.default();
14
+ return {
15
+ slug: (value, options) => githubSlugger.slug(value, options === null || options === void 0 ? void 0 : options.maintainCase),
16
+ };
17
+ }
18
+ exports.createSlugger = createSlugger;
19
+ //# sourceMappingURL=slugger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slugger.js","sourceRoot":"","sources":["../src/slugger.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,iFAA2C;AAW3C,SAAgB,aAAa;IAC3B,MAAM,aAAa,GAAG,IAAI,wBAAa,EAAE,CAAC;IAC1C,OAAO;QACL,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAC;KAC3E,CAAC;AACJ,CAAC;AALD,sCAKC"}
package/lib/tags.d.ts ADDED
@@ -0,0 +1,27 @@
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 type Tag = {
8
+ label: string;
9
+ permalink: string;
10
+ };
11
+ export declare type FrontMatterTag = string | Tag;
12
+ export declare function normalizeFrontMatterTag(tagsPath: string, frontMatterTag: FrontMatterTag): Tag;
13
+ export declare function normalizeFrontMatterTags(tagsPath: string, frontMatterTags?: FrontMatterTag[] | undefined): Tag[];
14
+ export declare type TaggedItemGroup<Item> = {
15
+ tag: Tag;
16
+ items: Item[];
17
+ };
18
+ /**
19
+ * Permits to group docs/blogPosts by tag (provided by front matter)
20
+ * Note: groups are indexed by permalink, because routes must be unique in the
21
+ * end. Labels may vary on 2 md files but they are normalized. Docs with
22
+ * label='some label' and label='some-label' should end-up in the same
23
+ * group/page in the end. We can't create 2 routes /some-label because one would
24
+ * override the other
25
+ */
26
+ export declare function groupTaggedItems<Item>(items: Item[], getItemTags: (item: Item) => Tag[]): Record<string, TaggedItemGroup<Item>>;
27
+ //# sourceMappingURL=tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,oBAAY,GAAG,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,cAAc,GAAG,MAAM,GAAG,GAAG,CAAC;AAE1C,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,cAAc,GAC7B,GAAG,CAyBL;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,EAChB,eAAe,GAAE,cAAc,EAAE,GAAG,SAAc,GACjD,GAAG,EAAE,CAMP;AAED,oBAAY,eAAe,CAAC,IAAI,IAAI;IAClC,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EACnC,KAAK,EAAE,IAAI,EAAE,EACb,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,EAAE,GACjC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CA8BvC"}
package/lib/tags.js ADDED
@@ -0,0 +1,77 @@
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.groupTaggedItems = exports.normalizeFrontMatterTags = exports.normalizeFrontMatterTag = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
12
+ const urlUtils_1 = require("./urlUtils");
13
+ function normalizeFrontMatterTag(tagsPath, frontMatterTag) {
14
+ function toTagObject(tagString) {
15
+ return {
16
+ label: tagString,
17
+ permalink: lodash_1.default.kebabCase(tagString),
18
+ };
19
+ }
20
+ // TODO maybe make ensure the permalink is valid url path?
21
+ function normalizeTagPermalink(permalink) {
22
+ // note: we always apply tagsPath on purpose. For versioned docs, v1/doc.md
23
+ // and v2/doc.md tags with custom permalinks don't lead to the same created
24
+ // page. tagsPath is different for each doc version
25
+ return (0, urlUtils_1.normalizeUrl)([tagsPath, permalink]);
26
+ }
27
+ const tag = typeof frontMatterTag === 'string'
28
+ ? toTagObject(frontMatterTag)
29
+ : frontMatterTag;
30
+ return {
31
+ label: tag.label,
32
+ permalink: normalizeTagPermalink(tag.permalink),
33
+ };
34
+ }
35
+ exports.normalizeFrontMatterTag = normalizeFrontMatterTag;
36
+ function normalizeFrontMatterTags(tagsPath, frontMatterTags = []) {
37
+ const tags = frontMatterTags.map((tag) => normalizeFrontMatterTag(tagsPath, tag));
38
+ return lodash_1.default.uniqBy(tags, (tag) => tag.permalink);
39
+ }
40
+ exports.normalizeFrontMatterTags = normalizeFrontMatterTags;
41
+ /**
42
+ * Permits to group docs/blogPosts by tag (provided by front matter)
43
+ * Note: groups are indexed by permalink, because routes must be unique in the
44
+ * end. Labels may vary on 2 md files but they are normalized. Docs with
45
+ * label='some label' and label='some-label' should end-up in the same
46
+ * group/page in the end. We can't create 2 routes /some-label because one would
47
+ * override the other
48
+ */
49
+ function groupTaggedItems(items, getItemTags) {
50
+ const result = {};
51
+ function handleItemTag(item, tag) {
52
+ var _a;
53
+ // Init missing tag groups
54
+ // TODO: it's not really clear what should be the behavior if 2 items have
55
+ // the same tag but the permalink is different for each
56
+ // For now, the first tag found wins
57
+ result[tag.permalink] = (_a = result[tag.permalink]) !== null && _a !== void 0 ? _a : {
58
+ tag,
59
+ items: [],
60
+ };
61
+ // Add item to group
62
+ result[tag.permalink].items.push(item);
63
+ }
64
+ items.forEach((item) => {
65
+ getItemTags(item).forEach((tag) => {
66
+ handleItemTag(item, tag);
67
+ });
68
+ });
69
+ // If user add twice the same tag to a md doc (weird but possible),
70
+ // we don't want the item to appear twice in the list...
71
+ Object.values(result).forEach((group) => {
72
+ group.items = lodash_1.default.uniq(group.items);
73
+ });
74
+ return result;
75
+ }
76
+ exports.groupTaggedItems = groupTaggedItems;
77
+ //# sourceMappingURL=tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,iEAAuB;AACvB,yCAAwC;AASxC,SAAgB,uBAAuB,CACrC,QAAgB,EAChB,cAA8B;IAE9B,SAAS,WAAW,CAAC,SAAiB;QACpC,OAAO;YACL,KAAK,EAAE,SAAS;YAChB,SAAS,EAAE,gBAAC,CAAC,SAAS,CAAC,SAAS,CAAC;SAClC,CAAC;IACJ,CAAC;IAED,0DAA0D;IAC1D,SAAS,qBAAqB,CAAC,SAAiB;QAC9C,2EAA2E;QAC3E,2EAA2E;QAC3E,mDAAmD;QACnD,OAAO,IAAA,uBAAY,EAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,GAAG,GACP,OAAO,cAAc,KAAK,QAAQ;QAChC,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC;QAC7B,CAAC,CAAC,cAAc,CAAC;IAErB,OAAO;QACL,KAAK,E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,EAAE;QACtC,KAAK,CAAC,KAAK,GAAG,gBAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAjCD,4CAiCC"}
@@ -0,0 +1,9 @@
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 normalizeUrl(rawUrls: string[]): string;
8
+ export declare function getEditUrl(fileRelativePath: string, editUrl?: string): string | undefined;
9
+ //# sourceMappingURL=urlUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CA8EtD;AAED,wBAAgB,UAAU,CACxB,gBAAgB,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAKpB"}