Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

docs: add links to examples #4204

Merged
merged 5 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/components/atoms/LinkExample.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<Alert type="info" icon="πŸ”Ž">
Read and edit a live example in <NuxtLink :to="link" v-text="computedTitle" />
</Alert>
</template>

<script>
import { defineComponent } from '@nuxtjs/composition-api'
import createTitle from '~/utils/createTitle'

export default defineComponent({
props: {
link: {
type: String,
required: true
},
title: {
type: String,
required: false
}
},
computed: {
computedTitle () {
return createTitle(this.title, this.link)
}
}
})
</script>
5 changes: 2 additions & 3 deletions docs/components/atoms/ReadMore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<script>
import { defineComponent } from '@nuxtjs/composition-api'
import { splitByCase, upperFirst } from 'scule'
import createTitle from '~/utils/createTitle'

export default defineComponent({
props: {
Expand All @@ -22,8 +22,7 @@ export default defineComponent({
computed: {
computedTitle () {
// Guess title from link!
return this.title || this.link.split('/')
.filter(Boolean).map(part => splitByCase(part).map(p => upperFirst(p)).join(' ')).join(' > ')
return createTitle(this.title, this.link)
}
}
})
Expand Down
2 changes: 2 additions & 0 deletions docs/content/2.guide/2.features/11.teleports.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ The `to` target of `<Teleport>` expects a CSS selector string or an actual DOM n
</ClientOnly>
</template>
```

:LinkExample{link="/examples/app/teleport"}
2 changes: 2 additions & 0 deletions docs/content/2.guide/2.features/4.head-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ useHead({
})
</script>
```

:LinkExample{link="/examples/composables/use-head"}
4 changes: 4 additions & 0 deletions docs/content/2.guide/2.features/5.data-fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const { data } = await useAsyncData('count', () => $fetch('/api/count'))
</template>
```

:LinkExample{link="/examples/composables/use-async-data"}

## `useLazyAsyncData`

This composable behaves identically to `useAsyncData` with the `lazy: true` option set. In other words, the async function does not block navigation. That means you will need to handle the situation where the data is `null` (or whatever value you have provided in a custom `default` factory function).
Expand Down Expand Up @@ -79,6 +81,8 @@ const { data } = await useFetch('/api/count')
</template>
```

:LinkExample{link="/examples/composables/use-fetch"}

## `useLazyFetch`

This composable behaves identically to `useFetch` with the `lazy: true` option set. In other words, the async function does not block navigation. That means you will need to handle the situation where the data is `null` (or whatever value you have provided in a custom `default` factory function).
Expand Down
4 changes: 2 additions & 2 deletions docs/content/2.guide/2.features/6.state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const counter = useState('counter', () => Math.round(Math.random() * 1000))
</template>
```

:button-link[Open on StackBlitz]{href="https://stackblitz.com/github/nuxt/framework/tree/main/examples/use-state?terminal=dev" blank}
:LinkExample{link="/examples/composables/use-state"}

::ReadMore{link="/api/composables/use-state"}
::
Expand All @@ -54,7 +54,7 @@ const counter = useState('counter', () => Math.round(Math.random() * 1000))

In this example, we use a composable that detects the user's default locale from the HTTP request headers and keeps it in a `locale` state.

:button-link[Open on StackBlitz]{href="https://stackblitz.com/github/nuxt/framework/tree/main/examples/locale?terminal=dev" blank}
:LinkExample{link="/examples/other/locale"}

## Shared state

Expand Down
2 changes: 2 additions & 0 deletions docs/content/2.guide/2.features/7.error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ If you navigate to another route, the error will be cleared automatically.
</NuxtErrorBoundary>
</template>
```

:LinkExample{link="/examples/app/error-handling"}
2 changes: 2 additions & 0 deletions docs/content/2.guide/2.features/8.plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@

::ReadMore{link="/guide/directory-structure/plugins"}
::

:LinkExample{link="/examples/app/plugins"}
2 changes: 2 additions & 0 deletions docs/content/2.guide/3.directory-structure/10.pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ definePageMeta({
</script>
```

:LinkExample{link="/examples/routing/pages"}

## Page Metadata

You might want to define metadata for each route in your app. You can do this using the `definePageMeta` macro, which will work both in `<script>` and in `<script setup>`:
Expand Down
2 changes: 2 additions & 0 deletions docs/content/2.guide/3.directory-structure/11.plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ export default defineNuxtPlugin((nuxtApp) => {
})
})
```

:LinkExample{link="/examples/app/plugins"}
2 changes: 2 additions & 0 deletions docs/content/2.guide/3.directory-structure/4.components.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,5 @@ export default {
```

It will automatically import the components only if used and also support HMR when updating your components in `node_modules/awesome-ui/components/`.

:LinkExample{link="/examples/auto-imports/components"}
2 changes: 2 additions & 0 deletions docs/content/2.guide/3.directory-structure/5.composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ You can now auto-import it:
const foo = useFoo()
</script>
```

:LinkExample{link="/examples/auto-imports/composables"}
2 changes: 2 additions & 0 deletions docs/content/2.guide/3.directory-structure/6.layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ definePageMeta({
});
</script>
```

:LinkExample{link="/examples/routing/layouts"}
2 changes: 2 additions & 0 deletions docs/content/2.guide/3.directory-structure/7.middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ definePageMeta({
```

Now, before navigation to that page can complete, the `auth` route middleware will be run.

:LinkExample{link="/examples/routing/middleware"}
2 changes: 2 additions & 0 deletions docs/content/3.api/1.composables/use-cookie.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,5 @@ export default (req, res) => {
return { counter }
}
```

:LinkExample{link="/examples/composables/use-cookie"}
2 changes: 2 additions & 0 deletions docs/content/3.api/2.components/4.nuxt-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ defineNuxtLink({
- **externalRelAttribute**: A default `rel` attribute value applied on external links. Defaults to `"noopener noreferrer"`. Set it to `""` to disable
- **activeClass**: A default class to apply on active links. Works the same as [Vue Router's `linkActiveClass` option](https://router.vuejs.org/api/#linkactiveclass). Defaults to Vue Router's default (`"router-link-active"`)
- **exactActiveClass**: A default class to apply on exact active links. Works the same as [Vue Router's `linkExactActiveClass` option](https://router.vuejs.org/api/#linkexactactiveclass). Defaults to Vue Router's default (`"router-link-exact-active"`)

:LinkExample{link="/examples/routing/nuxt-link"}
5 changes: 5 additions & 0 deletions docs/utils/createTitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { splitByCase, upperFirst } from 'scule'

export default (title, link) => {
return title || link.split('/').filter(Boolean).map(part => splitByCase(part).map(p => upperFirst(p)).join(' ')).join(' > ').replace('Api', 'API')
}