dumi 2.0.0-beta.8 → 2.0.0-beta.9
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/dist/client/theme-api/useSiteSearch.js +47 -31
- package/dist/features/configPlugins/schema.js +2 -1
- package/dist/features/meta.js +1 -1
- package/dist/features/routes.js +2 -1
- package/dist/features/tabs.js +1 -1
- package/dist/features/theme/index.js +1 -1
- package/dist/loaders/markdown/transformer/rehypeText.js +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
1
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
8
|
|
|
3
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -71,7 +77,7 @@ function generateSearchMetadata(routes, demos, nav) {
|
|
|
71
77
|
var _demosMapping$route$i;
|
|
72
78
|
|
|
73
79
|
var routeMeta = route.meta;
|
|
74
|
-
var routeAbsPath = route.path.replace(/^([^/])/, '/$1');
|
|
80
|
+
var routeAbsPath = route.path.replace(/^([^/])/, '/$1') || '/';
|
|
75
81
|
var routeNav = nav.find(function (item) {
|
|
76
82
|
return routeAbsPath === item.link || routeAbsPath.startsWith("".concat(item.activePath, "/"));
|
|
77
83
|
});
|
|
@@ -81,17 +87,17 @@ function generateSearchMetadata(routes, demos, nav) {
|
|
|
81
87
|
return (_demo$asset = demo.asset) === null || _demo$asset === void 0 ? void 0 : _demo$asset.id;
|
|
82
88
|
});
|
|
83
89
|
var orphanSection = createMetadataSection('', routeMeta.frontmatter.title, routeAbsPath, routeMeta.texts);
|
|
84
|
-
var tocSections = routeMeta.toc
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
});
|
|
92
|
-
var tabSections = (routeMeta.tabs || []).reduce(function (acc,
|
|
93
|
-
var key =
|
|
94
|
-
meta =
|
|
90
|
+
var tocSections = routeMeta.toc.reduce(function (acc, toc, i) {
|
|
91
|
+
// exclude demo id, to avoid duplicate
|
|
92
|
+
if (!demoIds.includes(toc.id) && toc.depth > 1) {
|
|
93
|
+
acc.push(createMetadataSection(toc.title, "".concat(routeMeta.frontmatter.title, " - ").concat(toc.title), "".concat(routeAbsPath, "#").concat(toc.id), routeMeta.texts, i));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return acc;
|
|
97
|
+
}, []);
|
|
98
|
+
var tabSections = (routeMeta.tabs || []).reduce(function (acc, _ref) {
|
|
99
|
+
var key = _ref.key,
|
|
100
|
+
meta = _ref.meta;
|
|
95
101
|
// collect orphan section that not in toc
|
|
96
102
|
var tabOrphanSection = createMetadataSection('', "".concat(routeMeta.frontmatter.title, " - ").concat(meta.frontmatter.title), "".concat(routeAbsPath, "?").concat(TAB_QUERY_KEY, "=").concat(key), meta.texts);
|
|
97
103
|
if (tabOrphanSection) acc.push(tabOrphanSection); // collect sections by toc
|
|
@@ -129,11 +135,13 @@ function generateHighlightTexts() {
|
|
|
129
135
|
textToHighlight: str,
|
|
130
136
|
searchWords: keywords,
|
|
131
137
|
autoEscape: true
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
}); // save matched keywords
|
|
139
|
+
|
|
140
|
+
var matchedMapping = {};
|
|
141
|
+
return [chunks.map(function (_ref2, i) {
|
|
142
|
+
var start = _ref2.start,
|
|
143
|
+
end = _ref2.end,
|
|
144
|
+
highlight = _ref2.highlight;
|
|
137
145
|
var highlightText = {
|
|
138
146
|
text: str.slice(start, end)
|
|
139
147
|
}; // omit long str before the first highlighted text
|
|
@@ -145,10 +153,13 @@ function generateHighlightTexts() {
|
|
|
145
153
|
|
|
146
154
|
if (highlight) {
|
|
147
155
|
highlightText.highlighted = true;
|
|
156
|
+
matchedMapping[keywords.find(function (k) {
|
|
157
|
+
return highlightText.text.includes(k);
|
|
158
|
+
})] = true;
|
|
148
159
|
}
|
|
149
160
|
|
|
150
161
|
return highlightText;
|
|
151
|
-
}),
|
|
162
|
+
}), matchedMapping];
|
|
152
163
|
}
|
|
153
164
|
|
|
154
165
|
function generateSearchResult(metadata, keywordsStr) {
|
|
@@ -172,17 +183,17 @@ function generateSearchResult(metadata, keywordsStr) {
|
|
|
172
183
|
var _generateHighlightTex3 = generateHighlightTexts(sec.title, keywords),
|
|
173
184
|
_generateHighlightTex4 = _slicedToArray(_generateHighlightTex3, 2),
|
|
174
185
|
_highlightTitleTexts = _generateHighlightTex4[0],
|
|
175
|
-
|
|
186
|
+
_titleMatchMapping = _generateHighlightTex4[1];
|
|
176
187
|
|
|
177
188
|
var _generateHighlightTex5 = generateHighlightTexts(p, keywords),
|
|
178
189
|
_generateHighlightTex6 = _slicedToArray(_generateHighlightTex5, 2),
|
|
179
190
|
highlightTexts = _generateHighlightTex6[0],
|
|
180
|
-
|
|
191
|
+
matchMapping = _generateHighlightTex6[1];
|
|
181
192
|
|
|
182
193
|
hints.push({
|
|
183
194
|
type: 'content',
|
|
184
195
|
link: sec.link,
|
|
185
|
-
priority:
|
|
196
|
+
priority: Object.keys(_objectSpread(_objectSpread({}, _titleMatchMapping), matchMapping)).length,
|
|
186
197
|
highlightTitleTexts: _highlightTitleTexts,
|
|
187
198
|
highlightTexts: highlightTexts
|
|
188
199
|
}); // match at most once in the same section
|
|
@@ -201,12 +212,12 @@ function generateSearchResult(metadata, keywordsStr) {
|
|
|
201
212
|
var _generateHighlightTex = generateHighlightTexts(sec.title, keywords),
|
|
202
213
|
_generateHighlightTex2 = _slicedToArray(_generateHighlightTex, 2),
|
|
203
214
|
highlightTitleTexts = _generateHighlightTex2[0],
|
|
204
|
-
|
|
215
|
+
titleMatchMapping = _generateHighlightTex2[1];
|
|
205
216
|
|
|
206
217
|
hints.push({
|
|
207
218
|
type: 'title',
|
|
208
219
|
link: sec.link,
|
|
209
|
-
priority:
|
|
220
|
+
priority: Object.keys(titleMatchMapping).length,
|
|
210
221
|
highlightTitleTexts: highlightTitleTexts,
|
|
211
222
|
highlightTexts: generateHighlightTexts(sec.paragraphs[0] || '', keywords)[0]
|
|
212
223
|
});
|
|
@@ -218,17 +229,17 @@ function generateSearchResult(metadata, keywordsStr) {
|
|
|
218
229
|
var _generateHighlightTex7 = generateHighlightTexts(demo.title, keywords),
|
|
219
230
|
_generateHighlightTex8 = _slicedToArray(_generateHighlightTex7, 2),
|
|
220
231
|
highlightTitleTexts = _generateHighlightTex8[0],
|
|
221
|
-
|
|
232
|
+
titleMatchMapping = _generateHighlightTex8[1];
|
|
222
233
|
|
|
223
234
|
var _generateHighlightTex9 = generateHighlightTexts(demo.description, keywords),
|
|
224
235
|
_generateHighlightTex10 = _slicedToArray(_generateHighlightTex9, 2),
|
|
225
236
|
highlightTexts = _generateHighlightTex10[0],
|
|
226
|
-
|
|
237
|
+
matchMapping = _generateHighlightTex10[1];
|
|
227
238
|
|
|
228
239
|
hints.push({
|
|
229
240
|
type: 'demo',
|
|
230
241
|
link: demo.link,
|
|
231
|
-
priority:
|
|
242
|
+
priority: Object.keys(_objectSpread(_objectSpread({}, titleMatchMapping), matchMapping)).length,
|
|
232
243
|
highlightTitleTexts: highlightTitleTexts,
|
|
233
244
|
highlightTexts: highlightTexts
|
|
234
245
|
});
|
|
@@ -241,12 +252,12 @@ function generateSearchResult(metadata, keywordsStr) {
|
|
|
241
252
|
var _generateHighlightTex11 = generateHighlightTexts(data.title, keywords),
|
|
242
253
|
_generateHighlightTex12 = _slicedToArray(_generateHighlightTex11, 2),
|
|
243
254
|
highlightTitleTexts = _generateHighlightTex12[0],
|
|
244
|
-
|
|
255
|
+
titleMatchMapping = _generateHighlightTex12[1];
|
|
245
256
|
|
|
246
257
|
hints.push({
|
|
247
258
|
type: 'page',
|
|
248
259
|
link: data.link,
|
|
249
|
-
priority:
|
|
260
|
+
priority: Object.keys(titleMatchMapping).length,
|
|
250
261
|
highlightTitleTexts: highlightTitleTexts,
|
|
251
262
|
highlightTexts: generateHighlightTexts(((_data$sections$ = data.sections[0]) === null || _data$sections$ === void 0 ? void 0 : _data$sections$.paragraphs[0]) || '', keywords)[0]
|
|
252
263
|
});
|
|
@@ -263,10 +274,15 @@ function generateSearchResult(metadata, keywordsStr) {
|
|
|
263
274
|
hints: []
|
|
264
275
|
};
|
|
265
276
|
|
|
266
|
-
(_resultMapping$key$hi = resultMapping[key].hints).push.apply(_resultMapping$key$hi,
|
|
267
|
-
return next.priority - prev.priority;
|
|
268
|
-
})));
|
|
277
|
+
(_resultMapping$key$hi = resultMapping[key].hints).push.apply(_resultMapping$key$hi, hints);
|
|
269
278
|
}
|
|
279
|
+
}); // sort hints
|
|
280
|
+
|
|
281
|
+
Object.values(resultMapping).forEach(function (_ref3) {
|
|
282
|
+
var hints = _ref3.hints;
|
|
283
|
+
hints.sort(function (prev, next) {
|
|
284
|
+
return next.priority - prev.priority;
|
|
285
|
+
});
|
|
270
286
|
});
|
|
271
287
|
return Object.values(resultMapping).sort(function (prev, next) {
|
|
272
288
|
return next.priority - prev.priority;
|
|
@@ -36,7 +36,8 @@ function getSchemas() {
|
|
|
36
36
|
}).optional(),
|
|
37
37
|
extraRemarkPlugins: getUnifiedPluginSchema,
|
|
38
38
|
extraRehypePlugins: getUnifiedPluginSchema,
|
|
39
|
-
themeConfig: (Joi) => Joi.object().optional()
|
|
39
|
+
themeConfig: (Joi) => Joi.object().optional(),
|
|
40
|
+
logo: (Joi) => Joi.string()
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/features/meta.js
CHANGED
|
@@ -40,7 +40,7 @@ var meta_default = (api) => {
|
|
|
40
40
|
fn: (routes) => {
|
|
41
41
|
metaFiles.length = 0;
|
|
42
42
|
Object.values(routes).forEach((route) => {
|
|
43
|
-
if (!route.isLayout && !/\*|:/.test(route.path) && !(0, import_tabs.isTabRouteFile)(route.file)) {
|
|
43
|
+
if (!route.isLayout && !/\*|:/.test(route.path) && route.file && !(0, import_tabs.isTabRouteFile)(route.file)) {
|
|
44
44
|
metaFiles.push({
|
|
45
45
|
index: metaFiles.length,
|
|
46
46
|
file: route.file,
|
package/dist/features/routes.js
CHANGED
|
@@ -113,7 +113,7 @@ var routes_default = (api) => {
|
|
|
113
113
|
Object.entries(pages).forEach(([, route]) => {
|
|
114
114
|
route.parentId = docLayoutId;
|
|
115
115
|
route.file = (0, import_plugin_utils.winPath)(import_path.default.resolve(pagesDir, route.file));
|
|
116
|
-
|
|
116
|
+
route.path = route.absPath.slice(1);
|
|
117
117
|
});
|
|
118
118
|
docDirs.map(normalizeDocDir).forEach(({ type, dir }) => {
|
|
119
119
|
const base = import_path.default.join(api.cwd, dir);
|
|
@@ -124,6 +124,7 @@ var routes_default = (api) => {
|
|
|
124
124
|
Object.entries(dirRoutes).forEach(([key, route]) => {
|
|
125
125
|
route.id = `${dir}/${key}`;
|
|
126
126
|
route.parentId = docLayoutId;
|
|
127
|
+
route.path = route.absPath.slice(1);
|
|
127
128
|
if (type) {
|
|
128
129
|
const pluralType = (0, import_pluralize.plural)(type);
|
|
129
130
|
route.path = `${pluralType}/${route.path}`.replace(/\/+$/, "/");
|
package/dist/features/tabs.js
CHANGED
|
@@ -54,7 +54,7 @@ var tabs_default = (api) => {
|
|
|
54
54
|
api.modifyRoutes((routes) => {
|
|
55
55
|
tabs.length = 0;
|
|
56
56
|
Object.values(routes).forEach((route) => {
|
|
57
|
-
if (isTabRouteFile(route.file)) {
|
|
57
|
+
if (route.file && isTabRouteFile(route.file)) {
|
|
58
58
|
delete routes[route.id];
|
|
59
59
|
const rtlFile = (0, import_plugin_utils.winPath)(import_path.default.relative(api.cwd, route.file));
|
|
60
60
|
const routeId = (0, import_utils.createRouteId)(rtlFile);
|
|
@@ -134,7 +134,7 @@ export default function DumiContextWrapper() {
|
|
|
134
134
|
locales,
|
|
135
135
|
loading,
|
|
136
136
|
setLoading,
|
|
137
|
-
themeConfig: ${JSON.stringify(api.config.themeConfig)},
|
|
137
|
+
themeConfig: ${JSON.stringify(Object.assign(import_plugin_utils.lodash.pick(api.config, "logo", "description", "title"), api.config.themeConfig))},
|
|
138
138
|
}}>
|
|
139
139
|
{outlet}
|
|
140
140
|
</SiteContext.Provider>
|
|
@@ -44,7 +44,7 @@ function findClosestTitle(ancestors, node) {
|
|
|
44
44
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
45
45
|
const parent = ancestors[i];
|
|
46
46
|
const current = ancestors[i + 1] || node;
|
|
47
|
-
for (let i2 = parent.children.indexOf(current) - 1; i2 >= 0; i2
|
|
47
|
+
for (let i2 = parent.children.indexOf(current) - 1; i2 >= 0; i2--) {
|
|
48
48
|
const child = parent.children[i2];
|
|
49
49
|
if (child.type === "element" && import_rehypeSlug.HEADING_TAGS.includes(child.tagName)) {
|
|
50
50
|
return child;
|