@uxfront/layer-docs 0.8.4 → 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.
- package/README.md +90 -1
- package/app/components/app/AppHeaderBody.vue +15 -2
- package/app/components/app/AppHeaderLinks.vue +6 -2
- package/app/components/app/AppSearch.vue +22 -0
- package/app/components/docs/DocsAsideLeftBody.vue +23 -0
- package/app/composables/useFramework.ts +27 -1
- package/app/internal/FrameworkSearch.vue +97 -0
- package/app/internal/frameworkRoute.ts +39 -0
- package/app/utils/frameworkUrls.ts +31 -0
- package/modules/framework-urls/index.ts +272 -0
- package/modules/framework-urls/runtime/landing.vue +57 -0
- package/modules/framework-urls/runtime/page.vue +211 -0
- package/modules/framework-urls/runtime/server/helpers.ts +49 -0
- package/modules/framework-urls/runtime/server/raw.ts +30 -0
- package/modules/framework-urls/runtime/server/routes.ts +26 -0
- package/modules/framework-urls/runtime/server/sitemap.ts +19 -0
- package/modules/framework-urls/utils.ts +418 -0
- package/nuxt.config.ts +15 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -163,6 +163,93 @@ export default defineNuxtConfig({
|
|
|
163
163
|
});
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
+
## Framework URLs
|
|
167
|
+
|
|
168
|
+
By default, every docs page has one URL for all your frameworks, and the reader's pick lives in their browser. So search engines only ever see the first framework's examples, and a link someone shares opens on whatever the next reader picked last. Framework URLs give each page its own URL for each framework, like `/docs/vue/components/button`, built from the same markdown file, so a search for "vue button" can land on a page that shows Vue.
|
|
169
|
+
|
|
170
|
+
Turn them on in the app's `nuxt.config.ts`, since the routes are decided when the site builds:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
// nuxt.config.ts
|
|
174
|
+
export default defineNuxtConfig({
|
|
175
|
+
extends: ["@uxfront/layer-docs"],
|
|
176
|
+
frameworkUrls: { enabled: true },
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Keep listing the frameworks in `docsTheme.frameworks` in `app/app.config.ts`, as above. The build reads them from there, along with any list that file imports, like `./data/frameworks`. It stops with a message if the list is empty, if the docs aren't in `content/docs/`, or if the app uses Docus's i18n locales, which framework URLs don't support yet.
|
|
181
|
+
|
|
182
|
+
### What changes
|
|
183
|
+
|
|
184
|
+
With framework URLs on:
|
|
185
|
+
|
|
186
|
+
- **Every docs page is served under each framework.** `content/docs/components/button.md` becomes `/docs/react/components/button`, `/docs/vue/components/button` and so on, and the build writes every one of them, whether or not anything links to it. The unprefixed `/docs/components/button` isn't built. Only the framework values match the segment, so keep content folders from sharing a name with a framework.
|
|
187
|
+
- **The URL decides the framework.** On `/docs/vue/…`, `useFramework()` returns Vue on the server and in the browser alike, and a stored pick never overrides it, so the page hydrates without a flash of another framework.
|
|
188
|
+
- **The select goes to the same page under the new framework.** Picking Svelte on `/docs/vue/components/button` opens `/docs/svelte/components/button`, from the sidebar and from the header's menu alike, and stores the pick.
|
|
189
|
+
- **Each page carries only one framework's examples.** Every `::framework-switcher` keeps only the slot it shows, in the HTML and in the page's payload, and the table of contents drops the headings of the other slots.
|
|
190
|
+
- **Links keep the framework.** The sidebar, the header's menu, previous and next, the breadcrumb and its structured data, search results, the page header's `links` from the frontmatter, links in your markdown (`[Button](/docs/components/button)` and `::card{to="/docs/…"}` alike) and `docsTheme.headerLinks` all point under the current framework. A link that already has a framework in it, like `/docs/react/…`, stays as it is, and so does `/docs` itself. On a page that isn't under a framework, like the homepage or the 404 page, they take the first framework, and so do the links in `content/index.md` when Docus's landing page renders it.
|
|
191
|
+
- **Each page's markdown is served at its framework path too.** Docus's "Copy page" button and `/raw/docs/vue/components/button.md` return the same markdown as `/raw/docs/components/button.md`, with every framework's examples in it.
|
|
192
|
+
|
|
193
|
+
A few things stay as they are, so keep them in mind:
|
|
194
|
+
|
|
195
|
+
- **Docus's sub-navigation mode** (`navigation.sub` in `app.config.ts`) isn't supported: its section bar and mobile bar keep their links unprefixed.
|
|
196
|
+
- **A `content/docs/index.md` page** is served at `/docs/<framework>`, but links to `/docs` stay `/docs`, so a crawler that follows one builds `/docs` with every framework's examples. Link to `docsPath("/")` instead.
|
|
197
|
+
- **Your own pages under `/docs/`**, like `app/pages/docs/changelog.vue`, get their links put under a framework and aren't built. Keep app pages outside `/docs/`.
|
|
198
|
+
- **Your own pages that render content** with `ContentRenderer` keep their markdown links as they are. Link to the docs from them with `docsPath()`.
|
|
199
|
+
|
|
200
|
+
### Links outside the docs
|
|
201
|
+
|
|
202
|
+
Links the layer doesn't render, like a "Read the docs" button on your own homepage, take their URL from `docsPath()`, which every component and composable can call:
|
|
203
|
+
|
|
204
|
+
```vue
|
|
205
|
+
<!-- app/pages/index.vue -->
|
|
206
|
+
<template>
|
|
207
|
+
<UButton :to="docsPath('/getting-started/introduction')">Read the docs</UButton>
|
|
208
|
+
</template>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
| Argument | Type | What it does |
|
|
212
|
+
| ----------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
213
|
+
| `page` | `string` | The page's path below `/docs`, like `/components/button`. |
|
|
214
|
+
| `framework` | `string` | The framework to link to. Leave it out to use the current route's framework, or the first framework on a page that isn't under one, like a homepage. |
|
|
215
|
+
|
|
216
|
+
It returns `/docs/<framework>/<page>`, like `/docs/react/components/button`. With framework URLs off, it returns `/docs/<page>` and ignores `framework`, so you can use it before you turn them on.
|
|
217
|
+
|
|
218
|
+
### Coverage and search engines
|
|
219
|
+
|
|
220
|
+
A page **covers** a framework when every `::framework-switcher` on it has a slot for it. A page with no switcher covers all of them. A page is still built under every framework, so the select never leads to a 404, and the head tags tell search engines which version to show:
|
|
221
|
+
|
|
222
|
+
- **A page that covers the framework** is canonical at its own URL, and has a `<link rel="alternate">` to its version under each other framework that covers it.
|
|
223
|
+
- **A page that doesn't** shows the first framework it covers, with the switcher's "Not available for Solid, showing React." note. It's marked `<meta name="robots" content="noindex, follow">`, and its canonical points to the first framework that covers it, so search engines index the page that really has the examples.
|
|
224
|
+
|
|
225
|
+
`docsPageFrameworks(page, frameworks)` returns the frameworks a page covers, in the order of `frameworks`. It's auto-imported in the app and in your server routes, and works with framework URLs off too.
|
|
226
|
+
|
|
227
|
+
### The sitemap
|
|
228
|
+
|
|
229
|
+
With framework URLs on, the layer serves `/sitemap.xml` in place of Docus's: each docs page once for each framework that covers it, with the date part of the page's `modifiedAt` as `<lastmod>`. Pages with `sitemap: false` in their frontmatter, `.navigation` files and the versions a page doesn't cover stay out. Docus's landing page, `/`, is listed when your app uses it, as Docus does. The URLs are absolute when the site has a URL, from `site.url` or `NUXT_SITE_URL`, read when the site builds.
|
|
230
|
+
|
|
231
|
+
A site that has its own `server/routes/sitemap.xml.ts` keeps it, and the layer adds nothing there. To list the docs pages in it, call `getDocsSitemapEntries(event)`, which is auto-imported in your server routes:
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
// server/routes/sitemap.xml.ts
|
|
235
|
+
export default defineEventHandler(async (event) => {
|
|
236
|
+
// Your own homepage, app/pages/index.vue, comes first. With Docus's landing
|
|
237
|
+
// page instead, the entries already list `/`.
|
|
238
|
+
const entries = [{ loc: "/" }, ...(await getDocsSitemapEntries(event))];
|
|
239
|
+
// Write `entries` as XML, with your site's URL before each `loc`…
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Each entry has these fields:
|
|
244
|
+
|
|
245
|
+
| Field | Type | What it holds |
|
|
246
|
+
| --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
247
|
+
| `loc` | `string` | The page's URL path: `/docs/vue/components/button` for a docs page, and `/` for Docus's landing page. |
|
|
248
|
+
| `lastmod` | `string` | The date part of the page's `modifiedAt`, like `2026-11-19`. It's left out when the page has none. |
|
|
249
|
+
| `path` | `string` | The page's content path, like `/docs/components/button`, the same for each framework's entry, and `/` for the landing page. |
|
|
250
|
+
|
|
251
|
+
With framework URLs off, it lists each page once, with `loc` the same as `path`. Docus's landing page is in the list whenever your app uses it, so only add `/` yourself when your app has its own `app/pages/index.vue`.
|
|
252
|
+
|
|
166
253
|
## What it adds
|
|
167
254
|
|
|
168
255
|
- **A Framework select above the sidebar.** It picks the framework for the whole site, and lines up with the navigation's pages below it. It replaces Docus's `DocsAsideLeftTop` and renders Docus's below it.
|
|
@@ -173,7 +260,9 @@ export default defineNuxtConfig({
|
|
|
173
260
|
- **A named menu toggle.** On smaller screens, the header's menu button says what it does, "Open menu" or "Close menu", in Nuxt UI's words, translated with its locale. Docus's has no name, which [WCAG 4.1.2](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html) asks every control to have, so screen readers announce it only as "button". It replaces Docus's `IconMenuToggle`, and its lines don't move for readers who ask for reduced motion.
|
|
174
261
|
- **A header wordmark and byline.** It replaces Docus's `AppHeaderLeft`, and renders Docus's unless the app sets a wordmark.
|
|
175
262
|
- **Typed app config.** `useAppConfig()` knows `docsTheme`, so `wordmark`, `byline` and `headerLinks` typecheck even in an app that leaves them unset.
|
|
176
|
-
- **`useFramework()`.** The reader's pick, shared by every switcher and the select, and kept in `localStorage` across visits. It's read once the page is mounted, so the prerendered HTML shows the default framework and hydrates cleanly.
|
|
263
|
+
- **`useFramework()`.** The reader's pick, shared by every switcher and the select, and kept in `localStorage` across visits. It's read once the page is mounted, so the prerendered HTML shows the default framework and hydrates cleanly. With framework URLs on, the route's framework wins on a framework route. It returns `{ framework, frameworks, current }`.
|
|
264
|
+
- **Framework URLs, when you turn them on.** Every docs page at `/docs/<framework>/<page>`, built once per framework with only that framework's examples (see [Framework URLs](#framework-urls)). They add a route with a copy of Docus's docs page, use a copy of Docus's landing page, and replace Docus's `DocsAsideLeftBody` and `AppSearch` to put their links under the framework. Off, those two render Docus's own.
|
|
265
|
+
- **`docsPath()` and `docsPageFrameworks()`.** A docs page's URL for links outside the Docus shell, and the frameworks a page covers. Both are auto-imported, and `docsPageFrameworks` and `getDocsSitemapEntries` are auto-imported in server routes too.
|
|
177
266
|
- **Highlighting for the frameworks' languages.** `tsx`, `svelte`, `angular-html`, `angular-ts` and `astro`, on top of Docus's.
|
|
178
267
|
- **Readable code colours.** GitHub's high-contrast themes, whose every colour reaches 4.5:1 on the code blocks' background (see [Code themes](#code-themes)).
|
|
179
268
|
- **Bundled icons.** Nuxt Icon bundles the icons named in app config too, so the select's icons don't come from the Iconify API.
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import DocusAppHeaderBody from "docus/app/components/app/AppHeaderBody.vue";
|
|
2
3
|
// Replaces Docus's to start the header's menu, which stands in for the sidebar
|
|
3
4
|
// on smaller screens, with `docsTheme.headerLinks` below 768px, where
|
|
4
5
|
// AppHeaderCTA hides them, and the framework select, as DocsAsideLeftTop puts
|
|
5
|
-
// it above the sidebar. Docus's renders below them
|
|
6
|
-
|
|
6
|
+
// it above the sidebar. Docus's renders below them, with the navigation under
|
|
7
|
+
// the route's framework when framework URLs are on.
|
|
8
|
+
import type { Ref } from "vue";
|
|
9
|
+
|
|
10
|
+
import type { NavigationItem } from "../../../modules/framework-urls/utils";
|
|
11
|
+
import { useFrameworkRoute } from "../../internal/frameworkRoute";
|
|
7
12
|
|
|
8
13
|
const appConfig = useAppConfig();
|
|
14
|
+
const navigation = inject<Ref<NavigationItem[] | null>>("navigation");
|
|
15
|
+
const { enabled, navigationFor } = useFrameworkRoute();
|
|
16
|
+
|
|
17
|
+
if (enabled)
|
|
18
|
+
provide(
|
|
19
|
+
"navigation",
|
|
20
|
+
computed(() => navigationFor(navigation?.value)),
|
|
21
|
+
);
|
|
9
22
|
</script>
|
|
10
23
|
|
|
11
24
|
<template>
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// The header's links, from `docsTheme.headerLinks`, or `items` for a site that
|
|
3
3
|
// splits them around controls of its own, like a Version select. A link with
|
|
4
4
|
// `activeFor` is active on that path and below it, so the docs link stays
|
|
5
|
-
// highlighted on every docs page, not only the one it points to.
|
|
5
|
+
// highlighted on every docs page, not only the one it points to. With framework
|
|
6
|
+
// URLs on, a link to a docs page goes to it under the route's framework.
|
|
6
7
|
import type { HeaderLink } from "../../composables/useFramework";
|
|
8
|
+
import { useFrameworkRoute } from "../../internal/frameworkRoute";
|
|
7
9
|
|
|
8
10
|
const props = defineProps<{
|
|
9
11
|
orientation: "horizontal" | "vertical";
|
|
@@ -13,9 +15,11 @@ const props = defineProps<{
|
|
|
13
15
|
|
|
14
16
|
const appConfig = useAppConfig();
|
|
15
17
|
const route = useRoute();
|
|
18
|
+
const { toFramework } = useFrameworkRoute();
|
|
16
19
|
|
|
17
20
|
const links = computed(() =>
|
|
18
|
-
(props.items ?? appConfig.docsTheme.headerLinks ?? []).map(({ activeFor, ...
|
|
21
|
+
(props.items ?? appConfig.docsTheme.headerLinks ?? []).map(({ activeFor, ...item }) => {
|
|
22
|
+
const link = { ...item, to: toFramework(item.to) };
|
|
19
23
|
if (activeFor === undefined) return link;
|
|
20
24
|
const active = route.path === activeFor || route.path.startsWith(`${activeFor}/`);
|
|
21
25
|
return { ...link, active, "aria-current": active ? ("page" as const) : undefined };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Replaces Docus's to keep search results and navigation under the route's
|
|
3
|
+
// framework when framework URLs are on. Without them, it renders Docus's own,
|
|
4
|
+
// so a site that doesn't opt in gets Docus's search as it ships.
|
|
5
|
+
import DocusAppSearch from "docus/app/components/app/AppSearch.vue";
|
|
6
|
+
|
|
7
|
+
import type { NavigationItem } from "../../../modules/framework-urls/utils";
|
|
8
|
+
import { useFrameworkRoute } from "../../internal/frameworkRoute";
|
|
9
|
+
import FrameworkSearch from "../../internal/FrameworkSearch.vue";
|
|
10
|
+
|
|
11
|
+
defineProps<{
|
|
12
|
+
navigation?: NavigationItem[] | null;
|
|
13
|
+
}>();
|
|
14
|
+
|
|
15
|
+
const { enabled } = useFrameworkRoute();
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<FrameworkSearch v-if="enabled" :navigation="navigation" />
|
|
20
|
+
<!-- Docus's search takes no null, and reads a missing navigation as none. -->
|
|
21
|
+
<DocusAppSearch v-else :navigation="navigation ?? undefined" />
|
|
22
|
+
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import DocusAsideLeftBody from "docus/app/components/docs/DocsAsideLeftBody.vue";
|
|
3
|
+
// Replaces Docus's to give the sidebar's navigation the framework of the route,
|
|
4
|
+
// with framework URLs on: Docus's renders below, reading the navigation this
|
|
5
|
+
// provides. Without them, it gets Docus's navigation as it is.
|
|
6
|
+
import type { Ref } from "vue";
|
|
7
|
+
|
|
8
|
+
import type { NavigationItem } from "../../../modules/framework-urls/utils";
|
|
9
|
+
import { useFrameworkRoute } from "../../internal/frameworkRoute";
|
|
10
|
+
|
|
11
|
+
const navigation = inject<Ref<NavigationItem[] | null>>("navigation");
|
|
12
|
+
const { enabled, navigationFor } = useFrameworkRoute();
|
|
13
|
+
|
|
14
|
+
if (enabled)
|
|
15
|
+
provide(
|
|
16
|
+
"navigation",
|
|
17
|
+
computed(() => navigationFor(navigation?.value)),
|
|
18
|
+
);
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<DocusAsideLeftBody />
|
|
23
|
+
</template>
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { useLocalStorage } from "@vueuse/core";
|
|
2
|
+
import type { Ref } from "vue";
|
|
3
|
+
|
|
4
|
+
import { useFrameworkRoute } from "../internal/frameworkRoute";
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* A framework offered by the `FrameworkSwitcher` content component and the
|
|
@@ -76,16 +79,39 @@ declare module "@nuxt/schema" {
|
|
|
76
79
|
*
|
|
77
80
|
* The stored pick is only read once mounted, so the prerendered HTML and the
|
|
78
81
|
* first client render both show the default, and hydrate cleanly.
|
|
82
|
+
*
|
|
83
|
+
* With framework URLs on, a framework route, like `/docs/vue/…`, decides the
|
|
84
|
+
* framework instead, on the server and in the browser alike, and a stored pick
|
|
85
|
+
* never overrides it. Setting `framework` there stores the pick and goes to the
|
|
86
|
+
* same page under the new framework.
|
|
79
87
|
*/
|
|
80
88
|
export function useFramework() {
|
|
81
89
|
const appConfig = useAppConfig();
|
|
90
|
+
const route = useRoute();
|
|
91
|
+
const { routeFramework, values } = useFrameworkRoute();
|
|
82
92
|
|
|
83
93
|
const frameworks = computed<FrameworkOption[]>(() => appConfig.docsTheme.frameworks);
|
|
84
94
|
|
|
85
|
-
const
|
|
95
|
+
const stored = useLocalStorage("docs-theme:framework", frameworks.value[0]?.value ?? "", {
|
|
86
96
|
initOnMounted: true,
|
|
87
97
|
});
|
|
88
98
|
|
|
99
|
+
const framework: Ref<string> = values.length
|
|
100
|
+
? computed({
|
|
101
|
+
get: () => routeFramework.value ?? stored.value,
|
|
102
|
+
set: (value) => {
|
|
103
|
+
stored.value = value;
|
|
104
|
+
const from = routeFramework.value;
|
|
105
|
+
if (!from || value === from || !values.includes(value)) return;
|
|
106
|
+
void navigateTo({
|
|
107
|
+
path: `/docs/${value}${route.path.slice(`/docs/${from}`.length)}`,
|
|
108
|
+
query: route.query,
|
|
109
|
+
hash: route.hash,
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
: stored;
|
|
114
|
+
|
|
89
115
|
// A stored pick that's no longer on the list falls back to the default.
|
|
90
116
|
const current = computed(
|
|
91
117
|
() =>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { NavigationItem } from "../../modules/framework-urls/utils";
|
|
3
|
+
// Docus's search (docus/app/components/app/AppSearch.vue), with its results
|
|
4
|
+
// and navigation under the route's framework, so a search opened on a
|
|
5
|
+
// `/docs/vue/…` page leads to `/docs/vue/…`. AppSearch renders it only with
|
|
6
|
+
// framework URLs on, and Docus's own otherwise.
|
|
7
|
+
//
|
|
8
|
+
// Upgrading Docus: this copies Docus 5.13.0's app/components/app/AppSearch.vue.
|
|
9
|
+
// When you raise the `docus` range in package.json, diff that file against
|
|
10
|
+
// this one, carry its changes over, and run `pnpm test:build`.
|
|
11
|
+
import { useFrameworkRoute } from "./frameworkRoute";
|
|
12
|
+
|
|
13
|
+
const props = defineProps<{
|
|
14
|
+
navigation?: NavigationItem[] | null;
|
|
15
|
+
}>();
|
|
16
|
+
|
|
17
|
+
interface SearchSection {
|
|
18
|
+
id: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const appConfig = useAppConfig();
|
|
23
|
+
const { forced: forcedColorMode } = useDocusColorMode();
|
|
24
|
+
const { locale, isEnabled } = useDocusI18n();
|
|
25
|
+
const { enabled, toFramework, navigationFor } = useFrameworkRoute();
|
|
26
|
+
|
|
27
|
+
const collectionName = computed(() => (isEnabled.value ? `docs_${locale.value}` : "docs") as never);
|
|
28
|
+
const useFts = appConfig.search.fts;
|
|
29
|
+
|
|
30
|
+
const { data: rawFiles } = useFts
|
|
31
|
+
? { data: ref(null) }
|
|
32
|
+
: useLazyAsyncData(
|
|
33
|
+
`search_${collectionName.value}`,
|
|
34
|
+
() => queryCollectionSearchSections(collectionName.value),
|
|
35
|
+
{
|
|
36
|
+
server: false,
|
|
37
|
+
watch: [locale],
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const files = computed(() =>
|
|
42
|
+
enabled && rawFiles.value
|
|
43
|
+
? (rawFiles.value as SearchSection[]).map((file) => ({ ...file, id: toFramework(file.id) }))
|
|
44
|
+
: rawFiles.value,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
search: rawSearch,
|
|
49
|
+
status: searchStatus,
|
|
50
|
+
init,
|
|
51
|
+
} = useFts
|
|
52
|
+
? useSearchCollection(collectionName, { immediate: false, ignoredTags: ["style"] })
|
|
53
|
+
: { search: undefined, status: ref(undefined), init: () => {} };
|
|
54
|
+
|
|
55
|
+
const search =
|
|
56
|
+
enabled && rawSearch
|
|
57
|
+
? async (...args: Parameters<typeof rawSearch>) =>
|
|
58
|
+
((await rawSearch(...args)) as SearchSection[]).map((result) => ({
|
|
59
|
+
...result,
|
|
60
|
+
id: toFramework(result.id),
|
|
61
|
+
}))
|
|
62
|
+
: rawSearch;
|
|
63
|
+
|
|
64
|
+
if (useFts) {
|
|
65
|
+
const { open } = useContentSearch();
|
|
66
|
+
watch(open, (value) => {
|
|
67
|
+
if (value && searchStatus.value === "idle") {
|
|
68
|
+
init();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const navigation = computed(() => (enabled ? navigationFor(props.navigation) : props.navigation));
|
|
74
|
+
|
|
75
|
+
const links = computed(() =>
|
|
76
|
+
useFts
|
|
77
|
+
? navigation.value
|
|
78
|
+
?.filter((item) => item.children?.length)
|
|
79
|
+
.map((item) => ({
|
|
80
|
+
label: item.title,
|
|
81
|
+
icon: item.icon,
|
|
82
|
+
to: item.children![0]!.path,
|
|
83
|
+
}))
|
|
84
|
+
: undefined,
|
|
85
|
+
);
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<template>
|
|
89
|
+
<LazyUContentSearch
|
|
90
|
+
:files="files"
|
|
91
|
+
:search="search"
|
|
92
|
+
:search-status="searchStatus"
|
|
93
|
+
:links="links"
|
|
94
|
+
:navigation="navigation"
|
|
95
|
+
:color-mode="!forcedColorMode"
|
|
96
|
+
/>
|
|
97
|
+
</template>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FRAMEWORK_ROUTE_NAME,
|
|
3
|
+
prefixDocsPath,
|
|
4
|
+
prefixNavigation,
|
|
5
|
+
type NavigationItem,
|
|
6
|
+
} from "../../modules/framework-urls/utils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Where framework URLs stand on the current route: whether they're on, the
|
|
10
|
+
* route's framework, and the framework links take. Off a framework route,
|
|
11
|
+
* links take the first framework, so a page built once, like the 404 page,
|
|
12
|
+
* never depends on the reader's stored pick.
|
|
13
|
+
*/
|
|
14
|
+
export function useFrameworkRoute() {
|
|
15
|
+
const route = useRoute();
|
|
16
|
+
const config = useRuntimeConfig().public.docsFrameworkUrls;
|
|
17
|
+
const enabled = !!config;
|
|
18
|
+
const values = config?.frameworks ?? [];
|
|
19
|
+
|
|
20
|
+
const routeFramework = computed(() => {
|
|
21
|
+
if (!enabled || route.name !== FRAMEWORK_ROUTE_NAME) return undefined;
|
|
22
|
+
const value = route.params.framework;
|
|
23
|
+
return typeof value === "string" && values.includes(value) ? value : undefined;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const linkFramework = computed(() => routeFramework.value ?? values[0]);
|
|
27
|
+
|
|
28
|
+
/** A same-site link to a docs page, under the framework links take. */
|
|
29
|
+
const toFramework = <T>(link: T): T =>
|
|
30
|
+
enabled && linkFramework.value ? prefixDocsPath(link, linkFramework.value, values) : link;
|
|
31
|
+
|
|
32
|
+
/** A navigation tree with every path under the framework links take. */
|
|
33
|
+
const navigationFor = <T extends NavigationItem>(items: T[] | null | undefined) =>
|
|
34
|
+
enabled && linkFramework.value
|
|
35
|
+
? prefixNavigation(items, linkFramework.value, values)
|
|
36
|
+
: (items ?? []);
|
|
37
|
+
|
|
38
|
+
return { enabled, values, routeFramework, linkFramework, toFramework, navigationFor };
|
|
39
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { pageFrameworks, type MinimarkBody } from "../../modules/framework-urls/utils";
|
|
2
|
+
import { useFrameworkRoute } from "../internal/frameworkRoute";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The URL of a docs page, for links outside the Docus shell, like a homepage's
|
|
6
|
+
* "Read the docs" button: `docsPath("/components/button")` is
|
|
7
|
+
* `/docs/react/components/button` on a site with framework URLs, under the
|
|
8
|
+
* framework of the current route, or the first framework off a framework
|
|
9
|
+
* route. Pass `framework` to pick one. Without framework URLs, it's
|
|
10
|
+
* `/docs/components/button`.
|
|
11
|
+
*/
|
|
12
|
+
export function docsPath(page: string, framework?: string): string {
|
|
13
|
+
const path = page.startsWith("/") ? page : `/${page}`;
|
|
14
|
+
const { enabled, linkFramework } = useFrameworkRoute();
|
|
15
|
+
const value = framework ?? linkFramework.value;
|
|
16
|
+
return enabled && value
|
|
17
|
+
? `/docs/${value}${path === "/" ? "" : path}`
|
|
18
|
+
: `/docs${path === "/" ? "" : path}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The frameworks a docs page covers, in the order of `frameworks`: those that
|
|
23
|
+
* every `::framework-switcher` on it has a slot for. A page with no switcher
|
|
24
|
+
* covers them all.
|
|
25
|
+
*/
|
|
26
|
+
export function docsPageFrameworks(
|
|
27
|
+
page: { body?: MinimarkBody | null } | null | undefined,
|
|
28
|
+
frameworks: readonly string[],
|
|
29
|
+
): string[] {
|
|
30
|
+
return pageFrameworks(page?.body, frameworks);
|
|
31
|
+
}
|