@lukoweb/apitogo 0.2.13 → 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
@@ -9663,7 +9663,7 @@ import {
9663
9663
  // package.json
9664
9664
  var package_default = {
9665
9665
  name: "@lukoweb/apitogo",
9666
- version: "0.2.13",
9666
+ version: "0.2.15",
9667
9667
  type: "module",
9668
9668
  sideEffects: [
9669
9669
  "**/*.css",
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "**/*.css",
@@ -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 Object.entries(options.fileImports).map(
62
+ return withIndexAliases(options.fileImports).map(
43
63
  ([routePath, importPromise]) => ({
44
64
  path: routePath,
45
65
  lazy: async () => {