From 7e7e9d0f85b2b22bfd623cda27dab2384987ccdc Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Mon, 14 Aug 2023 22:11:04 +0200 Subject: [PATCH] docs: add version select (#532) --- docs/app.vue | 21 ++++++- docs/components/BranchSelect.vue | 50 ++++++++++++++++ docs/components/Header.vue | 2 + docs/components/content/ComponentCard.vue | 2 +- docs/components/content/ComponentPreset.vue | 2 +- docs/components/content/ComponentProps.vue | 2 +- docs/components/content/ComponentSlots.vue | 2 +- .../themes/CommandPaletteThemeAlgolia.vue | 3 +- docs/composables/useContentSource.ts | 57 +++++++++++++++++++ docs/content/1.getting-started/3.theming.md | 6 +- docs/content/2.elements/2.alert.md | 2 - docs/content/2.elements/3.avatar.md | 2 +- docs/content/2.elements/4.badge.md | 8 +-- docs/content/2.elements/9.link.md | 2 - docs/content/3.forms/10.form.md | 2 - docs/content/3.forms/4.select-menu.md | 2 +- docs/content/3.forms/9.form-group.md | 2 +- docs/content/5.navigation/4.tabs.md | 6 +- docs/content/6.overlays/6.notification.md | 2 +- docs/error.vue | 20 ++++++- docs/nuxt.config.ts | 21 ++++++- docs/package.json | 2 +- docs/pages/[...slug].vue | 16 ++++-- docs/public/robots.txt | 1 + pnpm-lock.yaml | 8 +-- 25 files changed, 198 insertions(+), 45 deletions(-) create mode 100644 docs/components/BranchSelect.vue create mode 100644 docs/composables/useContentSource.ts create mode 100644 docs/public/robots.txt diff --git a/docs/app.vue b/docs/app.vue index f994cdc2..9851423b 100644 --- a/docs/app.vue +++ b/docs/app.vue @@ -8,6 +8,8 @@ @@ -35,13 +37,27 @@ diff --git a/docs/components/BranchSelect.vue b/docs/components/BranchSelect.vue new file mode 100644 index 00000000..9af53b43 --- /dev/null +++ b/docs/components/BranchSelect.vue @@ -0,0 +1,50 @@ + + + diff --git a/docs/components/Header.vue b/docs/components/Header.vue index 29027a19..a3ddf53e 100644 --- a/docs/components/Header.vue +++ b/docs/components/Header.vue @@ -20,6 +20,8 @@ diff --git a/docs/components/content/ComponentCard.vue b/docs/components/content/ComponentCard.vue index 24a2bf94..c847ff79 100644 --- a/docs/components/content/ComponentCard.vue +++ b/docs/components/content/ComponentCard.vue @@ -115,7 +115,7 @@ const componentProps = reactive({ ...props.props }) const appConfig = useAppConfig() const route = useRoute() // eslint-disable-next-line vue/no-dupe-keys -const slug = props.slug || route.params.slug[1] +const slug = props.slug || route.params.slug[route.params.slug.length - 1] const camelName = useCamelCase(slug) const name = `U${useUpperFirst(camelName)}` diff --git a/docs/components/content/ComponentPreset.vue b/docs/components/content/ComponentPreset.vue index 0e5bd8c9..a49498d3 100644 --- a/docs/components/content/ComponentPreset.vue +++ b/docs/components/content/ComponentPreset.vue @@ -16,7 +16,7 @@ const props = defineProps({ const appConfig = useAppConfig() const route = useRoute() // eslint-disable-next-line vue/no-dupe-keys -const slug = props.slug || route.params.slug[1] +const slug = props.slug || route.params.slug[route.params.slug.length - 1] const camelName = useCamelCase(slug) const name = `U${useUpperFirst(camelName)}` diff --git a/docs/components/content/ComponentProps.vue b/docs/components/content/ComponentProps.vue index e04f4c15..7bfc3b41 100644 --- a/docs/components/content/ComponentProps.vue +++ b/docs/components/content/ComponentProps.vue @@ -29,7 +29,7 @@ const props = defineProps({ const route = useRoute() // eslint-disable-next-line vue/no-dupe-keys -const slug = props.slug || route.params.slug[1] +const slug = props.slug || route.params.slug[route.params.slug.length - 1] const camelName = useCamelCase(slug) const name = `U${useUpperFirst(camelName)}` diff --git a/docs/components/content/ComponentSlots.vue b/docs/components/content/ComponentSlots.vue index 5d3f49f0..052ed413 100644 --- a/docs/components/content/ComponentSlots.vue +++ b/docs/components/content/ComponentSlots.vue @@ -27,7 +27,7 @@ const props = defineProps({ const route = useRoute() // eslint-disable-next-line vue/no-dupe-keys -const slug = props.slug || route.params.slug[1] +const slug = props.slug || route.params.slug[route.params.slug.length - 1] const camelName = useCamelCase(slug) const name = `U${useUpperFirst(camelName)}` diff --git a/docs/components/content/themes/CommandPaletteThemeAlgolia.vue b/docs/components/content/themes/CommandPaletteThemeAlgolia.vue index b77a6bf1..b8c1f286 100644 --- a/docs/components/content/themes/CommandPaletteThemeAlgolia.vue +++ b/docs/components/content/themes/CommandPaletteThemeAlgolia.vue @@ -2,8 +2,7 @@ const commandPaletteRef = ref() const navigation = inject('navigation') - -const { data: files } = await useLazyAsyncData('search', () => queryContent().where({ _type: 'markdown' }).find(), { default: () => [] }) +const files = inject('files') const groups = computed(() => navigation.value.map(item => ({ key: item._path, diff --git a/docs/composables/useContentSource.ts b/docs/composables/useContentSource.ts new file mode 100644 index 00000000..9f0fd4ce --- /dev/null +++ b/docs/composables/useContentSource.ts @@ -0,0 +1,57 @@ +import type { NavItem, ParsedContent } from '@nuxt/content/dist/runtime/types' + +export const useContentSource = () => { + const route = useRoute() + const config = useRuntimeConfig().public + + const branches = [{ + name: 'dev', + icon: 'i-heroicons-cube', + suffix: 'dev', + label: 'Edge' + }, { + name: 'main', + icon: 'i-heroicons-cube', + suffix: 'latest', + label: `v${config.version}` + }] + + const branch = computed(() => branches.find(b => b.name === (route.path.startsWith('/dev') ? 'dev' : 'main'))) + + const prefix = computed(() => `/${branch.value.name}`) + + function removePrefixFromNavigation (navigation: NavItem[]): NavItem[] { + return navigation.map((link) => { + const { _path, children, ...rest } = link + + return { + ...rest, + _path: route.path.startsWith(prefix.value) ? _path : _path.replace(new RegExp(`^${prefix.value}`, 'g'), ''), + children: children?.length ? removePrefixFromNavigation(children) : undefined + } + }) + } + + function removePrefixFromFiles (files: ParsedContent[]) { + return files.map((file) => { + if (!file) { + return + } + + const { _path, ...rest } = file + + return { + ...rest, + _path: route.path.startsWith(prefix.value) ? _path : _path.replace(new RegExp(`^${prefix.value}`, 'g'), '') + } + }) + } + + return { + branches, + branch, + prefix, + removePrefixFromNavigation, + removePrefixFromFiles + } +} diff --git a/docs/content/1.getting-started/3.theming.md b/docs/content/1.getting-started/3.theming.md index c96f9f9b..32234c84 100644 --- a/docs/content/1.getting-started/3.theming.md +++ b/docs/content/1.getting-started/3.theming.md @@ -37,7 +37,7 @@ Likewise, you can't define a `primary` color in your `tailwind.config.ts` as it We'd advise you to use those colors in your components and pages, e.g. `text-primary-500 dark:text-primary-400`, `bg-gray-100 dark:bg-gray-900`, etc. so your app automatically adapts when changing your `app.config.ts`. :: -The `primary` color also has a `DEFAULT` shade that changes based on the theme. It is `500` in light mode and `400` in dark mode. You can use as a shortcut in your components and pages, e.g. `text-primary`, `bg-primary`, `focus-visible:ring-primary`, etc. :u-badge{label="Edge" class="!rounded-full" variant="subtle"} +The `primary` color also has a `DEFAULT` shade that changes based on the theme. It is `500` in light mode and `400` in dark mode. You can use as a shortcut in your components and pages, e.g. `text-primary`, `bg-primary`, `focus-visible:ring-primary`, etc. :u-badge{label="New" class="!rounded-full" variant="subtle"} ### Smart Safelisting @@ -107,7 +107,7 @@ Each component has a `ui` prop that allows you to customize everything specifica You can find the default classes for each component under the `Preset` section. :: -Thanks to [tailwind-merge](https://github.com/dcastil/tailwind-merge), the `ui` prop is smartly merged with the config. This means you don't have to rewrite everything. :u-badge{label="Edge" class="!rounded-full" variant="subtle"} +Thanks to [tailwind-merge](https://github.com/dcastil/tailwind-merge), the `ui` prop is smartly merged with the config. This means you don't have to rewrite everything. :u-badge{label="New" class="!rounded-full" variant="subtle"} For example, the default preset of the `FormGroup` component looks like this: @@ -142,7 +142,7 @@ You can also use the `class` attribute to add classes to the component. ``` -Again, with [tailwind-merge](https://github.com/dcastil/tailwind-merge), this will smartly merge the classes with the `ui` prop and the config. :u-badge{label="Edge" class="!rounded-full" variant="subtle"} +Again, with [tailwind-merge](https://github.com/dcastil/tailwind-merge), this will smartly merge the classes with the `ui` prop and the config. :u-badge{label="New" class="!rounded-full" variant="subtle"} ### Default values diff --git a/docs/content/2.elements/2.alert.md b/docs/content/2.elements/2.alert.md index 998d7ab4..0607c23b 100644 --- a/docs/content/2.elements/2.alert.md +++ b/docs/content/2.elements/2.alert.md @@ -4,8 +4,6 @@ links: - label: GitHub icon: i-simple-icons-github to: https://github.com/nuxtlabs/ui/blob/dev/src/runtime/components/elements/Alert.vue -navigation: - badge: New --- ## Usage diff --git a/docs/content/2.elements/3.avatar.md b/docs/content/2.elements/3.avatar.md index c3da0a13..da779f70 100644 --- a/docs/content/2.elements/3.avatar.md +++ b/docs/content/2.elements/3.avatar.md @@ -53,7 +53,7 @@ baseProps: If there is an error loading the `src` of the avatar or `src` is null / false a background placeholder will be displayed, customizable in `ui.avatar.background`. -#### Icon :u-badge{label="Edge" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} +#### Icon :u-badge{label="New" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} Use any icon from [Iconify](https://icones.js.org) by setting the `icon` prop by using this pattern: `i-{collection_name}-{icon_name}` or change it globally in `ui.avatar.default.icon` to display an icon on top of the background. diff --git a/docs/content/2.elements/4.badge.md b/docs/content/2.elements/4.badge.md index c7c2d5e7..54dfb772 100644 --- a/docs/content/2.elements/4.badge.md +++ b/docs/content/2.elements/4.badge.md @@ -31,7 +31,7 @@ props: Use the `color` and `variant` props to change the visual style of the Badge. -- `variant` can be `solid` (default), `outline`, `soft` or `subtle`. :u-badge{label="New" class="!rounded-full" variant="subtle"} +- `variant` can be `solid` (default), `outline`, `soft` or `subtle`. ::component-card --- @@ -45,7 +45,7 @@ Badge Besides all the colors from the `ui.colors` object, you can also use the `white` and `black` colors with their pre-defined variants. -#### White :u-badge{label="New" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} +#### White ::component-card --- @@ -62,7 +62,7 @@ excludedProps: Badge :: -#### Gray :u-badge{label="New" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} +#### Gray ::component-card --- @@ -79,7 +79,7 @@ excludedProps: Badge :: -#### Black :u-badge{label="New" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} +#### Black ::component-card --- diff --git a/docs/content/2.elements/9.link.md b/docs/content/2.elements/9.link.md index 6e859f12..8edd20b1 100644 --- a/docs/content/2.elements/9.link.md +++ b/docs/content/2.elements/9.link.md @@ -5,8 +5,6 @@ links: - label: GitHub icon: i-simple-icons-github to: https://github.com/nuxtlabs/ui/blob/dev/src/runtime/components/elements/Link.vue -navigation: - badge: New --- ## Usage diff --git a/docs/content/3.forms/10.form.md b/docs/content/3.forms/10.form.md index f607c008..ba0b6dd8 100644 --- a/docs/content/3.forms/10.form.md +++ b/docs/content/3.forms/10.form.md @@ -4,8 +4,6 @@ links: - label: GitHub icon: i-simple-icons-github to: https://github.com/nuxtlabs/ui/blob/dev/src/runtime/components/forms/Form.ts -navigation: - badge: New --- ## Usage diff --git a/docs/content/3.forms/4.select-menu.md b/docs/content/3.forms/4.select-menu.md index 8035bcfa..7cf21234 100644 --- a/docs/content/3.forms/4.select-menu.md +++ b/docs/content/3.forms/4.select-menu.md @@ -108,7 +108,7 @@ const selected = ref(people[0]) ``` :: -If you only want to select a single object property rather than the whole object as value, you can set the `value-attribute` property. This prop defaults to `null`. :u-badge{label="New" class="!rounded-full" variant="subtle"} +If you only want to select a single object property rather than the whole object as value, you can set the `value-attribute` property. This prop defaults to `null`. ::component-example #default diff --git a/docs/content/3.forms/9.form-group.md b/docs/content/3.forms/9.form-group.md index 5dbb9720..6865f946 100644 --- a/docs/content/3.forms/9.form-group.md +++ b/docs/content/3.forms/9.form-group.md @@ -159,7 +159,7 @@ code: >- Learn more about form validation in the `Form` component. :: -### Size :u-badge{label="New" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} +### Size Use the `size` prop to change the size of the label and the form element. diff --git a/docs/content/5.navigation/4.tabs.md b/docs/content/5.navigation/4.tabs.md index 5066c24c..f8dad58e 100644 --- a/docs/content/5.navigation/4.tabs.md +++ b/docs/content/5.navigation/4.tabs.md @@ -4,8 +4,6 @@ links: - label: GitHub icon: i-simple-icons-github to: https://github.com/nuxtlabs/ui/blob/dev/src/runtime/components/navigation/Tabs.vue -navigation: - badge: New --- ## Usage @@ -87,7 +85,7 @@ const items = [...] This will have no effect if you are using a `v-model` to control the selected index. :: -### Listen to changes :u-badge{label="Edge" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} +### Listen to changes :u-badge{label="New" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} You can listen to changes by using the `@change` event. The event will emit the index of the selected item. @@ -113,7 +111,7 @@ function onChange (index) { ``` :: -### Control the selected index :u-badge{label="Edge" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} +### Control the selected index :u-badge{label="New" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} Use a `v-model` to control the selected index. diff --git a/docs/content/6.overlays/6.notification.md b/docs/content/6.overlays/6.notification.md index d7fa955c..513c0144 100644 --- a/docs/content/6.overlays/6.notification.md +++ b/docs/content/6.overlays/6.notification.md @@ -316,7 +316,7 @@ excludedProps: ## Slots -### `title` / `description` :u-badge{label="New" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} +### `title` / `description` Use the `#title` and `#description` slots to customize the Notification. diff --git a/docs/error.vue b/docs/error.vue index 6fb841e6..1d2a5b1e 100644 --- a/docs/error.vue +++ b/docs/error.vue @@ -21,6 +21,8 @@ diff --git a/docs/nuxt.config.ts b/docs/nuxt.config.ts index 028551ff..59d476c5 100644 --- a/docs/nuxt.config.ts +++ b/docs/nuxt.config.ts @@ -7,7 +7,7 @@ import pkg from '../package.json' const { resolve } = createResolver(import.meta.url) export default defineNuxtConfig({ - extends: '@nuxthq/elements', + extends: process.env.NUXT_ELEMENTS_PATH || '@nuxthq/elements', modules: [ '@nuxt/content', // '@nuxt/devtools', @@ -30,6 +30,23 @@ export default defineNuxtConfig({ icons: ['heroicons', 'simple-icons'], safelistColors: excludeColors(colors) }, + content: { + sources: { + // overwrite default source AKA `content` directory + content: { + prefix: '/dev', + driver: 'fs', + base: resolve('./content') + }, + main: { + prefix: '/main', + driver: 'github', + repo: 'nuxtlabs/ui', + branch: 'main', + dir: 'docs/content' + } + } + }, googleFonts: { families: { Inter: [400, 500, 600, 700] @@ -40,7 +57,7 @@ export default defineNuxtConfig({ }, nitro: { prerender: { - routes: ['/getting-started'] + routes: ['/getting-started', '/dev/getting-started'] } }, experimental: { diff --git a/docs/package.json b/docs/package.json index 2dc83e1a..476e613a 100644 --- a/docs/package.json +++ b/docs/package.json @@ -10,7 +10,7 @@ "@nuxt/content": "^2.7.2", "@nuxt/devtools": "^0.8.0", "@nuxt/eslint-config": "^0.1.1", - "@nuxthq/elements": "npm:@nuxthq/elements-edge@0.0.1-28197629.5e2d155", + "@nuxthq/elements": "npm:@nuxthq/elements-edge@0.0.1-28198976.e8e2f70", "@nuxthq/studio": "^0.13.4", "@nuxtjs/fontaine": "^0.4.1", "@nuxtjs/google-fonts": "^3.0.2", diff --git a/docs/pages/[...slug].vue b/docs/pages/[...slug].vue index 3ffd0252..af35ec52 100644 --- a/docs/pages/[...slug].vue +++ b/docs/pages/[...slug].vue @@ -11,7 +11,7 @@
- +