docus 1.0.6 → 3.0.0-beta.1
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 +9 -22
- package/app/router.options.ts +18 -0
- package/assets/css/fonts.css +84 -0
- package/assets/css/main.css +11 -0
- package/assets/css/tailwind.css +282 -0
- package/components/app/Container.vue +23 -0
- package/components/app/Footer.vue +38 -0
- package/components/app/Navbar.vue +26 -0
- package/components/app/NavbarLogo.vue +31 -0
- package/components/app/Page.vue +7 -0
- package/components/app/PoweredByDocus.vue +11 -0
- package/components/content/Alert.vue +124 -0
- package/components/content/BlockHero.vue +54 -0
- package/components/content/ButtonLink.vue +44 -0
- package/components/content/Card.vue +46 -0
- package/components/content/CardGrid.vue +23 -0
- package/components/content/CodeBlock.vue +47 -0
- package/components/content/CodeGroup.vue +134 -0
- package/components/content/CopyButton.vue +48 -0
- package/components/content/List.vue +5 -0
- package/components/content/NeedContribution.vue +23 -0
- package/components/content/ReadMore.vue +24 -0
- package/components/content/Sandbox.vue +100 -0
- package/components/content/TabsHeader.vue +44 -0
- package/components/content/Terminal.vue +70 -0
- package/components/content/VideoPlayer.vue +113 -0
- package/components/docs/DocsAside.vue +19 -0
- package/components/docs/DocsAsideTree.vue +101 -0
- package/components/docs/DocsHero.vue +39 -0
- package/components/docs/DocsPage.vue +22 -0
- package/components/docs/DocsPageContent.vue +29 -0
- package/components/docs/DocsToc.vue +72 -0
- package/components/globals/Icon.vue +24 -0
- package/components/globals/Logo.vue +3 -0
- package/components/globals/NuxtImg.vue +43 -0
- package/components/globals/SocialIcons.vue +43 -0
- package/components/globals/ThemeSelect.vue +35 -0
- package/components/icons/IconAlgolia.vue +8 -0
- package/components/icons/IconArrowLeft.vue +10 -0
- package/components/icons/IconArrowRight.vue +10 -0
- package/components/icons/IconBadgeCheck.vue +14 -0
- package/components/icons/IconCheck.vue +10 -0
- package/components/icons/IconCheckCircle.vue +10 -0
- package/components/icons/IconChevronRight.vue +12 -0
- package/components/icons/IconClipboardCheck.vue +14 -0
- package/components/icons/IconClipboardCopy.vue +14 -0
- package/components/icons/IconCodeSandbox.vue +8 -0
- package/components/icons/IconCopy.vue +17 -0
- package/components/icons/IconDots.vue +10 -0
- package/components/icons/IconEdit.vue +18 -0
- package/components/icons/IconExclamationCircle.vue +12 -0
- package/components/icons/IconExclamationTriangle.vue +10 -0
- package/components/icons/IconExternalLink.vue +12 -0
- package/components/icons/IconGit.vue +7 -0
- package/components/icons/IconGitHub.vue +10 -0
- package/components/icons/IconHeart.vue +9 -0
- package/components/icons/IconInformationCircle.vue +10 -0
- package/components/icons/IconLighthouse.vue +83 -0
- package/components/icons/IconLine.vue +10 -0
- package/components/icons/IconMarkdown.vue +13 -0
- package/components/icons/IconMenu.vue +12 -0
- package/components/icons/IconMenuAlt.vue +10 -0
- package/components/icons/IconMinus.vue +10 -0
- package/components/icons/IconMoon.vue +10 -0
- package/components/icons/IconNuxt.vue +14 -0
- package/components/icons/IconNuxtContent.vue +20 -0
- package/components/icons/IconNuxtLabs.vue +21 -0
- package/components/icons/IconPlus.vue +10 -0
- package/components/icons/IconPuzzle.vue +8 -0
- package/components/icons/IconSSG.vue +7 -0
- package/components/icons/IconSearch.vue +12 -0
- package/components/icons/IconSun.vue +10 -0
- package/components/icons/IconTocBack.vue +21 -0
- package/components/icons/IconTocCurrent.vue +21 -0
- package/components/icons/IconTocNext.vue +8 -0
- package/components/icons/IconTranslate.vue +14 -0
- package/components/icons/IconTwitter.vue +8 -0
- package/components/icons/IconVite.vue +30 -0
- package/components/icons/IconVue.vue +6 -0
- package/components/icons/IconVueTelescope.vue +11 -0
- package/components/icons/IconWindi.vue +17 -0
- package/components/icons/IconX.vue +12 -0
- package/components/icons/IconXCircle.vue +10 -0
- package/components/icons/IconZap.vue +8 -0
- package/components/prose/ProseA.vue +66 -0
- package/components/prose/ProseBlockquote.vue +21 -0
- package/components/prose/ProseCode.vue +68 -0
- package/components/prose/ProseCodeInline.vue +38 -0
- package/components/prose/ProseEm.vue +11 -0
- package/components/prose/ProseH1.vue +22 -0
- package/components/prose/ProseH2.vue +22 -0
- package/components/prose/ProseH3.vue +24 -0
- package/components/prose/ProseH4.vue +24 -0
- package/components/prose/ProseHr.vue +13 -0
- package/components/prose/ProseImg.vue +32 -0
- package/components/prose/ProseLi.vue +31 -0
- package/components/prose/ProseOl.vue +16 -0
- package/components/prose/ProseP.vue +14 -0
- package/components/prose/ProseStrong.vue +14 -0
- package/components/prose/ProseTable.vue +13 -0
- package/components/prose/ProseTbody.vue +5 -0
- package/components/prose/ProseTd.vue +11 -0
- package/components/prose/ProseTh.vue +11 -0
- package/components/prose/ProseThead.vue +11 -0
- package/components/prose/ProseTr.vue +11 -0
- package/components/prose/ProseUl.vue +15 -0
- package/composables/useContent.ts +155 -0
- package/composables/useMenu.ts +20 -0
- package/composables/useScrollToHeading.ts +35 -0
- package/composables/useScrollspy.ts +45 -0
- package/composables/useTheme.ts +10 -0
- package/layouts/default.vue +27 -0
- package/layouts/page.vue +11 -0
- package/nuxt.config.ts +151 -0
- package/package.json +45 -63
- package/pages/[...slug].vue +24 -0
- package/public/android-chrome-192x192.png +0 -0
- package/public/android-chrome-512x512.png +0 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon-16x16.png +0 -0
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/site.webmanifest +1 -0
- package/dist/create-docus/create-docus.js +0 -7
- package/dist/create-docus/index.js +0 -122
- package/dist/helpers.js +0 -154
- package/dist/index.js +0 -10
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 48 48" width="64" height="64">
|
|
3
|
+
<polygon
|
|
4
|
+
fill="#ffae0b"
|
|
5
|
+
points="16.828,5.828 29.966,5.828 25.172,19.414 33.966,19.414 18.621,43.138 21.034,26.379 12.828,26.379"
|
|
6
|
+
/>
|
|
7
|
+
</svg>
|
|
8
|
+
</template>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps({
|
|
3
|
+
href: {
|
|
4
|
+
type: String,
|
|
5
|
+
default: '',
|
|
6
|
+
},
|
|
7
|
+
blank: {
|
|
8
|
+
type: Boolean,
|
|
9
|
+
default: false,
|
|
10
|
+
},
|
|
11
|
+
/**
|
|
12
|
+
* `true` if `href` points to a static file
|
|
13
|
+
*/
|
|
14
|
+
static: {
|
|
15
|
+
type: Boolean,
|
|
16
|
+
default: false,
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<NuxtLink :to="href" :blank="blank" :static="static">
|
|
23
|
+
<slot />
|
|
24
|
+
</NuxtLink>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<style lang="postcss" scoped>
|
|
28
|
+
:not(h1, h2, h3, h4) > a {
|
|
29
|
+
@apply font-medium no-underline d-prose-a-text d-prose-a-border hover:d-prose-a-border-hover;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
h1 a,
|
|
33
|
+
h2 a,
|
|
34
|
+
h3 a,
|
|
35
|
+
h4 a {
|
|
36
|
+
@apply relative;
|
|
37
|
+
&::after {
|
|
38
|
+
@apply absolute pl-2 w-5 h-5 opacity-0;
|
|
39
|
+
content: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="%23111827"%3E%3Cpath stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1" /%3E%3C/svg%3E');
|
|
40
|
+
}
|
|
41
|
+
&:hover {
|
|
42
|
+
&::after {
|
|
43
|
+
@apply opacity-100;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Hover underline */
|
|
48
|
+
&:before {
|
|
49
|
+
@apply absolute top-0 left-0 w-full;
|
|
50
|
+
content: '';
|
|
51
|
+
height: calc(100% + 4px);
|
|
52
|
+
}
|
|
53
|
+
&:hover:before {
|
|
54
|
+
@apply d-prose-a-headline-border;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.dark h1 a,
|
|
59
|
+
.dark h2 a,
|
|
60
|
+
.dark h3 a,
|
|
61
|
+
.dark h4 a {
|
|
62
|
+
&::after {
|
|
63
|
+
content: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="white"%3E%3Cpath stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1" /%3E%3C/svg%3E');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<blockquote>
|
|
3
|
+
<slot />
|
|
4
|
+
</blockquote>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<style lang="postcss" scoped>
|
|
8
|
+
blockquote {
|
|
9
|
+
@apply text-base mt-[1.5em] mb-[1.5em] font-medium pl-4 d-prose-blockquote-text d-prose-blockquote-border;
|
|
10
|
+
|
|
11
|
+
quotes: '201C' '201D' '2018' '2019';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
blockquote p:first-of-type::before {
|
|
15
|
+
content: '';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
blockquote p:last-of-type::after {
|
|
19
|
+
content: '';
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { PropType } from 'vue'
|
|
3
|
+
import type { Lang } from 'shiki-es'
|
|
4
|
+
|
|
5
|
+
defineProps({
|
|
6
|
+
code: {
|
|
7
|
+
type: String,
|
|
8
|
+
default: '',
|
|
9
|
+
},
|
|
10
|
+
language: {
|
|
11
|
+
type: String as PropType<Lang>,
|
|
12
|
+
default: null,
|
|
13
|
+
},
|
|
14
|
+
filename: {
|
|
15
|
+
type: String,
|
|
16
|
+
default: null,
|
|
17
|
+
},
|
|
18
|
+
highlights: {
|
|
19
|
+
type: Array as () => number[],
|
|
20
|
+
default: () => [],
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<div class="prose-code w-full group">
|
|
27
|
+
<span v-if="filename" class="filename transition-base top-1 right-1 opacity-100 absolute right-0 z-0 m-1 py-1.5 px-2 text-gray-400 bg-gray-900 rounded-md font-mono text-xs leading-none tracking-tight">
|
|
28
|
+
{{ filename }}
|
|
29
|
+
</span>
|
|
30
|
+
|
|
31
|
+
<slot />
|
|
32
|
+
|
|
33
|
+
<CopyButton class="copy-button opacity-0 transition-base" />
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<style lang="postcss" scoped>
|
|
38
|
+
div {
|
|
39
|
+
@apply relative rounded-lg overflow-hidden my-4;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
:deep(pre) {
|
|
43
|
+
@apply flex flex-1 p-4 my-0 overflow-x-auto leading-normal;
|
|
44
|
+
background-color: #282c34;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
:deep(code) {
|
|
48
|
+
@apply flex flex-col;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:deep(.line) {
|
|
52
|
+
@apply inline-table min-h-[1rem];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
:deep(.line.highlight) {
|
|
56
|
+
background-color: #3f3f46;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.group:hover {
|
|
60
|
+
.filename {
|
|
61
|
+
@apply opacity-0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.copy-button {
|
|
65
|
+
@apply opacity-100;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
</style>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<code>
|
|
3
|
+
<slot />
|
|
4
|
+
</code>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<style lang="postcss" scoped>
|
|
8
|
+
code {
|
|
9
|
+
@apply font-normal text-sm py-[3px] px-[6px] rounded-md bg-gray-100 text-gray-800 dark:text-gray-100 dark:bg-gray-800;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
a code {
|
|
13
|
+
&:hover {
|
|
14
|
+
@apply border-primary-500;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
tbody code {
|
|
19
|
+
@apply text-[12px];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
h1 a,
|
|
23
|
+
h2 a,
|
|
24
|
+
h3 a,
|
|
25
|
+
h4 a {
|
|
26
|
+
code {
|
|
27
|
+
@apply relative;
|
|
28
|
+
font-size: inherit;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
& code:before {
|
|
32
|
+
@apply absolute top-[-2px] left-[-2px] -z-[1] d-prose-code-inline-bg rounded-md pointer-events-none;
|
|
33
|
+
content: '';
|
|
34
|
+
width: calc(100% + 4px);
|
|
35
|
+
height: calc(100% + 4px);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{ id: string }>()
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<h1 :id="id">
|
|
7
|
+
<NuxtLink :href="`#${id}`">
|
|
8
|
+
<slot />
|
|
9
|
+
</NuxtLink>
|
|
10
|
+
</h1>
|
|
11
|
+
</template>>
|
|
12
|
+
|
|
13
|
+
<style lang="postcss" scoped>
|
|
14
|
+
h1 {
|
|
15
|
+
font-size: 2rem;
|
|
16
|
+
@apply tracking-tight leading-snug font-semibold mt-[1em] mb-[0.5em];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
h1 + * {
|
|
20
|
+
@apply mt-0;
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{ id: string }>()
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<h2 :id="id">
|
|
7
|
+
<NuxtLink :href="`#${id}`">
|
|
8
|
+
<slot />
|
|
9
|
+
</NuxtLink>
|
|
10
|
+
</h2>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<style lang="postcss" scoped>
|
|
14
|
+
h2 {
|
|
15
|
+
font-size: 1.5rem;
|
|
16
|
+
@apply tracking-tight leading-snug font-semibold mt-[1.25em] mb-[0.5em];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
h2 + * {
|
|
20
|
+
@apply mt-0;
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{ id: string }>()
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<h3 :id="id">
|
|
7
|
+
<NuxtLink :href="`#${id}`">
|
|
8
|
+
<slot />
|
|
9
|
+
</NuxtLink>
|
|
10
|
+
</h3>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<style lang="postcss" scoped>
|
|
14
|
+
h3 {
|
|
15
|
+
/* TODO */
|
|
16
|
+
/* extend.fontSize do not work in Windi */
|
|
17
|
+
font-size: 1.25rem;
|
|
18
|
+
@apply tracking-tight leading-snug font-semibold mt-[1.25em] mb-[0.5em];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
h3 + * {
|
|
22
|
+
@apply mt-0;
|
|
23
|
+
}
|
|
24
|
+
</style>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{ id: string }>()
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<h4 :id="id">
|
|
7
|
+
<NuxtLink :href="`#${id}`">
|
|
8
|
+
<slot />
|
|
9
|
+
</NuxtLink>
|
|
10
|
+
</h4>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<style lang="postcss" scoped>
|
|
14
|
+
h4 {
|
|
15
|
+
/* TODO */
|
|
16
|
+
/* extend.fontSize do not work in Windi */
|
|
17
|
+
font-size: 1.125rem;
|
|
18
|
+
@apply tracking-tight leading-snug font-semibold mt-[1.25em] mb-[0.5em];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
h4 + * {
|
|
22
|
+
@apply mt-0;
|
|
23
|
+
}
|
|
24
|
+
</style>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export default {
|
|
3
|
+
props: {
|
|
4
|
+
src: {
|
|
5
|
+
type: String,
|
|
6
|
+
default: '',
|
|
7
|
+
},
|
|
8
|
+
alt: {
|
|
9
|
+
type: String,
|
|
10
|
+
default: '',
|
|
11
|
+
},
|
|
12
|
+
width: {
|
|
13
|
+
type: [String, Number],
|
|
14
|
+
default: undefined,
|
|
15
|
+
},
|
|
16
|
+
height: {
|
|
17
|
+
type: [String, Number],
|
|
18
|
+
default: undefined,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<NuxtImg :src="src" :alt="alt" :width="width" :height="height" />
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<style lang="postcss" scoped>
|
|
29
|
+
:deep(img) {
|
|
30
|
+
@apply my-[1em];
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<li><slot /></li>
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<style lang="postcss" scoped>
|
|
6
|
+
li {
|
|
7
|
+
@apply relative my-[0.25em] pl-4;
|
|
8
|
+
p {
|
|
9
|
+
@apply my-[0.75em];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
ul > li {
|
|
14
|
+
&::before {
|
|
15
|
+
@apply absolute left-0 top-[0.5em] d-prose-ul-li-bullet rounded-full w-1.5 h-1.5;
|
|
16
|
+
content: '';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
ol > li {
|
|
21
|
+
&::before {
|
|
22
|
+
@apply absolute left-0 top-0 d-secondary-text;
|
|
23
|
+
content: counter(list-item, decimal) '.';
|
|
24
|
+
content: counter(list-item, var(--list-counter-style, decimal)) '.';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
:deep(.nuxt-content-highlight) {
|
|
29
|
+
@apply m-0;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { withoutTrailingSlash } from 'ufo'
|
|
2
|
+
import type { NavItem, ParsedContent } from '@nuxt/content/dist/runtime/types'
|
|
3
|
+
|
|
4
|
+
let closeHook
|
|
5
|
+
|
|
6
|
+
export const useContent = () => {
|
|
7
|
+
const route = useRoute()
|
|
8
|
+
|
|
9
|
+
const path = computed(() => withoutTrailingSlash(route.path))
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Navigation tree from root of app.
|
|
13
|
+
*/
|
|
14
|
+
const navigation = useState<NavItem[]>('navigation', () => null)
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Current page complete data.
|
|
18
|
+
*/
|
|
19
|
+
const page = useState<ParsedContent>(`content-page-${path.value}`, () => null)
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Previous and next page data.
|
|
23
|
+
* Format: [prev, next]
|
|
24
|
+
*/
|
|
25
|
+
const surround = useState<ParsedContent[]>(`content-surround-${path.value}`, () => null)
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Table of contents from parsed page.
|
|
29
|
+
*/
|
|
30
|
+
const toc = computed(() => page?.value?.body?.toc?.links || [])
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Content type from parsed page.
|
|
34
|
+
*/
|
|
35
|
+
const type = computed(() => page.value?.meta?.type)
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Next page from `surround`.
|
|
39
|
+
*/
|
|
40
|
+
const next = computed(() => surround.value?.[1] || null)
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Previous page from `surround`.
|
|
44
|
+
*/
|
|
45
|
+
const prev = computed(() => surround.value?.[0] || null)
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Page list fetching helper.
|
|
49
|
+
*/
|
|
50
|
+
const fetchDir = async(path: string) => await queryContent(path).find()
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Find first child link from a navigation node.
|
|
54
|
+
*/
|
|
55
|
+
const findBottomLink = (link: NavItem) => {
|
|
56
|
+
let slug = link.slug
|
|
57
|
+
|
|
58
|
+
if (link.children && link.children.length)
|
|
59
|
+
slug = findBottomLink(link.children[0])
|
|
60
|
+
|
|
61
|
+
return slug
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Find current navigation node from a path.
|
|
66
|
+
*/
|
|
67
|
+
const navFromPath = (path: string, tree: NavItem[] = navigation.value) => {
|
|
68
|
+
for (const file of tree) {
|
|
69
|
+
if (file.children) {
|
|
70
|
+
const result = navFromPath(path, file.children)
|
|
71
|
+
if (result)
|
|
72
|
+
return result
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (file.slug === path)
|
|
76
|
+
return file
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Navigation fetching helper.
|
|
82
|
+
*/
|
|
83
|
+
const fetchNavigation = async(force = false) => {
|
|
84
|
+
if (navigation.value !== null && !force)
|
|
85
|
+
return
|
|
86
|
+
|
|
87
|
+
navigation.value = await fetchContentNavigation()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Local page fetching helper.
|
|
92
|
+
*/
|
|
93
|
+
const fetchPage = async(force = false) => {
|
|
94
|
+
if (page.value !== null && !force)
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
const splitted = path.value.split('/')
|
|
98
|
+
const directory = splitted.slice(0, splitted.length - 1).join('/')
|
|
99
|
+
|
|
100
|
+
// Get navigation node from current path
|
|
101
|
+
const file = navFromPath(path.value, navigation.value)
|
|
102
|
+
|
|
103
|
+
if (file && !file.children) {
|
|
104
|
+
// Path queried has a page (and is not a directory)
|
|
105
|
+
await Promise.all([
|
|
106
|
+
queryContent().where({ id: file.id }).findOne() as Promise<ParsedContent>,
|
|
107
|
+
queryContent(directory).findSurround(path.value) as Promise<ParsedContent[]>,
|
|
108
|
+
]).then(([_page, _surround]) => {
|
|
109
|
+
page.value = _page
|
|
110
|
+
surround.value = _surround
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
else if (file) {
|
|
114
|
+
navigateTo(findBottomLink(file))
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Re-fetch page on change (development only)
|
|
119
|
+
if (process.dev) {
|
|
120
|
+
onMounted(
|
|
121
|
+
() => {
|
|
122
|
+
// Cleanup previous hook before registering new one.
|
|
123
|
+
if (closeHook)
|
|
124
|
+
closeHook()
|
|
125
|
+
|
|
126
|
+
const { hook } = useNuxtApp()
|
|
127
|
+
|
|
128
|
+
closeHook = hook('app:data:refresh', async() => {
|
|
129
|
+
await fetchNavigation(true)
|
|
130
|
+
await fetchPage(true)
|
|
131
|
+
})
|
|
132
|
+
},
|
|
133
|
+
)
|
|
134
|
+
onBeforeUnmount(() => closeHook && closeHook())
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
// useState references
|
|
139
|
+
navigation,
|
|
140
|
+
page,
|
|
141
|
+
surround,
|
|
142
|
+
// Fetching helpers
|
|
143
|
+
fetchDir,
|
|
144
|
+
fetchPage,
|
|
145
|
+
fetchNavigation,
|
|
146
|
+
// Computed values
|
|
147
|
+
next,
|
|
148
|
+
prev,
|
|
149
|
+
type,
|
|
150
|
+
toc,
|
|
151
|
+
// Methods
|
|
152
|
+
navFromPath,
|
|
153
|
+
findBottomLink,
|
|
154
|
+
}
|
|
155
|
+
}
|