Skip to content

Commit

Permalink
docs: composables
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <zhangtianli2006@163.com>
  • Loading branch information
ZTL-UwU committed Jun 2, 2024
1 parent c88c66e commit 13f3c59
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions composables/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function useConfig() {
const main = appConfig?.value?.main || {};
const aside = appConfig?.value?.aside || {};
const footer = appConfig?.value?.footer || {};
const toc = appConfig?.value?.toc || {};

return {
...appConfig.value,
Expand All @@ -29,6 +30,11 @@ export function useConfig() {
...navKeyFromPath(route.path, 'aside', navigation.value || []),
...page.value?.aside,
} as typeof aside,
toc: {
...toc,
...navKeyFromPath(route.path, 'toc', navigation.value || []),
...page.value?.toc,
} as typeof toc,
footer: {
...footer,
...navKeyFromPath(route.path, 'footer', navigation.value || []),
Expand Down
33 changes: 32 additions & 1 deletion content/2.api/3.composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,35 @@ description: Composable functions exported by shadcn-docs-nuxt.
icon: 'lucide:square-function'
---

TODO
### `useConfig()`

Get the config from `app.config.ts`.

- `main`, `header`, `aside`, `footer` and `toc` can be set from `_dir.yml` and any `page.md` file.

```ts
const {
site,
search,
header,
main,
aside,
footer,
toc,
} = useConfig();
```

### `useScrollspy()`

Modified from [docus](https://github.com/nuxt-themes/docus/blob/main/composables/useScrollspy.ts). `useScrollspy()` is used in docs layout to make the ToC display the currently visible headings.

```ts
const {
// Headings on the page
visibleHeadings,
// Active headings (for the current page)
activeHeadings,
// Update headings (an array of DOM nodes)
updateHeadings
} = useScrollspy();
```

0 comments on commit 13f3c59

Please sign in to comment.