@docusaurus/utils 2.0.0-beta.15 → 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.
- package/lib/dataFileUtils.js +2 -2
- package/lib/dataFileUtils.js.map +1 -1
- package/lib/gitUtils.d.ts +17 -0
- package/lib/gitUtils.d.ts.map +1 -0
- package/lib/gitUtils.js +63 -0
- package/lib/gitUtils.js.map +1 -0
- package/lib/hashUtils.js +4 -3
- package/lib/hashUtils.js.map +1 -1
- package/lib/index.d.ts +14 -12
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +75 -29
- package/lib/index.js.map +1 -1
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +8 -5
- package/lib/markdownLinks.js.map +1 -1
- package/lib/markdownParser.d.ts.map +1 -1
- package/lib/markdownParser.js +35 -35
- package/lib/markdownParser.js.map +1 -1
- package/lib/pathUtils.d.ts +14 -1
- package/lib/pathUtils.d.ts.map +1 -1
- package/lib/pathUtils.js +19 -11
- package/lib/pathUtils.js.map +1 -1
- package/lib/tags.d.ts +8 -0
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +18 -13
- package/lib/tags.js.map +1 -1
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +11 -10
- package/lib/urlUtils.js.map +1 -1
- package/lib/webpackUtils.d.ts.map +1 -1
- package/lib/webpackUtils.js +11 -9
- package/lib/webpackUtils.js.map +1 -1
- package/package.json +12 -20
- package/src/dataFileUtils.ts +2 -2
- package/src/deps.d.ts +0 -4
- package/src/gitUtils.ts +93 -0
- package/src/hashUtils.ts +3 -3
- package/src/index.ts +86 -32
- package/src/markdownLinks.ts +9 -5
- package/src/markdownParser.ts +35 -33
- package/src/pathUtils.ts +19 -11
- package/src/tags.ts +17 -13
- package/src/urlUtils.ts +11 -10
- package/src/webpackUtils.ts +11 -9
package/src/tags.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import _ from 'lodash';
|
|
9
9
|
import {normalizeUrl} from './urlUtils';
|
|
10
10
|
|
|
11
11
|
export type Tag = {
|
|
@@ -22,15 +22,15 @@ export function normalizeFrontMatterTag(
|
|
|
22
22
|
function toTagObject(tagString: string): Tag {
|
|
23
23
|
return {
|
|
24
24
|
label: tagString,
|
|
25
|
-
permalink: kebabCase(tagString),
|
|
25
|
+
permalink: _.kebabCase(tagString),
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// TODO maybe make ensure the permalink is valid url path?
|
|
30
30
|
function normalizeTagPermalink(permalink: string): string {
|
|
31
|
-
// note: we always apply tagsPath on purpose
|
|
32
|
-
//
|
|
33
|
-
// tagsPath is different for each doc version
|
|
31
|
+
// note: we always apply tagsPath on purpose. For versioned docs, v1/doc.md
|
|
32
|
+
// and v2/doc.md tags with custom permalinks don't lead to the same created
|
|
33
|
+
// page. tagsPath is different for each doc version
|
|
34
34
|
return normalizeUrl([tagsPath, permalink]);
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -53,7 +53,7 @@ export function normalizeFrontMatterTags(
|
|
|
53
53
|
normalizeFrontMatterTag(tagsPath, tag),
|
|
54
54
|
);
|
|
55
55
|
|
|
56
|
-
return uniqBy(tags, (tag) => tag.permalink);
|
|
56
|
+
return _.uniqBy(tags, (tag) => tag.permalink);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export type TaggedItemGroup<Item> = {
|
|
@@ -61,11 +61,14 @@ export type TaggedItemGroup<Item> = {
|
|
|
61
61
|
items: Item[];
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Permits to group docs/blogPosts by tag (provided by front matter)
|
|
66
|
+
* Note: groups are indexed by permalink, because routes must be unique in the
|
|
67
|
+
* end. Labels may vary on 2 md files but they are normalized. Docs with
|
|
68
|
+
* label='some label' and label='some-label' should end-up in the same
|
|
69
|
+
* group/page in the end. We can't create 2 routes /some-label because one would
|
|
70
|
+
* override the other
|
|
71
|
+
*/
|
|
69
72
|
export function groupTaggedItems<Item>(
|
|
70
73
|
items: Item[],
|
|
71
74
|
getItemTags: (item: Item) => Tag[],
|
|
@@ -74,7 +77,8 @@ export function groupTaggedItems<Item>(
|
|
|
74
77
|
|
|
75
78
|
function handleItemTag(item: Item, tag: Tag) {
|
|
76
79
|
// Init missing tag groups
|
|
77
|
-
// TODO: it's not really clear what should be the behavior if 2 items have
|
|
80
|
+
// TODO: it's not really clear what should be the behavior if 2 items have
|
|
81
|
+
// the same tag but the permalink is different for each
|
|
78
82
|
// For now, the first tag found wins
|
|
79
83
|
result[tag.permalink] = result[tag.permalink] ?? {
|
|
80
84
|
tag,
|
|
@@ -94,7 +98,7 @@ export function groupTaggedItems<Item>(
|
|
|
94
98
|
// If user add twice the same tag to a md doc (weird but possible),
|
|
95
99
|
// we don't want the item to appear twice in the list...
|
|
96
100
|
Object.values(result).forEach((group) => {
|
|
97
|
-
group.items = uniq(group.items);
|
|
101
|
+
group.items = _.uniq(group.items);
|
|
98
102
|
});
|
|
99
103
|
|
|
100
104
|
return result;
|
package/src/urlUtils.ts
CHANGED
|
@@ -16,7 +16,8 @@ export function normalizeUrl(rawUrls: string[]): string {
|
|
|
16
16
|
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
|
|
17
17
|
const first = urls.shift();
|
|
18
18
|
if (first!.startsWith('file:') && urls[0].startsWith('/')) {
|
|
19
|
-
// Force a double slash here, else we lose the information that the next
|
|
19
|
+
// Force a double slash here, else we lose the information that the next
|
|
20
|
+
// segment is an absolute path
|
|
20
21
|
urls[0] = `${first}//${urls[0]}`;
|
|
21
22
|
} else {
|
|
22
23
|
urls[0] = first + urls[0];
|
|
@@ -26,10 +27,9 @@ export function normalizeUrl(rawUrls: string[]): string {
|
|
|
26
27
|
// There must be two or three slashes in the file protocol,
|
|
27
28
|
// two slashes in anything else.
|
|
28
29
|
const replacement = urls[0].match(/^file:\/\/\//) ? '$1:///' : '$1://';
|
|
29
|
-
urls[0] = urls[0].replace(/^([^/:]+):\/*/, replacement);
|
|
30
|
+
urls[0] = urls[0].replace(/^(?<protocol>[^/:]+):\/*/, replacement);
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
for (let i = 0; i < urls.length; i++) {
|
|
32
|
+
for (let i = 0; i < urls.length; i += 1) {
|
|
33
33
|
let component = urls[i];
|
|
34
34
|
|
|
35
35
|
if (typeof component !== 'string') {
|
|
@@ -40,7 +40,7 @@ export function normalizeUrl(rawUrls: string[]): string {
|
|
|
40
40
|
if (i === urls.length - 1 && hasEndingSlash) {
|
|
41
41
|
resultArray.push('/');
|
|
42
42
|
}
|
|
43
|
-
// eslint-disable-next-line
|
|
43
|
+
// eslint-disable-next-line no-continue
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -49,14 +49,15 @@ export function normalizeUrl(rawUrls: string[]): string {
|
|
|
49
49
|
// Removing the starting slashes for each component but the first.
|
|
50
50
|
component = component.replace(
|
|
51
51
|
/^[/]+/,
|
|
52
|
-
// Special case where the first element of rawUrls is empty
|
|
52
|
+
// Special case where the first element of rawUrls is empty
|
|
53
|
+
// ["", "/hello"] => /hello
|
|
53
54
|
component[0] === '/' && !hasStartingSlash ? '/' : '',
|
|
54
55
|
);
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
hasEndingSlash = component[component.length - 1] === '/';
|
|
58
|
-
// Removing the ending slashes for each component but the last.
|
|
59
|
-
//
|
|
59
|
+
// Removing the ending slashes for each component but the last. For the
|
|
60
|
+
// last component we will combine multiple slashes to a single one.
|
|
60
61
|
component = component.replace(/[/]+$/, i < urls.length - 1 ? '' : '/');
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -69,14 +70,14 @@ export function normalizeUrl(rawUrls: string[]): string {
|
|
|
69
70
|
// except the possible first plain protocol part.
|
|
70
71
|
|
|
71
72
|
// Remove trailing slash before parameters or hash.
|
|
72
|
-
str = str.replace(/\/(
|
|
73
|
+
str = str.replace(/\/(?<search>\?|&|#[^!])/g, '$1');
|
|
73
74
|
|
|
74
75
|
// Replace ? in parameters with &.
|
|
75
76
|
const parts = str.split('?');
|
|
76
77
|
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
|
|
77
78
|
|
|
78
79
|
// Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
79
|
-
str = str.replace(/([^:/]\/)\/+/g, '$1');
|
|
80
|
+
str = str.replace(/(?<textBefore>[^:/]\/)\/+/g, '$1');
|
|
80
81
|
|
|
81
82
|
// Dedupe forward slashes at the beginning of the path.
|
|
82
83
|
str = str.replace(/^\/+/g, '/');
|
package/src/webpackUtils.ts
CHANGED
|
@@ -33,12 +33,13 @@ type FileLoaderUtils = {
|
|
|
33
33
|
|
|
34
34
|
// Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
|
|
35
35
|
export function getFileLoaderUtils(): FileLoaderUtils {
|
|
36
|
-
// files/images < urlLoaderLimit will be inlined as base64 strings directly in
|
|
36
|
+
// files/images < urlLoaderLimit will be inlined as base64 strings directly in
|
|
37
|
+
// the html
|
|
37
38
|
const urlLoaderLimit = WEBPACK_URL_LOADER_LIMIT;
|
|
38
39
|
|
|
39
40
|
// defines the path/pattern of the assets handled by webpack
|
|
40
41
|
const fileLoaderFileName = (folder: AssetFolder) =>
|
|
41
|
-
`${OUTPUT_STATIC_ASSETS_DIR_NAME}/${folder}/[name]-[
|
|
42
|
+
`${OUTPUT_STATIC_ASSETS_DIR_NAME}/${folder}/[name]-[contenthash].[ext]`;
|
|
42
43
|
|
|
43
44
|
const loaders: FileLoaderUtils['loaders'] = {
|
|
44
45
|
file: (options: {folder: AssetFolder}) => ({
|
|
@@ -56,7 +57,7 @@ export function getFileLoaderUtils(): FileLoaderUtils {
|
|
|
56
57
|
},
|
|
57
58
|
}),
|
|
58
59
|
|
|
59
|
-
// TODO
|
|
60
|
+
// TODO avoid conflicts with the ideal-image plugin
|
|
60
61
|
// TODO this may require a little breaking change for ideal-image users?
|
|
61
62
|
// Maybe with the ideal image plugin, all md images should be "ideal"?
|
|
62
63
|
// This is used to force url-loader+file-loader on markdown images
|
|
@@ -78,12 +79,12 @@ export function getFileLoaderUtils(): FileLoaderUtils {
|
|
|
78
79
|
*/
|
|
79
80
|
images: () => ({
|
|
80
81
|
use: [loaders.url({folder: 'images'})],
|
|
81
|
-
test: /\.(ico|
|
|
82
|
+
test: /\.(?:ico|jpe?g|png|gif|webp)(?:\?.*)?$/i,
|
|
82
83
|
}),
|
|
83
84
|
|
|
84
85
|
fonts: () => ({
|
|
85
86
|
use: [loaders.url({folder: 'fonts'})],
|
|
86
|
-
test: /\.(
|
|
87
|
+
test: /\.(?:woff2?|eot|ttf|otf)$/i,
|
|
87
88
|
}),
|
|
88
89
|
|
|
89
90
|
/**
|
|
@@ -92,11 +93,11 @@ export function getFileLoaderUtils(): FileLoaderUtils {
|
|
|
92
93
|
*/
|
|
93
94
|
media: () => ({
|
|
94
95
|
use: [loaders.url({folder: 'medias'})],
|
|
95
|
-
test: /\.(mp4|webm|ogv|wav|mp3|m4a|aac|oga|flac)
|
|
96
|
+
test: /\.(?:mp4|webm|ogv|wav|mp3|m4a|aac|oga|flac)$/i,
|
|
96
97
|
}),
|
|
97
98
|
|
|
98
99
|
svg: () => ({
|
|
99
|
-
test: /\.svg
|
|
100
|
+
test: /\.svg$/i,
|
|
100
101
|
oneOf: [
|
|
101
102
|
{
|
|
102
103
|
use: [
|
|
@@ -111,6 +112,7 @@ export function getFileLoaderUtils(): FileLoaderUtils {
|
|
|
111
112
|
name: 'preset-default',
|
|
112
113
|
params: {
|
|
113
114
|
overrides: {
|
|
115
|
+
removeTitle: false,
|
|
114
116
|
removeViewBox: false,
|
|
115
117
|
},
|
|
116
118
|
},
|
|
@@ -125,7 +127,7 @@ export function getFileLoaderUtils(): FileLoaderUtils {
|
|
|
125
127
|
// We don't want to use SVGR loader for non-React source code
|
|
126
128
|
// ie we don't want to use SVGR for CSS files...
|
|
127
129
|
issuer: {
|
|
128
|
-
and: [/\.(
|
|
130
|
+
and: [/\.(?:tsx?|jsx?|mdx?)$/i],
|
|
129
131
|
},
|
|
130
132
|
},
|
|
131
133
|
{
|
|
@@ -136,7 +138,7 @@ export function getFileLoaderUtils(): FileLoaderUtils {
|
|
|
136
138
|
|
|
137
139
|
otherAssets: () => ({
|
|
138
140
|
use: [loaders.file({folder: 'files'})],
|
|
139
|
-
test: /\.(pdf|
|
|
141
|
+
test: /\.(?:pdf|docx?|xlsx?|zip|rar)$/i,
|
|
140
142
|
}),
|
|
141
143
|
};
|
|
142
144
|
|