@uxfront/layer-docs 0.9.0 → 0.9.1

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.
@@ -17,5 +17,6 @@ const { enabled } = useFrameworkRoute();
17
17
 
18
18
  <template>
19
19
  <FrameworkSearch v-if="enabled" :navigation="navigation" />
20
- <DocusAppSearch v-else :navigation="navigation" />
20
+ <!-- Docus's search takes no null, and reads a missing navigation as none. -->
21
+ <DocusAppSearch v-else :navigation="navigation ?? undefined" />
21
22
  </template>
@@ -1,10 +1,11 @@
1
1
  import { existsSync, realpathSync } from "node:fs";
2
2
  import { createRequire } from "node:module";
3
- import { dirname, join } from "node:path";
3
+ import { dirname, join, relative } from "node:path";
4
4
 
5
5
  import {
6
6
  addServerHandler,
7
7
  addServerImports,
8
+ addTypeTemplate,
8
9
  createResolver,
9
10
  defineNuxtModule,
10
11
  extendPages,
@@ -17,9 +18,12 @@ import {
17
18
  frameworkRoutePath,
18
19
  isUnprefixedDocsPath,
19
20
  keepsLayerSitemap,
21
+ type FrameworkUrlsRuntimeConfig,
20
22
  type ScannedHandler,
21
23
  } from "./utils";
22
24
 
25
+ export type { FrameworkUrlsRuntimeConfig };
26
+
23
27
  /** `frameworkUrls` in `nuxt.config.ts`. */
24
28
  export interface FrameworkUrlsOptions {
25
29
  /**
@@ -29,14 +33,9 @@ export interface FrameworkUrlsOptions {
29
33
  enabled?: boolean;
30
34
  }
31
35
 
32
- /** What the module passes to the app and the server at runtime, with framework URLs on. */
33
- export interface FrameworkUrlsRuntimeConfig {
34
- /** The values of `docsTheme.frameworks`, in order, as the build read them. */
35
- frameworks: string[];
36
- /** The site's URL, for the absolute URLs in the sitemap. */
37
- siteUrl?: string;
38
- }
39
-
36
+ // For `nuxt.config.ts`. The type of `useRuntimeConfig().public.docsFrameworkUrls`
37
+ // is a type template instead, written in `setup`: Nuxt leaves this file out of
38
+ // the app and server contexts, and `useRuntimeConfig()` reads `nuxt/schema`.
40
39
  declare module "@nuxt/schema" {
41
40
  interface NuxtConfig {
42
41
  frameworkUrls?: FrameworkUrlsOptions;
@@ -44,9 +43,6 @@ declare module "@nuxt/schema" {
44
43
  interface NuxtOptions {
45
44
  frameworkUrls?: FrameworkUrlsOptions;
46
45
  }
47
- interface PublicRuntimeConfig {
48
- docsFrameworkUrls?: FrameworkUrlsRuntimeConfig;
49
- }
50
46
  }
51
47
 
52
48
  /** The route the prerenderer asks for the list of docs pages. It's never written to disk. */
@@ -129,6 +125,34 @@ export default defineNuxtModule<FrameworkUrlsOptions>({
129
125
  { name: "docsPageFrameworks", from: resolve("./runtime/server/helpers") },
130
126
  ]);
131
127
 
128
+ // Types `useRuntimeConfig().public.docsFrameworkUrls` in the app and on the
129
+ // server, with framework URLs off too, so the layer's own files type-check
130
+ // inside every site. Nuxt's generated `PublicRuntimeConfig` lives in
131
+ // `nuxt/schema` and shadows the one in `@nuxt/schema`, so the type goes there.
132
+ const utilsPath = resolve("./utils");
133
+ addTypeTemplate(
134
+ {
135
+ filename: "types/layer-docs-framework-urls.d.ts",
136
+ getContents: ({ nuxt }) => {
137
+ const from = relative(join(nuxt.options.buildDir, "types"), utilsPath).replaceAll(
138
+ "\\",
139
+ "/",
140
+ );
141
+ return [
142
+ `import type { FrameworkUrlsRuntimeConfig } from ${JSON.stringify(from.startsWith(".") ? from : `./${from}`)};`,
143
+ "",
144
+ 'declare module "nuxt/schema" {',
145
+ " interface PublicRuntimeConfig {",
146
+ " docsFrameworkUrls?: FrameworkUrlsRuntimeConfig;",
147
+ " }",
148
+ "}",
149
+ "",
150
+ ].join("\n");
151
+ },
152
+ },
153
+ { nuxt: true, nitro: true },
154
+ );
155
+
132
156
  if (!options.enabled) return;
133
157
 
134
158
  const rootDir = nuxt.options.rootDir;
@@ -1,4 +1,8 @@
1
- import { createError, defineEventHandler, queryCollection } from "#imports";
1
+ // h3's helpers come from h3: Nuxt's typed route list loads this file in the app
2
+ // context too, where `#imports` doesn't have them.
3
+ import { createError, defineEventHandler } from "h3";
4
+
5
+ import { queryCollection } from "#imports";
2
6
 
3
7
  import { isNavigationPath } from "../../utils";
4
8
 
@@ -1,4 +1,8 @@
1
- import { defineEventHandler, setResponseHeader, useRuntimeConfig } from "#imports";
1
+ // h3's helpers come from h3: Nuxt's typed route list loads this file in the app
2
+ // context too, where `#imports` doesn't have them.
3
+ import { defineEventHandler, setResponseHeader } from "h3";
4
+
5
+ import { useRuntimeConfig } from "#imports";
2
6
 
3
7
  import { sitemapXml } from "../../utils";
4
8
  import { getDocsSitemapEntries } from "./helpers";
@@ -30,6 +30,17 @@ interface Toc {
30
30
  [key: string]: unknown;
31
31
  }
32
32
 
33
+ /**
34
+ * What the module passes to the app and the server at runtime, with framework
35
+ * URLs on, as `useRuntimeConfig().public.docsFrameworkUrls`.
36
+ */
37
+ export interface FrameworkUrlsRuntimeConfig {
38
+ /** The values of `docsTheme.frameworks`, in order, as the build read them. */
39
+ frameworks: string[];
40
+ /** The site's URL, for the absolute URLs in the sitemap. */
41
+ siteUrl?: string;
42
+ }
43
+
33
44
  /** A navigation item, as Nuxt Content builds them. */
34
45
  export interface NavigationItem {
35
46
  title: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxfront/layer-docs",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Nuxt layer for UXFront documentation sites: Docus, plus a framework switcher that shows every reader the examples for their framework, and the UXFront header wordmark.",
5
5
  "keywords": [
6
6
  "docs",