Skip to content

Commit

Permalink
docs: update examples for content helpers composable
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Oct 15, 2023
1 parent 1fab215 commit b6ff9ba
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions docs/content/3.composables/4.use-content-helpers.md
Expand Up @@ -24,10 +24,13 @@ Take a navigation node and will resolve the first available path from that node.

It can be useful to build nested navigations systems.

```ts
const { navigation } = useContent()
```vue
<script setup>
const { navBottomLink } = useContentHelpers()
const { data: navigation } = await useAsyncData('navigation', () => fetchContentNavigation())
const path = navBottomLink(navigation.value)
</script>
```

## `navDirFromPath()`
Expand All @@ -36,12 +39,14 @@ This function will take a path and will resolve the first available navigation n

It can be useful to find the current directory of a navigation node.

```ts
```vue
<script setup>
const route = useRoute()

const { navigation } = useContent()
const { navDirFromPath } = useContentHelpers()
const { data: navigation } = await useAsyncData('navigation', () => fetchContentNavigation())
const dir = navDirFromPath(route.path, navigation.value)
</script>
```

## `navPageFromPath()`
Expand All @@ -50,12 +55,14 @@ This function will take a path and will resolve the first available navigation p

It can be useful to find the current navigation node the page you're browsing.

```ts
```vue
<script setup>
const route = useRoute()

const { navigation } = useContent()
const { navPageFromPath } = useContentHelpers()
const { data: navigation } = await useAsyncData('navigation', () => fetchContentNavigation())
const page = navPageFromPath(route.path, navigation.value)
</script>
```

## `navKeyFromPath()`
Expand All @@ -64,10 +71,12 @@ This function will take a path and will resolve a specific key from that path.

It can be useful when you want to add a fallback on the `_dir.yml` value of a key in a page.

```ts
```vue
<script setup>
const route = useRoute()

const { navigation } = useContent()
const { navKeyFromPath } = useContentHelpers()
const { data: navigation } = await useAsyncData('navigation', () => fetchContentNavigation())
const layout = navKeyFromPath(route.path, 'layout', navigation.value)
</script>
```

0 comments on commit b6ff9ba

Please sign in to comment.