@docusaurus/utils 2.0.0-beta.13 → 2.0.0-beta.15
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/constants.d.ts +1 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -0
- package/lib/dataFileUtils.d.ts +24 -0
- package/lib/dataFileUtils.d.ts.map +1 -0
- package/lib/dataFileUtils.js +65 -0
- package/lib/dataFileUtils.js.map +1 -0
- package/lib/globUtils.d.ts +1 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +3 -2
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +1 -0
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +1 -0
- package/lib/hashUtils.js.map +1 -0
- package/lib/index.d.ts +19 -41
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +45 -143
- package/lib/index.js.map +1 -0
- package/lib/markdownLinks.d.ts +1 -0
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +13 -4
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownParser.d.ts +5 -3
- package/lib/markdownParser.d.ts.map +1 -0
- package/lib/markdownParser.js +32 -19
- package/lib/markdownParser.js.map +1 -0
- package/lib/pathUtils.d.ts +30 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +70 -5
- package/lib/pathUtils.js.map +1 -0
- package/lib/slugger.d.ts +1 -0
- package/lib/slugger.d.ts.map +1 -0
- package/lib/slugger.js +1 -0
- package/lib/slugger.js.map +1 -0
- package/lib/tags.d.ts +2 -1
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +5 -5
- package/lib/tags.js.map +1 -0
- package/lib/{normalizeUrl.d.ts → urlUtils.d.ts} +2 -0
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/{normalizeUrl.js → urlUtils.js} +17 -3
- package/lib/urlUtils.js.map +1 -0
- package/lib/webpackUtils.d.ts +1 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +4 -3
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +8 -6
- package/src/dataFileUtils.ts +90 -0
- package/src/globUtils.ts +2 -1
- package/src/index.ts +52 -177
- package/src/markdownLinks.ts +10 -3
- package/src/markdownParser.ts +33 -23
- package/src/pathUtils.ts +70 -4
- package/src/tags.ts +5 -4
- package/src/{normalizeUrl.ts → urlUtils.ts} +17 -2
- package/src/webpackUtils.ts +4 -4
- package/lib/.tsbuildinfo +0 -1
- package/lib/escapePath.d.ts +0 -17
- package/lib/escapePath.js +0 -25
- package/lib/mdxUtils.d.ts +0 -16
- package/lib/mdxUtils.js +0 -30
- package/lib/posixPath.d.ts +0 -14
- package/lib/posixPath.js +0 -28
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
- package/src/__tests__/escapePath.test.ts +0 -25
- package/src/__tests__/globUtils.test.ts +0 -109
- package/src/__tests__/hashUtils.test.ts +0 -51
- package/src/__tests__/index.test.ts +0 -527
- package/src/__tests__/markdownParser.test.ts +0 -830
- package/src/__tests__/mdxUtils.test.ts +0 -133
- package/src/__tests__/normalizeUrl.test.ts +0 -117
- package/src/__tests__/pathUtils.test.ts +0 -65
- package/src/__tests__/posixPath.test.ts +0 -25
- package/src/__tests__/slugger.test.ts +0 -27
- package/src/__tests__/tags.test.ts +0 -183
- package/src/__tests__/webpackUtils.test.ts +0 -33
- package/src/escapePath.ts +0 -23
- package/src/mdxUtils.ts +0 -32
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
|
@@ -1,133 +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 {mdxToHtml} from '../mdxUtils';
|
|
9
|
-
|
|
10
|
-
describe('mdxToHtml', () => {
|
|
11
|
-
test('work with simple markdown', () => {
|
|
12
|
-
const mdxString = `
|
|
13
|
-
# title
|
|
14
|
-
|
|
15
|
-
title text **bold**
|
|
16
|
-
|
|
17
|
-
## subtitle
|
|
18
|
-
|
|
19
|
-
subtitle text *italic*
|
|
20
|
-
|
|
21
|
-
> Quote
|
|
22
|
-
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(
|
|
26
|
-
`"<h1>title</h1><p>title text <strong>bold</strong></p><h2>subtitle</h2><p>subtitle text <em>italic</em></p><blockquote><p>Quote</p></blockquote>"`,
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('work with MDX imports', () => {
|
|
31
|
-
const mdxString = `
|
|
32
|
-
# title
|
|
33
|
-
|
|
34
|
-
import Tabs from '@theme/Tabs';
|
|
35
|
-
import TabItem from '@theme/TabItem';
|
|
36
|
-
|
|
37
|
-
text
|
|
38
|
-
|
|
39
|
-
`;
|
|
40
|
-
|
|
41
|
-
expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(
|
|
42
|
-
`"<h1>title</h1><p>text</p>"`,
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('work with MDX exports', () => {
|
|
47
|
-
const mdxString = `
|
|
48
|
-
# title
|
|
49
|
-
|
|
50
|
-
export const someExport = 42
|
|
51
|
-
|
|
52
|
-
export const MyLocalComponent = () => "result"
|
|
53
|
-
|
|
54
|
-
export const toc = [
|
|
55
|
-
{id: "title",label: "title"}
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
text
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
`;
|
|
62
|
-
|
|
63
|
-
expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(
|
|
64
|
-
`"<h1>title</h1><p>text</p>"`,
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('work with MDX Tabs', () => {
|
|
69
|
-
const mdxString = `
|
|
70
|
-
# title
|
|
71
|
-
|
|
72
|
-
import Tabs from '@theme/Tabs';
|
|
73
|
-
import TabItem from '@theme/TabItem';
|
|
74
|
-
|
|
75
|
-
<Tabs>
|
|
76
|
-
<TabItem value="apple" label="Apple">
|
|
77
|
-
This is an apple 🍎
|
|
78
|
-
</TabItem>
|
|
79
|
-
<TabItem value="orange" label="Orange">
|
|
80
|
-
This is an orange 🍊
|
|
81
|
-
</TabItem>
|
|
82
|
-
</Tabs>
|
|
83
|
-
|
|
84
|
-
text
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
`;
|
|
88
|
-
|
|
89
|
-
// TODO this is not an ideal behavior!
|
|
90
|
-
// There is a warning "Component TabItem was not imported, exported, or provided by MDXProvider as global scope"
|
|
91
|
-
// Theme + MDX config should provide a list of React components to put in MDX scope
|
|
92
|
-
expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(
|
|
93
|
-
`"<h1>title</h1><div><div value=\\"apple\\" label=\\"Apple\\">This is an apple 🍎</div><div value=\\"orange\\" label=\\"Orange\\">This is an orange 🍊</div></div><p>text</p>"`,
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('work with MDX Tabs with ```mdx-code-block', () => {
|
|
98
|
-
const mdxString = `
|
|
99
|
-
# title
|
|
100
|
-
|
|
101
|
-
import Tabs from '@theme/Tabs';
|
|
102
|
-
import TabItem from '@theme/TabItem';
|
|
103
|
-
|
|
104
|
-
\`\`\`mdx-code-block
|
|
105
|
-
<Tabs>
|
|
106
|
-
<TabItem value="apple" label="Apple">
|
|
107
|
-
This is an apple 🍎
|
|
108
|
-
</TabItem>
|
|
109
|
-
<TabItem value="orange" label="Orange">
|
|
110
|
-
This is an orange 🍊
|
|
111
|
-
</TabItem>
|
|
112
|
-
</Tabs>
|
|
113
|
-
\`\`\`
|
|
114
|
-
|
|
115
|
-
text
|
|
116
|
-
|
|
117
|
-
`;
|
|
118
|
-
|
|
119
|
-
// TODO bad behavior!
|
|
120
|
-
// ```mdx-code-block should be unwrapped and inner MDX content should be evaluated
|
|
121
|
-
expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(`
|
|
122
|
-
"<h1>title</h1><pre><code class=\\"language-mdx-code-block\\"><Tabs>
|
|
123
|
-
<TabItem value="apple" label="Apple">
|
|
124
|
-
This is an apple 🍎
|
|
125
|
-
</TabItem>
|
|
126
|
-
<TabItem value="orange" label="Orange">
|
|
127
|
-
This is an orange 🍊
|
|
128
|
-
</TabItem>
|
|
129
|
-
</Tabs>
|
|
130
|
-
</code></pre><p>text</p>"
|
|
131
|
-
`);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,117 +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 {normalizeUrl} from '../normalizeUrl';
|
|
9
|
-
|
|
10
|
-
describe('normalizeUrl', () => {
|
|
11
|
-
test('should normalize urls correctly', () => {
|
|
12
|
-
const asserts = [
|
|
13
|
-
{
|
|
14
|
-
input: ['/', ''],
|
|
15
|
-
output: '/',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
input: ['', '/'],
|
|
19
|
-
output: '/',
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
input: ['/'],
|
|
23
|
-
output: '/',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
input: [''],
|
|
27
|
-
output: '',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
input: ['/', '/'],
|
|
31
|
-
output: '/',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
input: ['/', 'docs'],
|
|
35
|
-
output: '/docs',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
input: ['/', 'docs', 'en', 'next', 'blog'],
|
|
39
|
-
output: '/docs/en/next/blog',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
input: ['/test/', '/docs', 'ro', 'doc1'],
|
|
43
|
-
output: '/test/docs/ro/doc1',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
input: ['/test/', '/', 'ro', 'doc1'],
|
|
47
|
-
output: '/test/ro/doc1',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
input: ['/', '/', '2020/02/29/leap-day'],
|
|
51
|
-
output: '/2020/02/29/leap-day',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
input: ['', '/', 'ko', 'hello'],
|
|
55
|
-
output: '/ko/hello',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
input: ['hello', 'world'],
|
|
59
|
-
output: 'hello/world',
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
input: ['http://www.google.com/', 'foo/bar', '?test=123'],
|
|
63
|
-
output: 'http://www.google.com/foo/bar?test=123',
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
input: ['http:', 'www.google.com///', 'foo/bar', '?test=123'],
|
|
67
|
-
output: 'http://www.google.com/foo/bar?test=123',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
input: ['http://foobar.com', '', 'test'],
|
|
71
|
-
output: 'http://foobar.com/test',
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
input: ['http://foobar.com', '', 'test', '/'],
|
|
75
|
-
output: 'http://foobar.com/test/',
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
input: ['/', '', 'hello', '', '/', '/', '', '/', '/world'],
|
|
79
|
-
output: '/hello/world',
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
input: ['', '', '/tt', 'ko', 'hello'],
|
|
83
|
-
output: '/tt/ko/hello',
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
input: ['', '///hello///', '', '///world'],
|
|
87
|
-
output: '/hello/world',
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
input: ['', '/hello/', ''],
|
|
91
|
-
output: '/hello/',
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
input: ['', '/', ''],
|
|
95
|
-
output: '/',
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
input: ['///', '///'],
|
|
99
|
-
output: '/',
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
input: ['/', '/hello/world/', '///'],
|
|
103
|
-
output: '/hello/world/',
|
|
104
|
-
},
|
|
105
|
-
];
|
|
106
|
-
asserts.forEach((testCase) => {
|
|
107
|
-
expect(normalizeUrl(testCase.input)).toBe(testCase.output);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
expect(() =>
|
|
111
|
-
// @ts-expect-error undefined for test
|
|
112
|
-
normalizeUrl(['http:example.com', undefined]),
|
|
113
|
-
).toThrowErrorMatchingInlineSnapshot(
|
|
114
|
-
`"Url must be a string. Received undefined"`,
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
@@ -1,65 +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 {isNameTooLong, shortName} from '../pathUtils';
|
|
9
|
-
|
|
10
|
-
describe('pathUtils', () => {
|
|
11
|
-
test('isNameTooLong', () => {
|
|
12
|
-
const asserts: Record<string, boolean> = {
|
|
13
|
-
'': false,
|
|
14
|
-
'foo-bar-096': false,
|
|
15
|
-
'foo-bar-1df': false,
|
|
16
|
-
'endi-lie-9fa': false,
|
|
17
|
-
'endi-lie-fd3': false,
|
|
18
|
-
'yangshun-tay-48d': false,
|
|
19
|
-
'yangshun-tay-f3b': false,
|
|
20
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-d46':
|
|
21
|
-
true,
|
|
22
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-test-1-test-2-787':
|
|
23
|
-
true,
|
|
24
|
-
};
|
|
25
|
-
Object.keys(asserts).forEach((path) => {
|
|
26
|
-
expect(isNameTooLong(path)).toBe(asserts[path]);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('shortName', () => {
|
|
31
|
-
test('works', () => {
|
|
32
|
-
const asserts: Record<string, string> = {
|
|
33
|
-
'': '',
|
|
34
|
-
'foo-bar': 'foo-bar',
|
|
35
|
-
'endi-lie': 'endi-lie',
|
|
36
|
-
'yangshun-tay': 'yangshun-tay',
|
|
37
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar':
|
|
38
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-',
|
|
39
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-test-1-test-2':
|
|
40
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-test-1-test-',
|
|
41
|
-
};
|
|
42
|
-
Object.keys(asserts).forEach((file) => {
|
|
43
|
-
expect(shortName(file)).toBe(asserts[file]);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// Based on https://github.com/gatsbyjs/gatsby/pull/21518/files
|
|
48
|
-
|
|
49
|
-
const SHORT_PATH = `/short/path/without/trailing/slash`;
|
|
50
|
-
const VERY_LONG_PATH = `/${`x`.repeat(256)}/`;
|
|
51
|
-
const VERY_LONG_PATH_NON_LATIN = `/${`あ`.repeat(255)}/`;
|
|
52
|
-
|
|
53
|
-
it(`Truncates long paths correctly`, () => {
|
|
54
|
-
const truncatedPathLatin = shortName(VERY_LONG_PATH);
|
|
55
|
-
const truncatedPathNonLatin = shortName(VERY_LONG_PATH_NON_LATIN);
|
|
56
|
-
expect(truncatedPathLatin.length).toBeLessThanOrEqual(255);
|
|
57
|
-
expect(truncatedPathNonLatin.length).toBeLessThanOrEqual(255);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it(`Does not truncate short paths`, () => {
|
|
61
|
-
const truncatedPath = shortName(SHORT_PATH);
|
|
62
|
-
expect(truncatedPath).toEqual(SHORT_PATH);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,25 +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 {posixPath} from '../posixPath';
|
|
9
|
-
|
|
10
|
-
describe('posixPath', () => {
|
|
11
|
-
test('posixPath works', () => {
|
|
12
|
-
const asserts: Record<string, string> = {
|
|
13
|
-
'c:/aaaa\\bbbb': 'c:/aaaa/bbbb',
|
|
14
|
-
'c:\\aaaa\\bbbb\\★': 'c:\\aaaa\\bbbb\\★',
|
|
15
|
-
'\\\\?\\c:\\aaaa\\bbbb': '\\\\?\\c:\\aaaa\\bbbb',
|
|
16
|
-
'c:\\aaaa\\bbbb': 'c:/aaaa/bbbb',
|
|
17
|
-
'foo\\bar': 'foo/bar',
|
|
18
|
-
'foo\\bar/lol': 'foo/bar/lol',
|
|
19
|
-
'website\\docs/**/*.{md,mdx}': 'website/docs/**/*.{md,mdx}',
|
|
20
|
-
};
|
|
21
|
-
Object.keys(asserts).forEach((file) => {
|
|
22
|
-
expect(posixPath(file)).toBe(asserts[file]);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,27 +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 {createSlugger} from '../slugger';
|
|
9
|
-
|
|
10
|
-
describe('createSlugger', () => {
|
|
11
|
-
test('can create unique slugs', () => {
|
|
12
|
-
const slugger = createSlugger();
|
|
13
|
-
expect(slugger.slug('Some$/vaLue$!^')).toEqual('somevalue');
|
|
14
|
-
expect(slugger.slug('Some$/vaLue$!^')).toEqual('somevalue-1');
|
|
15
|
-
expect(slugger.slug('Some$/vaLue$!^')).toEqual('somevalue-2');
|
|
16
|
-
expect(slugger.slug('Some$/vaLue$!^-1')).toEqual('somevalue-1-1');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('can create unique slugs respecting case', () => {
|
|
20
|
-
const slugger = createSlugger();
|
|
21
|
-
const opt = {maintainCase: true};
|
|
22
|
-
expect(slugger.slug('Some$/vaLue$!^', opt)).toEqual('SomevaLue');
|
|
23
|
-
expect(slugger.slug('Some$/vaLue$!^', opt)).toEqual('SomevaLue-1');
|
|
24
|
-
expect(slugger.slug('Some$/vaLue$!^', opt)).toEqual('SomevaLue-2');
|
|
25
|
-
expect(slugger.slug('Some$/vaLue$!^-1', opt)).toEqual('SomevaLue-1-1');
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,183 +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 {
|
|
9
|
-
normalizeFrontMatterTag,
|
|
10
|
-
normalizeFrontMatterTags,
|
|
11
|
-
groupTaggedItems,
|
|
12
|
-
Tag,
|
|
13
|
-
} from '../tags';
|
|
14
|
-
|
|
15
|
-
describe('normalizeFrontMatterTag', () => {
|
|
16
|
-
type Input = Parameters<typeof normalizeFrontMatterTag>[1];
|
|
17
|
-
type Output = ReturnType<typeof normalizeFrontMatterTag>;
|
|
18
|
-
|
|
19
|
-
test('should normalize simple string tag', () => {
|
|
20
|
-
const tagsPath = '/all/tags';
|
|
21
|
-
const input: Input = 'tag';
|
|
22
|
-
const expectedOutput: Output = {
|
|
23
|
-
label: 'tag',
|
|
24
|
-
permalink: `${tagsPath}/tag`,
|
|
25
|
-
};
|
|
26
|
-
expect(normalizeFrontMatterTag(tagsPath, input)).toEqual(expectedOutput);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should normalize complex string tag', () => {
|
|
30
|
-
const tagsPath = '/all/tags';
|
|
31
|
-
const input: Input = 'some more Complex_tag';
|
|
32
|
-
const expectedOutput: Output = {
|
|
33
|
-
label: 'some more Complex_tag',
|
|
34
|
-
permalink: `${tagsPath}/some-more-complex-tag`,
|
|
35
|
-
};
|
|
36
|
-
expect(normalizeFrontMatterTag(tagsPath, input)).toEqual(expectedOutput);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('should normalize simple object tag', () => {
|
|
40
|
-
const tagsPath = '/all/tags';
|
|
41
|
-
const input: Input = {label: 'tag', permalink: 'tagPermalink'};
|
|
42
|
-
const expectedOutput: Output = {
|
|
43
|
-
label: 'tag',
|
|
44
|
-
permalink: `${tagsPath}/tagPermalink`,
|
|
45
|
-
};
|
|
46
|
-
expect(normalizeFrontMatterTag(tagsPath, input)).toEqual(expectedOutput);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('should normalize complex string tag', () => {
|
|
50
|
-
const tagsPath = '/all/tags';
|
|
51
|
-
const input: Input = {
|
|
52
|
-
label: 'tag complex Label',
|
|
53
|
-
permalink: '/MoreComplex/Permalink',
|
|
54
|
-
};
|
|
55
|
-
const expectedOutput: Output = {
|
|
56
|
-
label: 'tag complex Label',
|
|
57
|
-
permalink: `${tagsPath}/MoreComplex/Permalink`,
|
|
58
|
-
};
|
|
59
|
-
expect(normalizeFrontMatterTag(tagsPath, input)).toEqual(expectedOutput);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('normalizeFrontMatterTags', () => {
|
|
64
|
-
type Input = Parameters<typeof normalizeFrontMatterTags>[1];
|
|
65
|
-
type Output = ReturnType<typeof normalizeFrontMatterTags>;
|
|
66
|
-
|
|
67
|
-
test('should normalize string list', () => {
|
|
68
|
-
const tagsPath = '/all/tags';
|
|
69
|
-
const input: Input = ['tag 1', 'tag-1', 'tag 3', 'tag1', 'tag-2'];
|
|
70
|
-
// Keep user input order but remove tags that lead to same permalink
|
|
71
|
-
const expectedOutput: Output = [
|
|
72
|
-
{
|
|
73
|
-
label: 'tag 1',
|
|
74
|
-
permalink: `${tagsPath}/tag-1`,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
label: 'tag 3',
|
|
78
|
-
permalink: `${tagsPath}/tag-3`,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
label: 'tag-2',
|
|
82
|
-
permalink: `${tagsPath}/tag-2`,
|
|
83
|
-
},
|
|
84
|
-
];
|
|
85
|
-
expect(normalizeFrontMatterTags(tagsPath, input)).toEqual(expectedOutput);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test('should normalize complex mixed list', () => {
|
|
89
|
-
const tagsPath = '/all/tags';
|
|
90
|
-
const input: Input = [
|
|
91
|
-
'tag 1',
|
|
92
|
-
{label: 'tag-1', permalink: '/tag-1'},
|
|
93
|
-
'tag 3',
|
|
94
|
-
'tag1',
|
|
95
|
-
{label: 'tag 4', permalink: '/tag4Permalink'},
|
|
96
|
-
];
|
|
97
|
-
// Keep user input order but remove tags that lead to same permalink
|
|
98
|
-
const expectedOutput: Output = [
|
|
99
|
-
{
|
|
100
|
-
label: 'tag 1',
|
|
101
|
-
permalink: `${tagsPath}/tag-1`,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
label: 'tag 3',
|
|
105
|
-
permalink: `${tagsPath}/tag-3`,
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
label: 'tag 4',
|
|
109
|
-
permalink: `${tagsPath}/tag4Permalink`,
|
|
110
|
-
},
|
|
111
|
-
];
|
|
112
|
-
expect(normalizeFrontMatterTags(tagsPath, input)).toEqual(expectedOutput);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('groupTaggedItems', () => {
|
|
117
|
-
type SomeTaggedItem = {
|
|
118
|
-
id: string;
|
|
119
|
-
nested: {
|
|
120
|
-
tags: Tag[];
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
function groupItems(items: SomeTaggedItem[]) {
|
|
124
|
-
return groupTaggedItems(items, (item) => item.nested.tags);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
type Input = Parameters<typeof groupItems>[0];
|
|
128
|
-
type Output = ReturnType<typeof groupItems>;
|
|
129
|
-
|
|
130
|
-
test('should group items by tag permalink', () => {
|
|
131
|
-
const tagGuide = {label: 'Guide', permalink: '/guide'};
|
|
132
|
-
const tagTutorial = {label: 'Tutorial', permalink: '/tutorial'};
|
|
133
|
-
const tagAPI = {label: 'API', permalink: '/api'};
|
|
134
|
-
|
|
135
|
-
// This one will be grouped under same permalink and label is ignored
|
|
136
|
-
const tagTutorialOtherLabel = {
|
|
137
|
-
label: 'TutorialOtherLabel',
|
|
138
|
-
permalink: '/tutorial',
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const item1: SomeTaggedItem = {
|
|
142
|
-
id: '1',
|
|
143
|
-
nested: {
|
|
144
|
-
tags: [
|
|
145
|
-
tagGuide,
|
|
146
|
-
tagTutorial,
|
|
147
|
-
tagAPI,
|
|
148
|
-
// Add some duplicates on purpose: they should be filtered
|
|
149
|
-
tagGuide,
|
|
150
|
-
tagTutorialOtherLabel,
|
|
151
|
-
],
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
const item2: SomeTaggedItem = {
|
|
155
|
-
id: '2',
|
|
156
|
-
nested: {
|
|
157
|
-
tags: [tagAPI],
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
const item3: SomeTaggedItem = {
|
|
161
|
-
id: '3',
|
|
162
|
-
nested: {
|
|
163
|
-
tags: [tagTutorial],
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
const item4: SomeTaggedItem = {
|
|
167
|
-
id: '4',
|
|
168
|
-
nested: {
|
|
169
|
-
tags: [tagTutorialOtherLabel],
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const input: Input = [item1, item2, item3, item4];
|
|
174
|
-
|
|
175
|
-
const expectedOutput: Output = {
|
|
176
|
-
'/guide': {tag: tagGuide, items: [item1]},
|
|
177
|
-
'/tutorial': {tag: tagTutorial, items: [item1, item3, item4]},
|
|
178
|
-
'/api': {tag: tagAPI, items: [item1, item2]},
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
expect(groupItems(input)).toEqual(expectedOutput);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
@@ -1,33 +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 {getFileLoaderUtils} from '../webpackUtils';
|
|
9
|
-
|
|
10
|
-
describe('getFileLoaderUtils()', () => {
|
|
11
|
-
test('plugin svgo/removeViewBox should be disabled', () => {
|
|
12
|
-
const {oneOf} = getFileLoaderUtils().rules.svg();
|
|
13
|
-
expect(oneOf[0].use).toContainEqual(
|
|
14
|
-
expect.objectContaining({
|
|
15
|
-
loader: require.resolve('@svgr/webpack'),
|
|
16
|
-
options: expect.objectContaining({
|
|
17
|
-
svgoConfig: {
|
|
18
|
-
plugins: [
|
|
19
|
-
{
|
|
20
|
-
name: 'preset-default',
|
|
21
|
-
params: {
|
|
22
|
-
overrides: {
|
|
23
|
-
removeViewBox: false,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
});
|
package/src/escapePath.ts
DELETED
|
@@ -1,23 +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
|
-
/**
|
|
9
|
-
* When you have a path like C:\X\Y
|
|
10
|
-
* It is not safe to use directly when generating code
|
|
11
|
-
* For example, this would fail due to unescaped \: `<img src={require('${filePath}')} />`
|
|
12
|
-
* But this would work: `<img src={require('${escapePath(filePath)}')} />`
|
|
13
|
-
*
|
|
14
|
-
* Workaround for issue in posixPath, maybe we won't need it anymore soon?
|
|
15
|
-
* https://github.com/facebook/docusaurus/issues/4730#issuecomment-833530370
|
|
16
|
-
* https://github.com/sindresorhus/slash/pull/16#issuecomment-833528479
|
|
17
|
-
*/
|
|
18
|
-
export function escapePath(str: string): string {
|
|
19
|
-
const escaped = JSON.stringify(str);
|
|
20
|
-
|
|
21
|
-
// Remove the " around the json string;
|
|
22
|
-
return escaped.substring(1, escaped.length - 1);
|
|
23
|
-
}
|
package/src/mdxUtils.ts
DELETED
|
@@ -1,32 +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 React from 'react';
|
|
9
|
-
import ReactDOMServer from 'react-dom/server';
|
|
10
|
-
import MDX from '@mdx-js/runtime';
|
|
11
|
-
import removeImports from 'remark-mdx-remove-imports';
|
|
12
|
-
import removeExports from 'remark-mdx-remove-exports';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Transform mdx text to plain html text
|
|
16
|
-
* Initially created to convert MDX blog posts to HTML for the RSS feed
|
|
17
|
-
* without import/export nodes
|
|
18
|
-
*
|
|
19
|
-
* TODO not ideal implementation, won't work well with MDX elements!
|
|
20
|
-
* TODO theme+global site config should be able to declare MDX comps in scope for rendering the RSS feeds
|
|
21
|
-
* see also https://github.com/facebook/docusaurus/issues/4625
|
|
22
|
-
*/
|
|
23
|
-
export function mdxToHtml(
|
|
24
|
-
mdxStr: string,
|
|
25
|
-
// TODO allow providing components/scope here, see https://github.com/mdx-js/mdx/tree/v1.6.13/packages/runtime
|
|
26
|
-
): string {
|
|
27
|
-
return ReactDOMServer.renderToString(
|
|
28
|
-
React.createElement(MDX, {remarkPlugins: [removeImports, removeExports]}, [
|
|
29
|
-
mdxStr,
|
|
30
|
-
]),
|
|
31
|
-
);
|
|
32
|
-
}
|
package/src/posixPath.ts
DELETED
|
@@ -1,27 +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
|
-
/**
|
|
9
|
-
* Convert Windows backslash paths to posix style paths.
|
|
10
|
-
* E.g: endi\\lie -> endi/lie
|
|
11
|
-
*
|
|
12
|
-
* Looks like this code was originally copied from https://github.com/sindresorhus/slash/blob/main/index.js
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
export function posixPath(str: string): string {
|
|
16
|
-
const isExtendedLengthPath = /^\\\\\?\\/.test(str);
|
|
17
|
-
|
|
18
|
-
// TODO not sure why we need this
|
|
19
|
-
// See https://github.com/sindresorhus/slash/pull/16#issuecomment-833528479
|
|
20
|
-
// See https://github.com/facebook/docusaurus/issues/4730#issuecomment-833530370
|
|
21
|
-
const hasNonAscii = /[^\u0000-\u0080]+/.test(str); // eslint-disable-line
|
|
22
|
-
|
|
23
|
-
if (isExtendedLengthPath || hasNonAscii) {
|
|
24
|
-
return str;
|
|
25
|
-
}
|
|
26
|
-
return str.replace(/\\/g, '/');
|
|
27
|
-
}
|