@lukoweb/apitogo 0.2.14 → 0.2.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/dist/cli/cli.js
CHANGED
|
@@ -31,4 +31,5 @@ export type MDXImport = {
|
|
|
31
31
|
__filepath: string;
|
|
32
32
|
default: (props: MDXProps) => JSX.Element;
|
|
33
33
|
};
|
|
34
|
+
export declare const withIndexAliases: <T>(fileImports: Record<string, T>) => [string, T][];
|
|
34
35
|
export declare const markdownPlugin: (options: MarkdownPluginOptions) => ApitogoPlugin;
|
package/package.json
CHANGED
|
@@ -35,11 +35,31 @@ export type MDXImport = {
|
|
|
35
35
|
default: (props: MDXProps) => JSX.Element;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
const INDEX_SUFFIX = "/index";
|
|
39
|
+
|
|
40
|
+
// `index.mdx` is the page of its folder: `/index` also answers at `/`, `/guides/index` at `/guides`.
|
|
41
|
+
// Without this the browser has no route for `/` (the pre-built index.html only hides that on first load).
|
|
42
|
+
export const withIndexAliases = <T,>(
|
|
43
|
+
fileImports: Record<string, T>,
|
|
44
|
+
): [string, T][] => {
|
|
45
|
+
const entries = Object.entries(fileImports);
|
|
46
|
+
return entries.flatMap(([routePath, value]): [string, T][] => {
|
|
47
|
+
if (!routePath.endsWith(INDEX_SUFFIX)) return [[routePath, value]];
|
|
48
|
+
const alias = routePath.slice(0, -INDEX_SUFFIX.length) || "/";
|
|
49
|
+
return alias in fileImports
|
|
50
|
+
? [[routePath, value]]
|
|
51
|
+
: [
|
|
52
|
+
[routePath, value],
|
|
53
|
+
[alias, value],
|
|
54
|
+
];
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
38
58
|
export const markdownPlugin = (
|
|
39
59
|
options: MarkdownPluginOptions,
|
|
40
60
|
): ApitogoPlugin => ({
|
|
41
61
|
getRoutes: () => {
|
|
42
|
-
return
|
|
62
|
+
return withIndexAliases(options.fileImports).map(
|
|
43
63
|
([routePath, importPromise]) => ({
|
|
44
64
|
path: routePath,
|
|
45
65
|
lazy: async () => {
|