@vite-hub/docs 0.8.0 → 0.9.0
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 +1 -1
- package/dist/{assistant-shared-JcfjK-qg.js → assistant-shared-BmCHVfEd.js} +0 -1
- package/dist/assistant-worker.js +1 -1
- package/dist/assistant.js +1 -1
- package/dist/{content-Chgcvz1q.js → content-Df5eeqTg.js} +1 -3
- package/dist/{draft-BKQg2PLU.js → draft-CYScbH80.js} +0 -1
- package/dist/{manifest-E4mohC7O.js → manifest-BgBIScEV.js} +0 -16
- package/dist/{markdown-BzZkYb24.js → markdown-DgQg53dB.js} +0 -28
- package/dist/navigation.js +0 -2
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +4 -43
- package/dist/primitive-rail.js +0 -4
- package/dist/runtime/app/assistant/DocsAssistant.vue +0 -3
- package/dist/runtime/app/assistant/DocsAssistantOff.vue +0 -2
- package/dist/runtime/app/assistant/DocsAssistantPanel.vue +0 -12
- package/dist/runtime/app/components/DocsAppShell.vue +0 -7
- package/dist/runtime/app/components/DocsArticle.vue +0 -8
- package/dist/runtime/app/components/DocsAsideFooter.vue +0 -5
- package/dist/runtime/app/components/DocsAsideLeftBody.vue +0 -18
- package/dist/runtime/app/components/DocsBrandMark.vue +0 -6
- package/dist/runtime/app/components/DocsCodePanel.vue +0 -19
- package/dist/runtime/app/components/DocsMarkdown.vue +0 -9
- package/dist/runtime/app/components/DocsPage.vue +0 -10
- package/dist/runtime/app/components/DocsPageCredits.vue +0 -1
- package/dist/runtime/app/components/DocsSidebars.vue +0 -8
- package/dist/runtime/app/components/OgImage/DocsPage.takumi.vue +0 -2
- package/dist/runtime/app/components/content/AgentOnly.vue +0 -1
- package/dist/runtime/app/components/content/CodeTree.vue +0 -6
- package/dist/runtime/app/components/content/ComarkHtml.vue +0 -9
- package/dist/runtime/app/components/content/Correct.vue +0 -1
- package/dist/runtime/app/components/content/Example.vue +0 -11
- package/dist/runtime/app/components/content/Examples.vue +0 -4
- package/dist/runtime/app/components/content/Incorrect.vue +0 -1
- package/dist/runtime/app/components/content/McpClient.vue +0 -5
- package/dist/runtime/app/components/content/McpInstall.vue +0 -4
- package/dist/runtime/app/components/content/PageList.vue +0 -11
- package/dist/runtime/app/components/content/ProductFeatureItem.vue +0 -3
- package/dist/runtime/app/components/content/ProductFeatures.vue +0 -3
- package/dist/runtime/app/composables/docs-assistant-problem.ts +0 -8
- package/dist/runtime/app/composables/docs-theme.ts +0 -6
- package/dist/runtime/app/composables/headerActions.ts +0 -1
- package/dist/runtime/app/composables/icons.ts +0 -1
- package/dist/runtime/app/composables/seo.ts +0 -11
- package/dist/runtime/app/composables/tutorial.ts +0 -8
- package/dist/runtime/app/composables/useDocsAssistant.ts +0 -2
- package/dist/runtime/app/error.vue +0 -4
- package/dist/runtime/app/layouts/docs.vue +0 -6
- package/dist/runtime/app/middleware/docs-layout.ts +0 -9
- package/dist/runtime/app/plugins/comark-css.ts +0 -5
- package/dist/runtime/app/plugins/icon-stroke.ts +0 -3
- package/dist/runtime/app/plugins/theme-color.ts +0 -5
- package/dist/runtime/app/utils/docs-theme.ts +0 -9
- package/dist/runtime/app/utils/file-tree.ts +0 -4
- package/dist/runtime/server/llms.js +1 -1
- package/dist/runtime/server/markdown.js +2 -7
- package/dist/runtime/server/mcp.js +1 -1
- package/dist/runtime/server/page.js +2 -2
- package/dist/runtime/server/raw.js +1 -1
- package/dist/runtime/server/search.js +2 -3
- package/dist/runtime/server/sitemap.js +1 -1
- package/dist/runtime/theme/design.css +1 -1
- package/dist/runtime/theme/vitehub.css +386 -0
- package/dist/server.js +2 -2
- package/dist/snapshot-worker.mjs +0 -5
- package/dist/{theme-Bju84I9x.js → theme-DowEsyAx.js} +289 -6
- package/dist/{theme-CgJRnVdT.d.ts → theme-aPbJMLsc.d.ts} +0 -6
- package/dist/theme.d.ts +1 -1
- package/dist/theme.js +1 -1
- package/package.json +12 -12
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { useDocsHeaderActionsTarget } from "../composables/headerActions"
|
|
3
3
|
|
|
4
|
-
// Wide screens have no site header beside the docs sidebar, so its foot holds the repository, the community links, and
|
|
5
|
-
// the color mode button. Phones keep them in the header and its menu.
|
|
6
|
-
// A collapsed sidebar stacks them in its narrow column, as icons.
|
|
7
4
|
defineProps<{ stacked?: boolean }>()
|
|
8
5
|
const { github, site, socials } = useDocsConfig()
|
|
9
6
|
const actionsTargetId = useDocsHeaderActionsTarget()
|
|
10
7
|
const id = `docs-header-actions-${useId()}`
|
|
11
|
-
// Register only after hydration. The server and the first client render keep the action in the header.
|
|
12
8
|
onMounted(() => { actionsTargetId.value = id })
|
|
13
9
|
onBeforeUnmount(() => {
|
|
14
10
|
if (actionsTargetId.value === id) actionsTargetId.value = null
|
|
15
11
|
})
|
|
16
|
-
// Nuxt turns a `null` in runtime config into "", so only a number counts.
|
|
17
12
|
const stars = github && typeof github.stars === "number" ? new Intl.NumberFormat("en", { notation: "compact" }).format(github.stars) : null
|
|
18
13
|
</script>
|
|
19
14
|
|
|
@@ -9,42 +9,30 @@ const { categories, groups, icons: iconOptions, railExclude, start } = useDocsCo
|
|
|
9
9
|
const icons = useDocsIcons()
|
|
10
10
|
const currentPath = computed(() => normalizeDocsPath(route.path))
|
|
11
11
|
const section = useDocsSection()
|
|
12
|
-
// The start section is the home of the docs, so it also lists the site pages that the header shows on the landing page.
|
|
13
12
|
const startLinks = computed(() => section.value && section.value.id === start?.section ? start.links : [])
|
|
14
13
|
const pageGroups = computed(() => section.value ? docsSidebarGroups(section.value) : [])
|
|
15
14
|
const related = computed(() => section.value ? docsRelatedSections(manifest, section.value) : [])
|
|
16
|
-
// Outside every section, for example on the catalog, the sidebar lists every section by category.
|
|
17
15
|
const catalog = docsCatalog(manifest, categories)
|
|
18
|
-
// A small site has no rail, so the sidebar lists every section with its pages on every page.
|
|
19
16
|
const rail = docsHasRail(manifest, iconOptions, groups, { categories, railExclude })
|
|
20
|
-
// Sidebar membership comes from every manifest section, including groups entirely excluded from the rail.
|
|
21
17
|
const group = computed(() => section.value ? docsSidebarGroup(manifest, section.value, groups) : null)
|
|
22
18
|
const sectionBlocks = computed(() => {
|
|
23
19
|
const sections = rail ? group.value?.sections : manifest.sections
|
|
24
20
|
return sections ? docsSidebarSections(sections) : null
|
|
25
21
|
})
|
|
26
22
|
const groupStartLinks = computed(() => start && group.value?.sections.some(candidate => candidate.id === start.section) ? start.links : [])
|
|
27
|
-
// Nuxt serializes a `null` runtime config value as "", so `start` can be a string here.
|
|
28
23
|
const siteLinks = computed(() => rail ? groupStartLinks.value : start?.links ?? [])
|
|
29
24
|
|
|
30
|
-
// A folder with `navigation.panel: true` replaces the section sidebar while the reader is inside it. The section sidebar
|
|
31
|
-
// links to each panel once.
|
|
32
25
|
const panel = computed(() => {
|
|
33
26
|
const page = section.value?.pages.find(candidate => candidate.path === currentPath.value)
|
|
34
27
|
return section.value && page ? docsPanelOf(section.value, page) : null
|
|
35
28
|
})
|
|
36
29
|
const panels = computed(() => section.value ? docsSectionPanels(section.value) : [])
|
|
37
|
-
// The site search finds a page of a long panel, so the panel has no filter of its own.
|
|
38
30
|
const panelGroups = computed(() => panel.value && section.value ? docsPanelSidebarGroups(section.value, panel.value) : [])
|
|
39
31
|
|
|
40
32
|
function isActive(path: string) {
|
|
41
33
|
return currentPath.value === normalizeDocsPath(path)
|
|
42
34
|
}
|
|
43
35
|
|
|
44
|
-
// A folded group opens itself on its own pages, so the current page stays in view.
|
|
45
|
-
// Key the active disclosure by its page so navigation also reopens a group the reader closed.
|
|
46
|
-
// Panels often list codes such as `QUEUE_BINDING_NOT_FOUND`. A code reads as code on one line, and the tooltip holds a
|
|
47
|
-
// code that the sidebar cuts.
|
|
48
36
|
function isCode(title: string) {
|
|
49
37
|
return /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/.test(title)
|
|
50
38
|
}
|
|
@@ -53,15 +41,10 @@ function holdsCurrent(pageGroup: DocsSidebarGroup<DocsAppPage>) {
|
|
|
53
41
|
return pageGroup.pages.some(page => isActive(page.path))
|
|
54
42
|
}
|
|
55
43
|
|
|
56
|
-
// A panel group renders its links only when the reader opens it, and the group of the current page renders the pages
|
|
57
|
-
// around it, so a page of a thousand-code panel does not carry every code. The panel Overview lists them all.
|
|
58
44
|
const shownGroups = ref(new Set<string>())
|
|
59
|
-
// Keyed by panel too, so a group the reader showed in one panel does not show the group of the same name in another.
|
|
60
45
|
function groupKey(pageGroup: DocsSidebarGroup<DocsAppPage>) {
|
|
61
46
|
return `${panel.value?.id}:${pageGroup.label || ""}`
|
|
62
47
|
}
|
|
63
|
-
// A folded group renders the window of the current page, or nothing while it is shut. A group that does not fold is
|
|
64
|
-
// always open, so without the current page it renders its first pages.
|
|
65
48
|
function panelLinks(pageGroup: DocsSidebarGroup<DocsAppPage>) {
|
|
66
49
|
if (shownGroups.value.has(groupKey(pageGroup))) return pageGroup.pages
|
|
67
50
|
if (pageGroup.fold || holdsCurrent(pageGroup)) return docsPanelGroupWindow(pageGroup.pages, currentPath.value)
|
|
@@ -70,7 +53,6 @@ function panelLinks(pageGroup: DocsSidebarGroup<DocsAppPage>) {
|
|
|
70
53
|
function showGroup(pageGroup: DocsSidebarGroup<DocsAppPage>) {
|
|
71
54
|
shownGroups.value = new Set([...shownGroups.value, groupKey(pageGroup)])
|
|
72
55
|
}
|
|
73
|
-
// The group of the current page opens with its window; only a group that the reader opens renders all its links.
|
|
74
56
|
function toggleGroup(pageGroup: DocsSidebarGroup<DocsAppPage>, event: Event) {
|
|
75
57
|
if (event.target instanceof HTMLDetailsElement && event.target.open && !holdsCurrent(pageGroup)) showGroup(pageGroup)
|
|
76
58
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
// The site mark beside its name in the header, the rail, and the sidebar. A one-color mark is a mask filled with the
|
|
3
|
-
// text color, so it follows light and dark mode. A colored logo shows as it is, with its dark version in dark mode.
|
|
4
|
-
// The parent sets its size with `--vh-docs-mark-size`.
|
|
5
2
|
const { site } = useDocsConfig()
|
|
6
|
-
// Nuxt turns a `null` in runtime config into "", so an empty value means no logo.
|
|
7
3
|
const logo = site.logo || null
|
|
8
|
-
// A mask image is fetched only once the CSS applies to the mark, after the text around it has painted. The preload
|
|
9
|
-
// fetches it with the HTML, in CORS mode like a mask.
|
|
10
4
|
if (logo?.mask) {
|
|
11
5
|
useHead({ link: [{ key: "vh-docs-logo", rel: "preload", as: "image", href: logo.src, crossorigin: "anonymous", fetchpriority: "high" }] })
|
|
12
6
|
}
|
|
@@ -2,12 +2,7 @@
|
|
|
2
2
|
import { CopyButton } from "@vite-hub/ui"
|
|
3
3
|
import { buildFileTree } from "../utils/file-tree"
|
|
4
4
|
|
|
5
|
-
// The sticky code panel beside a tutorial. It reads the code blocks of the article body in order.
|
|
6
|
-
// While the reader scrolls, the tree lists every file seen so far and the panel shows the file being read.
|
|
7
|
-
// Shell blocks (`bash`, or a `commands/` name) are steps to run, not project files, so the panel skips them.
|
|
8
|
-
// On wide screens each file block in the prose shrinks to its name bar, which opens the file in the panel.
|
|
9
5
|
const props = defineProps<{
|
|
10
|
-
/** The rendered article body that holds the code blocks. */
|
|
11
6
|
body: HTMLElement | null | undefined
|
|
12
7
|
}>()
|
|
13
8
|
|
|
@@ -19,7 +14,6 @@ const selectedPath = ref<string>()
|
|
|
19
14
|
const code = useTemplateRef<HTMLElement>("code")
|
|
20
15
|
const panel = useTemplateRef<HTMLElement>("panel")
|
|
21
16
|
const codeId = useId()
|
|
22
|
-
// Only a deliberate choice is announced. The file that changes while the reader scrolls stays quiet.
|
|
23
17
|
const announcement = ref("")
|
|
24
18
|
|
|
25
19
|
function filenameFor(pre: HTMLPreElement): string {
|
|
@@ -36,7 +30,6 @@ function collectBlocks(body: HTMLElement): Block[] {
|
|
|
36
30
|
})
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
// The file being read is the last block whose top crossed 40% of the viewport. Before the first one, it is the first block.
|
|
40
33
|
function updateReached() {
|
|
41
34
|
const line = window.innerHeight * 0.4
|
|
42
35
|
let index = 0
|
|
@@ -49,7 +42,6 @@ function updateReached() {
|
|
|
49
42
|
}
|
|
50
43
|
}
|
|
51
44
|
|
|
52
|
-
// One entry per path, in order of first appearance. A later block with the same path replaces the earlier code.
|
|
53
45
|
const seenFiles = computed(() => {
|
|
54
46
|
const latest = new Map<string, Block>()
|
|
55
47
|
for (const block of blocks.value.slice(0, reached.value + 1)) latest.set(block.path, block)
|
|
@@ -58,7 +50,6 @@ const seenFiles = computed(() => {
|
|
|
58
50
|
const rows = computed(() => buildFileTree(seenFiles.value.map((file) => file.path)))
|
|
59
51
|
const selected = computed(() => seenFiles.value.find((file) => file.path === selectedPath.value))
|
|
60
52
|
|
|
61
|
-
// The panel reuses the highlighted markup the article already rendered, so both copies look the same.
|
|
62
53
|
watch([selected, code], ([file, container]) => {
|
|
63
54
|
if (!container) return
|
|
64
55
|
container.replaceChildren(...(file ? [file.pre.cloneNode(true)] : []))
|
|
@@ -68,8 +59,6 @@ watch([selected, code], ([file, container]) => {
|
|
|
68
59
|
let frame = 0
|
|
69
60
|
let rescanTimer = 0
|
|
70
61
|
let observer: MutationObserver | undefined
|
|
71
|
-
// The panel sticks below the header, but at the top of the page the banner pushes it down. Its height is the
|
|
72
|
-
// viewport below its top edge, so the file tree under the code stays in view at every scroll position.
|
|
73
62
|
let panelTop = -1
|
|
74
63
|
function fitPanel() {
|
|
75
64
|
const element = panel.value
|
|
@@ -98,21 +87,15 @@ function selectBlock(index: number) {
|
|
|
98
87
|
selectFile(blocks.value[index]?.path)
|
|
99
88
|
}
|
|
100
89
|
|
|
101
|
-
// Each source block gets a class for the wide-screen styles and a click on its name bar.
|
|
102
90
|
const releases: (() => void)[] = []
|
|
103
91
|
function releaseSources() {
|
|
104
92
|
for (const release of releases.splice(0)) release()
|
|
105
93
|
}
|
|
106
94
|
function markSources(list: Block[]) {
|
|
107
95
|
list.forEach((block, index) => {
|
|
108
|
-
// Filename metadata lives on the `<pre>` for collection, but that node is
|
|
109
|
-
// hidden on wide screens. Bind the selection handler to the visible header
|
|
110
|
-
// sibling instead of the hidden code element.
|
|
111
96
|
const bar = [...block.wrapper.children].find(
|
|
112
97
|
(child) => child !== block.pre && !child.matches("button"),
|
|
113
98
|
) as HTMLElement | undefined
|
|
114
|
-
// Keep the original filename bar as text. Add a native button for keyboard readers. A click anywhere on the bar,
|
|
115
|
-
// the button included, opens the file, so the whole bar that highlights on hover works.
|
|
116
99
|
const trigger = document.createElement("button")
|
|
117
100
|
trigger.type = "button"
|
|
118
101
|
trigger.className = "vh-code-panel-trigger"
|
|
@@ -145,8 +128,6 @@ watch(() => props.body, (body) => {
|
|
|
145
128
|
scan(body)
|
|
146
129
|
if (!body) return
|
|
147
130
|
observer = new MutationObserver((records) => {
|
|
148
|
-
// Our native filename buttons are presentation only. Rescanning for their
|
|
149
|
-
// insertion/removal would trigger another scan indefinitely.
|
|
150
131
|
const contentChanged = records.some(record =>
|
|
151
132
|
[...record.addedNodes, ...record.removedNodes].some(node =>
|
|
152
133
|
!(node instanceof HTMLElement && node.classList.contains("vh-code-panel-trigger")),
|
|
@@ -10,20 +10,14 @@ import type { Component } from "vue"
|
|
|
10
10
|
import type { ElementNode, Node as ComarkNode } from "comark"
|
|
11
11
|
import type { DocsDocument } from "@vite-hub/docs"
|
|
12
12
|
|
|
13
|
-
// The server parsed the page, so the client only renders nodes. Explicit maps and app content components override
|
|
14
|
-
// comark-ui's blocks. Blocks and content components load on first use, so a page downloads only the blocks it renders.
|
|
15
|
-
// The map has every comark-ui block, not only those of the plugins this package parses with: a site that adds chips or
|
|
16
|
-
// another comark-ui plugin to its parser gets its nodes drawn.
|
|
17
13
|
const props = defineProps<{
|
|
18
14
|
document: DocsDocument
|
|
19
|
-
/** Components by tag, such as `{ pre: DocsCodePre }`. */
|
|
20
15
|
components?: Record<string, Component>
|
|
21
16
|
}>()
|
|
22
17
|
|
|
23
18
|
const blocks: Record<string, Component> = lazyBlocks
|
|
24
19
|
const motionEnabled = useViteHubUIMotionEnabled()
|
|
25
20
|
|
|
26
|
-
// `::note`, `::tip`, and the other callout components draw comark-ui's GitHub callout, the same as a `> [!NOTE]` quote.
|
|
27
21
|
const callout = (type: string, title?: string): Component => defineComponent({
|
|
28
22
|
name: `${type[0]!.toUpperCase()}${type.slice(1)}Callout`,
|
|
29
23
|
setup: (_, { slots }) => () => h(blocks.GithubCallout!, { type, title }, slots),
|
|
@@ -39,7 +33,6 @@ const callouts: Record<string, Component> = {
|
|
|
39
33
|
|
|
40
34
|
const contentBlocks = Object.fromEntries(Object.entries(contentComponents).flatMap(([tag, load]) => load ? [[tag, defineAsyncComponent(async () => (await load()).default)]] : []))
|
|
41
35
|
const componentKey = (tag: string) => capitalize(camelize(tag))
|
|
42
|
-
// Comark looks up PascalCase before the raw tag, so all maps must use the same keys for precedence to hold.
|
|
43
36
|
const byKey = (maps: Record<string, Component>[]) => Object.fromEntries(maps.flatMap(map => Object.entries(map).map(([tag, component]) => [componentKey(tag), component])))
|
|
44
37
|
const overrides = computed(() => byKey([contentBlocks, customComponents, props.components ?? {}]))
|
|
45
38
|
const resolved = computed(() => ({
|
|
@@ -48,8 +41,6 @@ const resolved = computed(() => ({
|
|
|
48
41
|
...(motionEnabled ? {} : { ProseMotionRuntime: () => null }),
|
|
49
42
|
}))
|
|
50
43
|
|
|
51
|
-
// HTML is the fallback. An app component still receives the original tag, props, and source children. comark-ui's own
|
|
52
|
-
// component doesn't: the parser drew the block as HTML because that component can't, as with a chart's marks.
|
|
53
44
|
const unbrokenCodeLength = 24
|
|
54
45
|
const isShortText = (children: ComarkNode[]) => children.length === 1 && typeof children[0] === "string" && children[0].length <= unbrokenCodeLength
|
|
55
46
|
|
|
@@ -12,29 +12,22 @@ const route = useRoute()
|
|
|
12
12
|
const manifest = useDocsManifest()
|
|
13
13
|
const { site, appBase } = useDocsConfig()
|
|
14
14
|
const path = normalizeDocsPath(route.path)
|
|
15
|
-
// A Content preview can show a new draft outside the build-time manifest. Let the page request decide whether it exists.
|
|
16
15
|
const { data } = await useFetch<DocsPageResponse>(docsAppPath(`/api/_docs/page${path === "/" ? "/index" : path}.json`, appBase), { key: `docs:${path}` })
|
|
17
16
|
if (!data.value) throw createError({ statusCode: 404, statusMessage: "Page not found", fatal: true })
|
|
18
17
|
const response = data.value
|
|
19
18
|
const { page } = response
|
|
20
19
|
|
|
21
20
|
const isRoot = page.path === manifest.root?.path
|
|
22
|
-
// A page that `start.links` lists opens inside the start section, like the pages of a section.
|
|
23
21
|
const isStartLink = isDocsStartLink(useDocsConfig(), page.path)
|
|
24
22
|
const loadWorkspace = isDocsWorkspaceLayout(page.layout) ? workspaces[page.path] : undefined
|
|
25
23
|
const workspace = loadWorkspace && (await loadWorkspace()).default
|
|
26
|
-
// Content previews can change a page's layout or add a home page after the manifest was built.
|
|
27
24
|
const layout = isDocsWorkspaceLayout(page.layout) || (page.layout !== "home" && (response.section || isRoot || isStartLink)) ? "docs" : articleLayout
|
|
28
25
|
if (import.meta.client && route.meta.layout !== layout) {
|
|
29
|
-
// The server has already rendered the manifest's layout. Finish hydrating it before switching shells.
|
|
30
26
|
if (useNuxtApp().isHydrating) onNuxtReady(() => setPageLayout(layout))
|
|
31
27
|
else setPageLayout(layout)
|
|
32
28
|
}
|
|
33
|
-
// A page outside the docs base has no section. It reads as a plain article under the site header.
|
|
34
29
|
const isStandalone = !response.section && !isRoot && !isStartLink && page.layout !== "home" && !isDocsWorkspaceLayout(page.layout)
|
|
35
30
|
|
|
36
|
-
// A home page draws the app's `components/content/` blocks at full width. The Markdown between two of them, such as a
|
|
37
|
-
// heading and a list, goes in one column with the prose styles of a docs page.
|
|
38
31
|
const componentKey = (tag: string) => capitalize(camelize(tag))
|
|
39
32
|
function homeDocument(document: DocsDocument): DocsDocument {
|
|
40
33
|
const blocks = new Set(pageBlocks.map(componentKey))
|
|
@@ -45,7 +38,6 @@ function homeDocument(document: DocsDocument): DocsDocument {
|
|
|
45
38
|
prose = []
|
|
46
39
|
}
|
|
47
40
|
for (const node of document.nodes) {
|
|
48
|
-
// The parser draws some blocks as HTML. An app component with the block's name still draws it.
|
|
49
41
|
const tag = typeof node === "string" || node[0] === null ? undefined : node[0] === "comark-html" && typeof node[1].block === "string" ? node[1].block : node[0]
|
|
50
42
|
if (tag && blocks.has(componentKey(tag))) {
|
|
51
43
|
flush()
|
|
@@ -58,10 +50,8 @@ function homeDocument(document: DocsDocument): DocsDocument {
|
|
|
58
50
|
}
|
|
59
51
|
const home = page.layout === "home" ? homeDocument(response.document) : undefined
|
|
60
52
|
|
|
61
|
-
// Agents can fetch the Markdown twin of the page instead of the HTML.
|
|
62
53
|
useHead({ link: [{ rel: "alternate", type: "text/markdown", href: `${site.url}${docsAppPath(docsRawPath(page.path), appBase)}` }] })
|
|
63
54
|
const section = manifest.sections.find(candidate => candidate.id === response.section)
|
|
64
|
-
// A page that search engines must not index gets no share image either: the build does not prerender it.
|
|
65
55
|
const indexed = page.seo?.index !== false
|
|
66
56
|
if (!indexed) useSeoMeta({ robots: "noindex, follow" })
|
|
67
57
|
useDocsSeo({
|
|
@@ -2,20 +2,12 @@
|
|
|
2
2
|
import { docsHasRail } from "#docs/navigation"
|
|
3
3
|
|
|
4
4
|
defineProps<{
|
|
5
|
-
/** Shows the page panel next to the rail. Outside a section the panel lists every product. */
|
|
6
5
|
panel: boolean
|
|
7
|
-
/** Shows the rail labels, for the mobile menu where touch has no hover to expand the rail. */
|
|
8
6
|
labeled?: boolean
|
|
9
|
-
/** Shows the brand, search, and the links row, for wide screens, which have no site header beside the sidebar. */
|
|
10
7
|
head?: boolean
|
|
11
|
-
/**
|
|
12
|
-
* On a page with a collapsible sidebar, shows the button that opens or collapses it. Collapsed, a site with the rail
|
|
13
|
-
* shows the rail alone and a site without it shows a strip. `panel` is then false.
|
|
14
|
-
*/
|
|
15
8
|
collapsible?: boolean
|
|
16
9
|
}>()
|
|
17
10
|
|
|
18
|
-
// A small site has no rail. The panel lists every section with its pages.
|
|
19
11
|
const config = useDocsConfig()
|
|
20
12
|
const rail = docsHasRail(useDocsManifest(), config.icons, config.groups, config)
|
|
21
13
|
</script>
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
// The share image of every docs page, in the docs design: the site, the page title and description, and the section.
|
|
3
|
-
// The build renders it once per page while prerendering, so the Worker carries no renderer.
|
|
4
2
|
withDefaults(defineProps<{
|
|
5
3
|
title?: string
|
|
6
4
|
description?: string
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
// `::code-tree` shows code blocks as a project: file tabs beside the code of the open file. Each child code block names
|
|
3
|
-
// its file with a path, such as ```ts [server/api/kv.ts]```. The tabs list folders first, like an editor, and
|
|
4
|
-
// `default-value` names the file that opens first, else the first block. A wide panel shows the tabs as a column beside
|
|
5
|
-
// the code. A narrow panel, such as a hero beside its copy, shows them as a row above the code, so the code keeps the width.
|
|
6
2
|
import type { VNode } from "vue";
|
|
7
3
|
|
|
8
4
|
const props = defineProps<{
|
|
9
|
-
/** The path of the file that opens first. */
|
|
10
5
|
defaultValue?: string;
|
|
11
6
|
}>();
|
|
12
7
|
|
|
@@ -25,7 +20,6 @@ const files = computed(() =>
|
|
|
25
20
|
);
|
|
26
21
|
const selected = ref(files.value.find((file) => file.path === props.defaultValue)?.path ?? files.value[0]?.path ?? "");
|
|
27
22
|
|
|
28
|
-
// The tabs show file names, so two files with the same name also show their folder.
|
|
29
23
|
const items = computed(() => {
|
|
30
24
|
const names = files.value.map((file) => file.path.split("/").at(-1));
|
|
31
25
|
const shared = new Set(names.filter((name, index) => names.indexOf(name) !== index));
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
// A block that has only an HTML renderer (annotate, comments, diff, quiz), drawn on the server by the docs parser.
|
|
3
|
-
// `block` is its tag, so a page's styles can tell a diff from a screenshot without looking inside. A block inside a
|
|
4
|
-
// paragraph is `inline`, and draws in a `span`, since a `div` would end the paragraph. Both tags are written out, since
|
|
5
|
-
// Vue's server renderer drops `v-html` on `<component :is>`.
|
|
6
|
-
// The parser keeps source children for search. This component renders only `html`, so they do not appear twice.
|
|
7
2
|
const props = defineProps<{ html: string, block?: string, blockProps?: Record<string, unknown>, inline?: boolean }>()
|
|
8
3
|
const root = ref<HTMLElement>()
|
|
9
4
|
|
|
10
|
-
// Scripts inserted by v-html are inert. Recreate them after mounting or replacing the HTML; the package runtimes
|
|
11
|
-
// guard repeated starts, including when the server's scripts already ran before hydration.
|
|
12
|
-
// Hydration sets `html` again, so these scripts never carry the nonce a CSP module added to the server's copies. They
|
|
13
|
-
// take the page's: under a CSP the browser empties every nonce attribute and keeps the value only in the property.
|
|
14
5
|
function runScripts() {
|
|
15
6
|
const nonce = document.querySelector<HTMLScriptElement>("script[nonce]")?.nonce
|
|
16
7
|
for (const old of root.value?.querySelectorAll("script") ?? []) {
|
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import examples from "#docs/examples"
|
|
3
3
|
|
|
4
|
-
// `:::example`: a preview with its source a switch away, and an optional link that opens it in a playground. Around a
|
|
5
|
-
// Markdown code block, the parser put the rendered Markdown in an `example-preview` node before the source. With
|
|
6
|
-
// `name`, the preview is the Vue file of that name in the examples folder, and the parser made its source the code.
|
|
7
4
|
const props = defineProps<{
|
|
8
5
|
label?: string
|
|
9
|
-
/** A playground URL that opens this example. */
|
|
10
6
|
play?: string
|
|
11
|
-
/** A Vue file in the examples folder, without `.vue`. */
|
|
12
7
|
name?: string
|
|
13
|
-
/** The height, in rem, that a Vue example keeps before its module loads. Markdown writes it as a string. */
|
|
14
8
|
height?: number | string
|
|
15
|
-
/** Show a Vue example edge to edge, at a fixed height, for chats and dashboards. */
|
|
16
9
|
flush?: boolean
|
|
17
|
-
/** Show a Reset control that mounts a Vue example again with its first state. */
|
|
18
10
|
reset?: boolean
|
|
19
11
|
kit?: boolean
|
|
20
12
|
}>()
|
|
21
13
|
|
|
22
|
-
// `::examples` passes its view in, so the next tab opens in the view the reader picked.
|
|
23
14
|
const view = defineModel<"preview" | "code">("view", { default: "preview" })
|
|
24
15
|
const loader = props.name ? examples[props.name] : undefined
|
|
25
16
|
const live = loader ? defineAsyncComponent(loader) : undefined
|
|
26
17
|
const mounts = ref(0)
|
|
27
18
|
const views = ["preview", "code"] as const
|
|
28
19
|
|
|
29
|
-
// A segmented switch is a radio group: arrow keys move the choice and the focus, and only the checked radio is a tab
|
|
30
|
-
// stop. The motion layer moves the raised look from one radio to the other.
|
|
31
20
|
function onKeydown(event: KeyboardEvent) {
|
|
32
21
|
const step = { ArrowLeft: -1, ArrowUp: -1, ArrowRight: 1, ArrowDown: 1 }[event.key]
|
|
33
22
|
if (!step) return
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
// `::examples`: one tab per `:::example`. Each example's Playground link and Preview and Code switch sit at the end of
|
|
3
|
-
// the tab row.
|
|
4
2
|
import type { VNode } from "vue"
|
|
5
3
|
|
|
6
4
|
const slots = useSlots()
|
|
7
5
|
const items = computed(() => (slots.default?.() ?? []).filter((node: VNode) => typeof node.type === "object"))
|
|
8
6
|
const labels = computed(() => items.value.map((node, at) => String(node.props?.label ?? `Example ${at + 1}`)))
|
|
9
7
|
const active = ref(0)
|
|
10
|
-
// Mount each preview on first use, then retain its state between tabs.
|
|
11
8
|
const opened = ref(new Set([0]))
|
|
12
|
-
// One view for every example, so Code stays on when the reader changes tabs.
|
|
13
9
|
const view = ref<"preview" | "code">("preview")
|
|
14
10
|
const tabs = computed(() => labels.value.map((label, at) => ({ label, value: at })))
|
|
15
11
|
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
// `:::mcp-client{label icon method}` inside `::mcp-install`: the setup of one client. Its Markdown is the steps,
|
|
3
|
-
// usually a numbered list, which shows as numbered circles. `install` adds the client's one-click install link,
|
|
4
|
-
// and `note` adds a footer line.
|
|
5
2
|
import { docsMcpInstallLinks } from "#docs/navigation"
|
|
6
3
|
|
|
7
4
|
const props = defineProps<{
|
|
8
5
|
label: string
|
|
9
6
|
icon?: string
|
|
10
|
-
/** How the server gets into this client, such as "Terminal" or "Settings". */
|
|
11
7
|
method?: string
|
|
12
|
-
/** A client with a one-click install link from the site's MCP config. */
|
|
13
8
|
install?: "cursor" | "vscode"
|
|
14
9
|
note?: string
|
|
15
10
|
}>()
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
// `::mcp-install` connects a reader's agent to the docs MCP server. The Client tab lists one `:::mcp-client` per
|
|
3
|
-
// client as a row of logos, and shows the steps of the client the reader picks. The Prompt, MCP URL, and Command tabs
|
|
4
|
-
// come from the site's `mcp` config, so they always name the real server. Raw Markdown keeps every client's steps.
|
|
5
2
|
import { CopyButton } from "@vite-hub/ui"
|
|
6
3
|
import type { VNode } from "vue"
|
|
7
4
|
|
|
@@ -16,7 +13,6 @@ const tabs = [
|
|
|
16
13
|
]
|
|
17
14
|
const tab = ref("client")
|
|
18
15
|
|
|
19
|
-
// Comark wraps children in fragments. A client is any node with a `label` prop.
|
|
20
16
|
function clientNodes(nodes: VNode[]): VNode[] {
|
|
21
17
|
return nodes.flatMap(node => typeof node.type === "symbol" && Array.isArray(node.children)
|
|
22
18
|
? clientNodes(node.children as VNode[])
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { docsPanelOf, docsPanelPages } from "#docs/navigation"
|
|
3
3
|
|
|
4
|
-
// `::page-list` lists the pages of a section under their sidebar groups, each with its icon and description, so an
|
|
5
|
-
// Overview can link every page without keeping a list by hand. On a panel Overview it lists the pages of the panel.
|
|
6
|
-
// Its own content is the list agents read in the Markdown copy; the site leaves it out.
|
|
7
4
|
const props = defineProps<{
|
|
8
|
-
/** The section to list, by id. Defaults to the section of the page. */
|
|
9
5
|
section?: string
|
|
10
|
-
/** One sidebar group to list, such as `Runtime errors`. */
|
|
11
6
|
group?: string
|
|
12
|
-
/** Sidebar groups to leave out, comma-separated, such as `Start`. */
|
|
13
7
|
exclude?: string
|
|
14
|
-
/**
|
|
15
|
-
* One line per page without icons, for long lists such as one page per error code. It renders a tenth of the markup
|
|
16
|
-
* of a Markdown table, so a list of a thousand pages stays far below the 2 MB that crawlers read.
|
|
17
|
-
*/
|
|
18
8
|
compact?: boolean
|
|
19
9
|
}>()
|
|
20
10
|
|
|
@@ -25,7 +15,6 @@ const icons = useDocsIcons()
|
|
|
25
15
|
const groups = computed(() => {
|
|
26
16
|
const section = props.section ? manifest.sections.find(candidate => candidate.id === props.section) : current.value
|
|
27
17
|
const exclude = new Set((props.exclude ?? "").split(",").map(name => name.trim()).filter(Boolean))
|
|
28
|
-
// Pages in the panel of the current page, or outside every panel: the section sidebar links each panel once.
|
|
29
18
|
const panel = section && !props.section && page.value ? docsPanelOf(section, page.value.page) : null
|
|
30
19
|
const grouped = new Map<string, NonNullable<typeof section>["pages"]>()
|
|
31
20
|
const pages = !section ? [] : panel ? docsPanelPages(section, panel) : section.pages.filter(candidate => candidate.panel || !docsPanelOf(section, candidate))
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
// `::product-features` is the feature list of a product landing page. Its default slot holds
|
|
3
|
-
// `:::product-feature-item` entries: one claim, one sentence, one link. No code: the hero carries the code.
|
|
4
2
|
defineProps<{
|
|
5
|
-
/** Optional heading above the list. */
|
|
6
3
|
title?: string
|
|
7
4
|
}>()
|
|
8
5
|
</script>
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
/** A failed answer, described for the reader, with the command that fixes it when there is one. */
|
|
2
1
|
export interface DocsAssistantProblem {
|
|
3
|
-
/** Stable code from the server, such as `AGENT_R1016`, or `unknown`. */
|
|
4
2
|
code: string
|
|
5
3
|
title: string
|
|
6
4
|
detail: string
|
|
7
|
-
/** A shell command for the site owner, run from the app folder. */
|
|
8
5
|
command?: string
|
|
9
6
|
}
|
|
10
7
|
|
|
11
8
|
const codePattern = /\b(AGENT_R\d{4}|AGENT_BUDGET_EXCEEDED|RATE_LIMIT_(?:REJECTED|UNAVAILABLE))\b/
|
|
12
9
|
|
|
13
|
-
/**
|
|
14
|
-
* Maps a chat error to what the panel shows. The ChatGPT plan errors name their fix, so the panel shows the exact
|
|
15
|
-
* command instead of a generic failure. `origin` is the site origin that the CLI connects to.
|
|
16
|
-
*/
|
|
17
10
|
export function docsAssistantProblem(error: Error | string, origin: string): DocsAssistantProblem {
|
|
18
11
|
const message = errorText(typeof error === "string" ? error : error.message)
|
|
19
12
|
const code = codePattern.exec(message)?.[1] ?? "unknown"
|
|
@@ -45,7 +38,6 @@ export function docsAssistantProblem(error: Error | string, origin: string): Doc
|
|
|
45
38
|
}
|
|
46
39
|
}
|
|
47
40
|
|
|
48
|
-
/** A failed chat request carries the response body, such as `{"code":"PROVIDER_UNAVAILABLE","error":"AGENT_R1016: ..."}`. */
|
|
49
41
|
function errorText(message: string): string {
|
|
50
42
|
if (!message.startsWith("{")) return message
|
|
51
43
|
try {
|
|
@@ -2,12 +2,6 @@ import theme from "#docs/theme"
|
|
|
2
2
|
|
|
3
3
|
import { resolveDocsTheme } from "../utils/docs-theme"
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* The `ui` prop of a Nuxt UI component in the shell, with the design's classes for the same slots in front. In an app
|
|
7
|
-
* with its own `app.vue`, `<UTheme>` gives the docs components the design, but a component's own `ui` prop replaces a
|
|
8
|
-
* `<UTheme>` slot instead of adding to it. In a docs site the design is in the app config, and this returns `ui` as is.
|
|
9
|
-
* Remove when ViteHub moves to Nuxt UI v5, where `<UTheme>` merges `ui` (https://github.com/nuxt/ui/pull/7050).
|
|
10
|
-
*/
|
|
11
5
|
export function withDocsTheme<T extends Record<string, string | undefined>>(component: string, ui: T): T {
|
|
12
6
|
if (!theme.ui[component]) return ui
|
|
13
7
|
const design = resolveDocsTheme(theme, useAppConfig().ui).ui[component] as Record<string, string | undefined>
|
|
@@ -3,7 +3,6 @@ import { useDocsConfig } from "./docs"
|
|
|
3
3
|
|
|
4
4
|
import type { DocsAppPage, DocsSection } from "@vite-hub/docs"
|
|
5
5
|
|
|
6
|
-
/** Icons of pages and sections in the rail, the sidebar, and the catalog, after the `icons` options apply. */
|
|
7
6
|
export function useDocsIcons() {
|
|
8
7
|
const { icons } = useDocsConfig()
|
|
9
8
|
return {
|
|
@@ -6,30 +6,20 @@ import { useDocsConfig } from "./docs"
|
|
|
6
6
|
export interface DocsSeoInput {
|
|
7
7
|
title: string
|
|
8
8
|
description?: string | null
|
|
9
|
-
/** Section label in the share image and the breadcrumb, such as `KV`. */
|
|
10
9
|
section?: { title: string, path: string } | null
|
|
11
|
-
/** A path in `public/` or a URL for the share image, or `false` for none. Without it the build renders one. */
|
|
12
10
|
image?: string | false
|
|
13
|
-
/** `article` marks the page a TechArticle in Schema.org. */
|
|
14
11
|
type?: "article" | "page"
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
/**
|
|
18
|
-
* Title, description, share image, and Schema.org of a page. Docs pages call it with their frontmatter; an app page,
|
|
19
|
-
* such as a playground, calls it to look the same when shared.
|
|
20
|
-
*/
|
|
21
14
|
export function useDocsSeo(input: DocsSeoInput): void {
|
|
22
15
|
const { site, appBase, ogImage } = useDocsConfig()
|
|
23
16
|
const route = useRoute()
|
|
24
17
|
const path = docsAppPath(normalizeDocsPath(route.path), appBase)
|
|
25
|
-
// A section's own Overview names the section already.
|
|
26
18
|
const section = input.section && input.section.path !== path ? input.section : null
|
|
27
19
|
const description = input.description ?? site.description ?? undefined
|
|
28
20
|
useSeoMeta({ title: input.title, ogTitle: input.title, description, ogDescription: description, ogType: input.type === "article" ? "article" : "website" })
|
|
29
21
|
|
|
30
22
|
if (input.image === false) {
|
|
31
|
-
// Null overrides inherited head tags before Unhead removes them from the rendered page.
|
|
32
|
-
// A `summary` card tells share previews and the search check that the page has no image on purpose.
|
|
33
23
|
useSeoMeta({ twitterCard: "summary", ogImage: null, ogImageUrl: null, ogImageSecureUrl: null, ogImageType: null, ogImageWidth: null, ogImageHeight: null, ogImageAlt: null, twitterImage: null, twitterImageAlt: null })
|
|
34
24
|
}
|
|
35
25
|
else if (input.image) {
|
|
@@ -44,7 +34,6 @@ export function useDocsSeo(input: DocsSeoInput): void {
|
|
|
44
34
|
description: description ?? "",
|
|
45
35
|
site: site.name,
|
|
46
36
|
section: section?.title ?? "",
|
|
47
|
-
// A path, so the prerender reads the file from the build instead of fetching the site before it is deployed.
|
|
48
37
|
logo: site.logo ? site.logo.src : "",
|
|
49
38
|
host: site.url.replace(/^https?:\/\//, ""),
|
|
50
39
|
})
|
|
@@ -2,9 +2,6 @@ import { useCookie, useState } from "#imports"
|
|
|
2
2
|
import { docsTutorialNavigationCookie } from "#docs/navigation"
|
|
3
3
|
import { nextTick } from "vue"
|
|
4
4
|
|
|
5
|
-
// A page with a collapsed sidebar, such as a code panel tutorial, starts with a narrow strip so the content gets the
|
|
6
|
-
// page. Its button opens the sidebar. A cookie keeps the choice, so the server renders the same layout on the next
|
|
7
|
-
// visit and nothing jumps.
|
|
8
5
|
export function useDocsSidebarExpanded() {
|
|
9
6
|
return useCookie<boolean>(docsTutorialNavigationCookie, {
|
|
10
7
|
default: () => false,
|
|
@@ -13,13 +10,8 @@ export function useDocsSidebarExpanded() {
|
|
|
13
10
|
})
|
|
14
11
|
}
|
|
15
12
|
|
|
16
|
-
/** Ids of the buttons that open and collapse the sidebar. Only one of them is on the page at a time. */
|
|
17
13
|
export const docsSidebarToggleIds = { show: "vh-docs-sidebar-show", hide: "vh-docs-sidebar-hide" } as const
|
|
18
14
|
|
|
19
|
-
/**
|
|
20
|
-
* Opens or collapses the sidebar and focuses the opposite control after the DOM updates, whether the component mounts
|
|
21
|
-
* or only its toggle prop changes.
|
|
22
|
-
*/
|
|
23
15
|
export function useDocsSidebarToggle() {
|
|
24
16
|
const expanded = useDocsSidebarExpanded()
|
|
25
17
|
const focus = useState<string | null>("vh-docs-sidebar-focus", () => null)
|