@movk/nuxt-docs 1.1.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 +265 -0
- package/app/app.config.ts +53 -0
- package/app/app.vue +73 -0
- package/app/components/AdsCarbon.vue +3 -0
- package/app/components/Footer.vue +32 -0
- package/app/components/PageHeaderLinks.vue +73 -0
- package/app/components/StarsBg.vue +122 -0
- package/app/components/content/ComponentEmits.vue +43 -0
- package/app/components/content/ComponentExample.vue +247 -0
- package/app/components/content/ComponentProps.vue +105 -0
- package/app/components/content/ComponentPropsLinks.vue +20 -0
- package/app/components/content/ComponentPropsSchema.vue +55 -0
- package/app/components/content/ComponentSlots.vue +50 -0
- package/app/components/content/HeroBackground.vue +65 -0
- package/app/components/content/HighlightInlineType.vue +39 -0
- package/app/components/content/Motion.vue +21 -0
- package/app/components/header/Header.vue +60 -0
- package/app/components/header/HeaderBody.vue +19 -0
- package/app/components/header/HeaderBottom.vue +26 -0
- package/app/components/header/HeaderLogo.vue +57 -0
- package/app/components/theme-picker/ThemePicker.vue +152 -0
- package/app/components/theme-picker/ThemePickerButton.vue +37 -0
- package/app/composables/fetchComponentExample.ts +32 -0
- package/app/composables/fetchComponentMeta.ts +34 -0
- package/app/composables/useCategory.ts +5 -0
- package/app/composables/useHeader.ts +6 -0
- package/app/composables/useNavigation.ts +89 -0
- package/app/error.vue +59 -0
- package/app/layouts/default.vue +3 -0
- package/app/layouts/docs.vue +31 -0
- package/app/pages/docs/[...slug].vue +158 -0
- package/app/pages/index.vue +30 -0
- package/app/pages/releases.vue +92 -0
- package/app/plugins/prettier.ts +67 -0
- package/app/plugins/theme.ts +82 -0
- package/app/types/index.d.ts +37 -0
- package/app/workers/prettier.js +36 -0
- package/content.config.ts +68 -0
- package/modules/component-example.ts +128 -0
- package/modules/component-meta.ts +22 -0
- package/modules/config.ts +79 -0
- package/modules/css.ts +33 -0
- package/nuxt.config.ts +80 -0
- package/package.json +55 -0
- package/server/api/component-example.get.ts +19 -0
- package/server/plugins/llms.ts +24 -0
- package/server/routes/raw/[...slug].md.get.ts +27 -0
- package/utils/git.ts +108 -0
- package/utils/meta.ts +29 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { ContentNavigationItem } from '@nuxt/content'
|
|
3
|
+
import { kebabCase } from 'scule'
|
|
4
|
+
|
|
5
|
+
definePageMeta({
|
|
6
|
+
layout: 'docs',
|
|
7
|
+
heroBackground: 'opacity-30'
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const route = useRoute()
|
|
11
|
+
const { toc, github } = useAppConfig()
|
|
12
|
+
|
|
13
|
+
const { data: page } = await useAsyncData(`docs-${kebabCase(route.path)}`, () => queryCollection('docs').path(route.path).first())
|
|
14
|
+
|
|
15
|
+
if (!page.value) {
|
|
16
|
+
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
|
|
20
|
+
|
|
21
|
+
const { data: surround } = await useAsyncData(`surround-${(kebabCase(route.path))}`, () => {
|
|
22
|
+
return queryCollectionItemSurroundings('docs', route.path, {
|
|
23
|
+
fields: ['description']
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const { findBreadcrumb } = useNavigation(navigation!)
|
|
28
|
+
|
|
29
|
+
const breadcrumb = computed(() => findBreadcrumb(page.value?.path as string))
|
|
30
|
+
|
|
31
|
+
const title = page.value?.seo?.title || page.value?.title
|
|
32
|
+
const description = page.value?.seo?.description || page.value?.description
|
|
33
|
+
|
|
34
|
+
const filterValidLinks = (links: Array<any>) => links.filter(Boolean)
|
|
35
|
+
|
|
36
|
+
function buildFileLink(type: 'edit' | 'blob') {
|
|
37
|
+
if (!github)
|
|
38
|
+
return null
|
|
39
|
+
|
|
40
|
+
const segments = [
|
|
41
|
+
github.url,
|
|
42
|
+
type,
|
|
43
|
+
github.branch,
|
|
44
|
+
github.rootDir,
|
|
45
|
+
'content',
|
|
46
|
+
`${page.value?.stem}.${page.value?.extension}`
|
|
47
|
+
].filter(Boolean)
|
|
48
|
+
|
|
49
|
+
return segments.join('/')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const pageLinks = computed(() => {
|
|
53
|
+
const links = []
|
|
54
|
+
|
|
55
|
+
if (github && github.url) {
|
|
56
|
+
links.push({
|
|
57
|
+
icon: 'i-lucide-file-code',
|
|
58
|
+
label: 'View source',
|
|
59
|
+
to: buildFileLink('blob'),
|
|
60
|
+
target: '_blank'
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return filterValidLinks([...(page.value?.links || []), ...links])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const communityLinks = computed(() => {
|
|
68
|
+
const links = []
|
|
69
|
+
|
|
70
|
+
if (github && github.url) {
|
|
71
|
+
links.push({
|
|
72
|
+
icon: 'i-lucide-file-pen',
|
|
73
|
+
label: 'Edit this page',
|
|
74
|
+
to: buildFileLink('edit'),
|
|
75
|
+
target: '_blank'
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return filterValidLinks([...links, ...(toc?.bottom?.links || [])])
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
useSeoMeta({
|
|
83
|
+
title,
|
|
84
|
+
ogTitle: title,
|
|
85
|
+
description,
|
|
86
|
+
ogDescription: description
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
defineOgImageComponent('Nuxt', {
|
|
90
|
+
title,
|
|
91
|
+
description
|
|
92
|
+
})
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<template>
|
|
96
|
+
<UPage v-if="page">
|
|
97
|
+
<UPageHeader :title="title">
|
|
98
|
+
<template #headline>
|
|
99
|
+
<UBreadcrumb :items="breadcrumb" />
|
|
100
|
+
</template>
|
|
101
|
+
|
|
102
|
+
<template #description>
|
|
103
|
+
<MDC
|
|
104
|
+
v-if="page.description"
|
|
105
|
+
:value="page.description"
|
|
106
|
+
unwrap="p"
|
|
107
|
+
:cache-key="`${kebabCase(route.path)}-description`"
|
|
108
|
+
/>
|
|
109
|
+
</template>
|
|
110
|
+
|
|
111
|
+
<template #links>
|
|
112
|
+
<UButton
|
|
113
|
+
v-for="link in pageLinks"
|
|
114
|
+
:key="link.label"
|
|
115
|
+
color="neutral"
|
|
116
|
+
variant="outline"
|
|
117
|
+
:target="link.to?.startsWith('http') ? '_blank' : undefined"
|
|
118
|
+
size="sm"
|
|
119
|
+
v-bind="link"
|
|
120
|
+
>
|
|
121
|
+
<template v-if="link.avatar" #leading>
|
|
122
|
+
<UAvatar v-bind="link.avatar" size="2xs" :alt="`${link.label} avatar`" />
|
|
123
|
+
</template>
|
|
124
|
+
</UButton>
|
|
125
|
+
<PageHeaderLinks />
|
|
126
|
+
</template>
|
|
127
|
+
</UPageHeader>
|
|
128
|
+
|
|
129
|
+
<UPageBody>
|
|
130
|
+
<ContentRenderer v-if="page.body" :value="page" />
|
|
131
|
+
|
|
132
|
+
<USeparator v-if="surround?.filter(Boolean).length" />
|
|
133
|
+
|
|
134
|
+
<UContentSurround :surround="surround" />
|
|
135
|
+
</UPageBody>
|
|
136
|
+
|
|
137
|
+
<template v-if="page?.body?.toc?.links?.length" #right>
|
|
138
|
+
<UContentToc
|
|
139
|
+
:title="toc?.title"
|
|
140
|
+
:links="page.body?.toc?.links"
|
|
141
|
+
highlight
|
|
142
|
+
class="z-[2]"
|
|
143
|
+
>
|
|
144
|
+
<template v-if="toc?.bottom" #bottom>
|
|
145
|
+
<div class="hidden lg:block space-y-6" :class="{ '!mt-6': page.body?.toc?.links?.length }">
|
|
146
|
+
<USeparator v-if="page.body?.toc?.links?.length" type="dashed" />
|
|
147
|
+
|
|
148
|
+
<UPageLinks v-if="communityLinks?.length" :title="toc.bottom.title" :links="communityLinks" />
|
|
149
|
+
|
|
150
|
+
<USeparator v-if="communityLinks?.length" type="dashed" />
|
|
151
|
+
|
|
152
|
+
<AdsCarbon />
|
|
153
|
+
</div>
|
|
154
|
+
</template>
|
|
155
|
+
</UContentToc>
|
|
156
|
+
</template>
|
|
157
|
+
</UPage>
|
|
158
|
+
</template>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const { data: page } = await useAsyncData('landing', () => queryCollection('landing').path('/').first())
|
|
3
|
+
if (!page.value) {
|
|
4
|
+
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const title = page.value.seo?.title || page.value.title
|
|
8
|
+
const description = page.value.seo?.description || page.value.description
|
|
9
|
+
|
|
10
|
+
useSeoMeta({
|
|
11
|
+
titleTemplate: '',
|
|
12
|
+
title,
|
|
13
|
+
description,
|
|
14
|
+
ogTitle: title,
|
|
15
|
+
ogDescription: description
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
defineOgImageComponent('Nuxt', {
|
|
19
|
+
title,
|
|
20
|
+
description
|
|
21
|
+
})
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<ContentRenderer
|
|
26
|
+
v-if="page"
|
|
27
|
+
:value="page"
|
|
28
|
+
:prose="false"
|
|
29
|
+
/>
|
|
30
|
+
</template>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const { data: page } = await useAsyncData('releases', () => queryCollection('releases').first())
|
|
3
|
+
if (!page.value) {
|
|
4
|
+
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const title = page.value.seo?.title || page.value.title
|
|
8
|
+
const description = page.value.seo?.description || page.value.description
|
|
9
|
+
|
|
10
|
+
useSeoMeta({
|
|
11
|
+
title,
|
|
12
|
+
description,
|
|
13
|
+
ogTitle: title,
|
|
14
|
+
ogDescription: description
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
defineOgImageComponent('Nuxt', {
|
|
18
|
+
title,
|
|
19
|
+
description
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const { data: versions } = await useFetch(page.value.hero.releases || '', {
|
|
23
|
+
transform: (data: {
|
|
24
|
+
releases: {
|
|
25
|
+
name?: string
|
|
26
|
+
tag: string
|
|
27
|
+
publishedAt: string
|
|
28
|
+
markdown: string
|
|
29
|
+
}[]
|
|
30
|
+
}) => {
|
|
31
|
+
return data.releases.map(release => ({
|
|
32
|
+
tag: release.tag,
|
|
33
|
+
title: release.name || release.tag,
|
|
34
|
+
date: release.publishedAt,
|
|
35
|
+
markdown: release.markdown
|
|
36
|
+
}))
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<div v-if="page">
|
|
43
|
+
<UPageHero
|
|
44
|
+
:title="page.hero.title"
|
|
45
|
+
:description="page.hero.description"
|
|
46
|
+
:links="page.hero.links"
|
|
47
|
+
class="md:border-b border-default"
|
|
48
|
+
:ui="{
|
|
49
|
+
container: 'relative lg:py-32'
|
|
50
|
+
}"
|
|
51
|
+
>
|
|
52
|
+
<template #top>
|
|
53
|
+
<div
|
|
54
|
+
class="absolute z-[-1] rounded-full bg-primary blur-[300px] size-60 sm:size-80 transform -translate-x-1/2 left-1/2 -translate-y-80"
|
|
55
|
+
/>
|
|
56
|
+
</template>
|
|
57
|
+
|
|
58
|
+
<LazyStarsBg />
|
|
59
|
+
|
|
60
|
+
<div
|
|
61
|
+
aria-hidden="true"
|
|
62
|
+
class="hidden md:block absolute z-[-1] border-x border-default inset-0 mx-4 sm:mx-6 lg:mx-8"
|
|
63
|
+
/>
|
|
64
|
+
</UPageHero>
|
|
65
|
+
|
|
66
|
+
<UPageSection :ui="{ container: '!py-0' }">
|
|
67
|
+
<div class="py-4 md:py-8 lg:py-16 md:border-x border-default">
|
|
68
|
+
<UContainer class="max-w-5xl">
|
|
69
|
+
<UChangelogVersions>
|
|
70
|
+
<UChangelogVersion
|
|
71
|
+
v-for="version in versions"
|
|
72
|
+
:key="version.tag"
|
|
73
|
+
v-bind="version"
|
|
74
|
+
:ui="{
|
|
75
|
+
root: 'flex items-start',
|
|
76
|
+
container: 'max-w-xl',
|
|
77
|
+
header: 'border-b border-default pb-4',
|
|
78
|
+
title: 'text-3xl',
|
|
79
|
+
date: 'text-xs/9 text-highlighted font-mono',
|
|
80
|
+
indicator: 'sticky top-0 pt-16 -mt-16 sm:pt-24 sm:-mt-24 lg:pt-32 lg:-mt-32'
|
|
81
|
+
}"
|
|
82
|
+
>
|
|
83
|
+
<template #body>
|
|
84
|
+
<MDC v-if="version.markdown" :value="version.markdown" />
|
|
85
|
+
</template>
|
|
86
|
+
</UChangelogVersion>
|
|
87
|
+
</UChangelogVersions>
|
|
88
|
+
</UContainer>
|
|
89
|
+
</div>
|
|
90
|
+
</UPageSection>
|
|
91
|
+
</div>
|
|
92
|
+
</template>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Options } from 'prettier'
|
|
2
|
+
import { defu } from 'defu'
|
|
3
|
+
import PrettierWorker from '@/workers/prettier.js?worker&inline'
|
|
4
|
+
|
|
5
|
+
export interface SimplePrettier {
|
|
6
|
+
format: (source: string, options?: Options) => Promise<string>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function createPrettierWorkerApi(worker: Worker): SimplePrettier {
|
|
10
|
+
let counter = 0
|
|
11
|
+
const handlers: any = {}
|
|
12
|
+
|
|
13
|
+
worker.addEventListener('message', (event) => {
|
|
14
|
+
const { uid, message, error } = event.data
|
|
15
|
+
|
|
16
|
+
if (!handlers[uid]) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const [resolve, reject] = handlers[uid]
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
22
|
+
delete handlers[uid]
|
|
23
|
+
|
|
24
|
+
if (error) {
|
|
25
|
+
reject(error)
|
|
26
|
+
} else {
|
|
27
|
+
resolve(message)
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
function postMessage<T>(message: any) {
|
|
32
|
+
const uid = ++counter
|
|
33
|
+
return new Promise<T>((resolve, reject) => {
|
|
34
|
+
handlers[uid] = [resolve, reject]
|
|
35
|
+
worker.postMessage({ uid, message })
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
format(source: string, options?: Options) {
|
|
41
|
+
return postMessage({ type: 'format', source, options })
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default defineNuxtPlugin(async () => {
|
|
47
|
+
let prettier: SimplePrettier
|
|
48
|
+
if (import.meta.server) {
|
|
49
|
+
const prettierModule = await import('prettier')
|
|
50
|
+
prettier = {
|
|
51
|
+
format(source, options = {}) {
|
|
52
|
+
return prettierModule.format(source, defu(options, {
|
|
53
|
+
parser: 'markdown'
|
|
54
|
+
}))
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
const worker = new PrettierWorker()
|
|
59
|
+
prettier = createPrettierWorkerApi(worker)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
provide: {
|
|
64
|
+
prettier
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
})
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export default defineNuxtPlugin({
|
|
2
|
+
enforce: 'post',
|
|
3
|
+
setup() {
|
|
4
|
+
const appConfig = useAppConfig()
|
|
5
|
+
const site = useSiteConfig()
|
|
6
|
+
|
|
7
|
+
if (import.meta.client) {
|
|
8
|
+
function updateColor(type: 'primary' | 'neutral') {
|
|
9
|
+
const color = localStorage.getItem(`${site.name}-ui-${type}`)
|
|
10
|
+
if (color) {
|
|
11
|
+
appConfig.ui.colors[type] = color
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function updateRadius() {
|
|
16
|
+
const radius = localStorage.getItem(`${site.name}-ui-radius`)
|
|
17
|
+
if (radius) {
|
|
18
|
+
appConfig.theme.radius = Number.parseFloat(radius)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function updateBlackAsPrimary() {
|
|
23
|
+
const blackAsPrimary = localStorage.getItem(`${site.name}-ui-black-as-primary`)
|
|
24
|
+
if (blackAsPrimary) {
|
|
25
|
+
appConfig.theme.blackAsPrimary = blackAsPrimary === 'true'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
updateColor('primary')
|
|
30
|
+
updateColor('neutral')
|
|
31
|
+
updateRadius()
|
|
32
|
+
updateBlackAsPrimary()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (import.meta.server) {
|
|
36
|
+
useHead({
|
|
37
|
+
script: [{
|
|
38
|
+
innerHTML: `
|
|
39
|
+
let html = document.querySelector('style#nuxt-ui-colors').innerHTML;
|
|
40
|
+
|
|
41
|
+
if (localStorage.getItem('${site.name}-ui-primary')) {
|
|
42
|
+
const primaryColor = localStorage.getItem('${site.name}-ui-primary');
|
|
43
|
+
if (primaryColor !== 'black') {
|
|
44
|
+
html = html.replace(
|
|
45
|
+
/(--ui-color-primary-\\d{2,3}:\\s*var\\(--color-)${appConfig.ui.colors.primary}(-\\d{2,3}.*?\\))/g,
|
|
46
|
+
\`$1\${primaryColor}$2\`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (localStorage.getItem('${site.name}-ui-neutral')) {
|
|
51
|
+
let neutralColor = localStorage.getItem('${site.name}-ui-neutral');
|
|
52
|
+
html = html.replace(
|
|
53
|
+
/(--ui-color-neutral-\\d{2,3}:\\s*var\\(--color-)${appConfig.ui.colors.neutral}(-\\d{2,3}.*?\\))/g,
|
|
54
|
+
\`$1\${neutralColor === 'neutral' ? 'old-neutral' : neutralColor}$2\`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
document.querySelector('style#nuxt-ui-colors').innerHTML = html;
|
|
59
|
+
`.replace(/\s+/g, ' '),
|
|
60
|
+
type: 'text/javascript',
|
|
61
|
+
tagPriority: -1
|
|
62
|
+
}, {
|
|
63
|
+
innerHTML: `
|
|
64
|
+
if (localStorage.getItem('${site.name}-ui-radius')) {
|
|
65
|
+
document.querySelector('style#nuxt-ui-radius').innerHTML = ':root { --ui-radius: ' + localStorage.getItem('${site.name}-ui-radius') + 'rem; }';
|
|
66
|
+
}
|
|
67
|
+
`.replace(/\s+/g, ' '),
|
|
68
|
+
type: 'text/javascript',
|
|
69
|
+
tagPriority: -1
|
|
70
|
+
}, {
|
|
71
|
+
innerHTML: `
|
|
72
|
+
if (localStorage.getItem('${site.name}-ui-black-as-primary') === 'true') {
|
|
73
|
+
document.querySelector('style#nuxt-ui-black-as-primary').innerHTML = ':root { --ui-primary: black; } .dark { --ui-primary: white; }';
|
|
74
|
+
} else {
|
|
75
|
+
document.querySelector('style#nuxt-ui-black-as-primary').innerHTML = '';
|
|
76
|
+
}
|
|
77
|
+
`.replace(/\s+/g, ' ')
|
|
78
|
+
}]
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ButtonProps } from '@nuxt/ui'
|
|
2
|
+
|
|
3
|
+
declare module 'nuxt/schema' {
|
|
4
|
+
interface AppConfig {
|
|
5
|
+
seo: {
|
|
6
|
+
titleTemplate: string
|
|
7
|
+
title: string
|
|
8
|
+
description: string
|
|
9
|
+
}
|
|
10
|
+
header: {
|
|
11
|
+
title: string
|
|
12
|
+
to: string
|
|
13
|
+
search: boolean
|
|
14
|
+
colorMode: boolean
|
|
15
|
+
links: ButtonProps[]
|
|
16
|
+
}
|
|
17
|
+
footer: {
|
|
18
|
+
credits: string
|
|
19
|
+
socials: ButtonProps[]
|
|
20
|
+
}
|
|
21
|
+
toc: {
|
|
22
|
+
title: string
|
|
23
|
+
bottom: {
|
|
24
|
+
title: string
|
|
25
|
+
links: ButtonProps[]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
github: {
|
|
29
|
+
url: string
|
|
30
|
+
branch: string
|
|
31
|
+
rootDir: string
|
|
32
|
+
} | false
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// It is always important to ensure you import/export something when augmenting a type
|
|
37
|
+
export { }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
self.onmessage = async function (event) {
|
|
3
|
+
self.postMessage({
|
|
4
|
+
uid: event.data.uid,
|
|
5
|
+
message: await handleMessage(event.data.message)
|
|
6
|
+
})
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function handleMessage(message) {
|
|
10
|
+
switch (message.type) {
|
|
11
|
+
case 'format':
|
|
12
|
+
return handleFormatMessage(message)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function handleFormatMessage(message) {
|
|
17
|
+
if (!globalThis.prettier) {
|
|
18
|
+
await Promise.all([
|
|
19
|
+
import('https://cdn.jsdelivr.net/npm/prettier@3.6.2/standalone.js'),
|
|
20
|
+
import('https://cdn.jsdelivr.net/npm/prettier@3.6.2/plugins/babel.js'),
|
|
21
|
+
import('https://cdn.jsdelivr.net/npm/prettier@3.6.2/plugins/estree.js'),
|
|
22
|
+
import('https://cdn.jsdelivr.net/npm/prettier@3.6.2/plugins/html.js'),
|
|
23
|
+
import('https://cdn.jsdelivr.net/npm/prettier@3.6.2/plugins/markdown.js'),
|
|
24
|
+
import('https://cdn.jsdelivr.net/npm/prettier@3.6.2/plugins/typescript.js')
|
|
25
|
+
])
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { options, source } = message
|
|
29
|
+
const formatted = await prettier.format(source, {
|
|
30
|
+
parser: 'markdown',
|
|
31
|
+
plugins: prettierPlugins,
|
|
32
|
+
...options
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return formatted
|
|
36
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
|
|
2
|
+
import { useNuxt } from '@nuxt/kit'
|
|
3
|
+
import { asSeoCollection } from '@nuxtjs/seo/content'
|
|
4
|
+
import { joinURL } from 'ufo'
|
|
5
|
+
|
|
6
|
+
const { options } = useNuxt()
|
|
7
|
+
const cwd = joinURL(options.rootDir, 'content')
|
|
8
|
+
|
|
9
|
+
const Avatar = z.object({
|
|
10
|
+
src: z.string(),
|
|
11
|
+
alt: z.string().optional()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const Button = z.object({
|
|
15
|
+
label: z.string(),
|
|
16
|
+
icon: z.string().optional(),
|
|
17
|
+
avatar: Avatar.optional(),
|
|
18
|
+
leadingIcon: z.string().optional(),
|
|
19
|
+
trailingIcon: z.string().optional(),
|
|
20
|
+
to: z.string().optional(),
|
|
21
|
+
target: z.enum(['_blank', '_self']).optional(),
|
|
22
|
+
color: z.enum(['primary', 'neutral', 'success', 'warning', 'error', 'info']).optional(),
|
|
23
|
+
size: z.enum(['xs', 'sm', 'md', 'lg', 'xl']).optional(),
|
|
24
|
+
variant: z.enum(['solid', 'outline', 'subtle', 'soft', 'ghost', 'link']).optional(),
|
|
25
|
+
id: z.string().optional(),
|
|
26
|
+
class: z.string().optional()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export default defineContentConfig({
|
|
30
|
+
collections: {
|
|
31
|
+
landing: defineCollection(asSeoCollection({
|
|
32
|
+
type: 'page',
|
|
33
|
+
source: {
|
|
34
|
+
cwd,
|
|
35
|
+
include: 'index.md'
|
|
36
|
+
}
|
|
37
|
+
})),
|
|
38
|
+
docs: defineCollection(asSeoCollection({
|
|
39
|
+
type: 'page',
|
|
40
|
+
source: {
|
|
41
|
+
cwd,
|
|
42
|
+
include: 'docs/**/*'
|
|
43
|
+
},
|
|
44
|
+
schema: z.object({
|
|
45
|
+
links: z.array(Button),
|
|
46
|
+
category: z.string().optional(),
|
|
47
|
+
navigation: z.object({
|
|
48
|
+
title: z.string().optional()
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
})),
|
|
52
|
+
releases: defineCollection(asSeoCollection({
|
|
53
|
+
type: 'page',
|
|
54
|
+
source: {
|
|
55
|
+
cwd,
|
|
56
|
+
include: 'releases.yml'
|
|
57
|
+
},
|
|
58
|
+
schema: z.object({
|
|
59
|
+
hero: z.object({
|
|
60
|
+
title: z.string(),
|
|
61
|
+
description: z.string().optional(),
|
|
62
|
+
releases: z.string(),
|
|
63
|
+
links: z.array(Button).optional()
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
}))
|
|
67
|
+
}
|
|
68
|
+
})
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import fsp from 'node:fs/promises'
|
|
3
|
+
import { dirname, join } from 'pathe'
|
|
4
|
+
import { defineNuxtModule, addTemplate, addServerHandler, createResolver } from '@nuxt/kit'
|
|
5
|
+
|
|
6
|
+
export default defineNuxtModule({
|
|
7
|
+
meta: {
|
|
8
|
+
name: 'component-example'
|
|
9
|
+
},
|
|
10
|
+
async setup(_options, nuxt) {
|
|
11
|
+
const resolver = createResolver(import.meta.url)
|
|
12
|
+
let _configResolved: any
|
|
13
|
+
let components: Record<string, any>
|
|
14
|
+
const outputPath = join(nuxt.options.buildDir, 'component-example')
|
|
15
|
+
|
|
16
|
+
async function stubOutput() {
|
|
17
|
+
if (existsSync(outputPath + '.mjs')) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
await updateOutput('export default {}')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function fetchComponent(component: string | any) {
|
|
24
|
+
if (typeof component === 'string') {
|
|
25
|
+
if (components[component]) {
|
|
26
|
+
component = components[component]
|
|
27
|
+
} else {
|
|
28
|
+
component = Object.entries(components).find(
|
|
29
|
+
([, comp]: any) => comp.filePath === component
|
|
30
|
+
)
|
|
31
|
+
if (!component) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
component = component[1]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!component?.filePath || !component?.pascalName) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
const code = await fsp.readFile(component.filePath, 'utf-8')
|
|
43
|
+
components[component.pascalName] = {
|
|
44
|
+
code,
|
|
45
|
+
filePath: component.filePath,
|
|
46
|
+
pascalName: component.pascalName
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const getStringifiedComponents = () => JSON.stringify(components, null, 2)
|
|
50
|
+
|
|
51
|
+
const getVirtualModuleContent = () =>
|
|
52
|
+
`export default ${getStringifiedComponents()}`
|
|
53
|
+
|
|
54
|
+
async function updateOutput(content?: string) {
|
|
55
|
+
const path = outputPath + '.mjs'
|
|
56
|
+
if (!existsSync(dirname(path))) {
|
|
57
|
+
await fsp.mkdir(dirname(path), { recursive: true })
|
|
58
|
+
}
|
|
59
|
+
if (existsSync(path)) {
|
|
60
|
+
await fsp.unlink(path)
|
|
61
|
+
}
|
|
62
|
+
await fsp.writeFile(path, content || getVirtualModuleContent(), 'utf-8')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function fetchComponents() {
|
|
66
|
+
await Promise.all(Object.keys(components).map(fetchComponent))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
nuxt.hook('components:extend', async (_components) => {
|
|
70
|
+
components = _components
|
|
71
|
+
.filter(v => v.shortPath.includes('components/content/examples/'))
|
|
72
|
+
.reduce((acc, component) => {
|
|
73
|
+
acc[component.pascalName] = component
|
|
74
|
+
return acc
|
|
75
|
+
}, {} as Record<string, any>)
|
|
76
|
+
await stubOutput()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
addTemplate({
|
|
80
|
+
filename: 'component-example.mjs',
|
|
81
|
+
getContents: () => 'export default {}',
|
|
82
|
+
write: true
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
nuxt.hook('vite:extend', (vite: any) => {
|
|
86
|
+
vite.config.plugins = vite.config.plugins || []
|
|
87
|
+
vite.config.plugins.push({
|
|
88
|
+
name: 'component-example',
|
|
89
|
+
enforce: 'post',
|
|
90
|
+
async buildStart() {
|
|
91
|
+
if (_configResolved?.build.ssr) {
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
await fetchComponents()
|
|
95
|
+
await updateOutput()
|
|
96
|
+
},
|
|
97
|
+
configResolved(config: any) {
|
|
98
|
+
_configResolved = config
|
|
99
|
+
},
|
|
100
|
+
async handleHotUpdate({ file }: { file: any }) {
|
|
101
|
+
if (
|
|
102
|
+
Object.entries(components).some(
|
|
103
|
+
([, comp]: any) => comp.filePath === file
|
|
104
|
+
)
|
|
105
|
+
) {
|
|
106
|
+
await fetchComponent(file)
|
|
107
|
+
await updateOutput()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
nuxt.hook('nitro:config', (nitroConfig) => {
|
|
114
|
+
nitroConfig.virtual = nitroConfig.virtual || {}
|
|
115
|
+
nitroConfig.virtual['#component-example/nitro'] = () =>
|
|
116
|
+
readFileSync(
|
|
117
|
+
join(nuxt.options.buildDir, '/component-example.mjs'),
|
|
118
|
+
'utf-8'
|
|
119
|
+
)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
addServerHandler({
|
|
123
|
+
method: 'get',
|
|
124
|
+
route: '/api/component-example/:component?',
|
|
125
|
+
handler: resolver.resolve('../server/api/component-example.get')
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
})
|