@vuepress/theme-default 2.0.0-beta.6 → 2.0.0-beta.61
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/lib/client/components/AutoLink.vue +114 -0
- package/lib/client/components/DropdownTransition.vue +21 -0
- package/lib/client/components/Home.vue +15 -0
- package/lib/client/components/HomeContent.vue +5 -0
- package/lib/client/components/HomeFeatures.vue +23 -0
- package/lib/client/components/HomeFooter.vue +17 -0
- package/lib/client/components/HomeHero.vue +98 -0
- package/lib/client/components/Navbar.vue +75 -0
- package/lib/client/components/NavbarBrand.vue +55 -0
- package/lib/client/components/NavbarDropdown.vue +126 -0
- package/lib/{components/NavbarLinks.vue → client/components/NavbarItems.vue} +61 -50
- package/lib/{components → client/components}/Page.vue +9 -15
- package/lib/{components → client/components}/PageMeta.vue +51 -66
- package/lib/{components → client/components}/PageNav.vue +44 -57
- package/lib/client/components/Sidebar.vue +13 -0
- package/lib/client/components/SidebarItem.vue +87 -0
- package/lib/client/components/SidebarItems.vue +57 -0
- package/lib/client/components/ToggleColorModeButton.vue +57 -0
- package/lib/client/components/ToggleSidebarButton.vue +24 -0
- package/lib/client/components/global/Badge.vue +31 -0
- package/lib/client/components/global/CodeGroup.d.ts +4 -0
- package/lib/client/components/global/CodeGroup.js +106 -0
- package/lib/client/components/global/CodeGroupItem.vue +31 -0
- package/lib/client/components/global/index.d.ts +4 -0
- package/lib/client/components/global/index.js +4 -0
- package/lib/client/composables/index.d.ts +6 -0
- package/lib/client/composables/index.js +6 -0
- package/lib/client/composables/useDarkMode.d.ts +12 -0
- package/lib/client/composables/useDarkMode.js +57 -0
- package/lib/{composables → client/composables}/useNavLink.d.ts +6 -1
- package/lib/{composables → client/composables}/useNavLink.js +5 -2
- package/lib/{composables → client/composables}/useResolveRouteWithRedirect.d.ts +1 -1
- package/lib/{composables → client/composables}/useResolveRouteWithRedirect.js +2 -2
- package/lib/{composables → client/composables}/useScrollPromise.js +1 -1
- package/lib/client/composables/useSidebarItems.d.ts +36 -0
- package/lib/client/composables/useSidebarItems.js +118 -0
- package/lib/{composables → client/composables}/useThemeData.d.ts +2 -2
- package/lib/{composables → client/composables}/useThemeData.js +1 -1
- package/lib/client/config.d.ts +3 -0
- package/lib/client/config.js +44 -0
- package/lib/client/index.d.ts +3 -0
- package/lib/client/index.js +3 -0
- package/lib/client/layouts/Layout.vue +134 -0
- package/lib/client/layouts/NotFound.vue +27 -0
- package/lib/{styles/_wrapper.scss → client/styles/_mixins.scss} +7 -2
- package/lib/client/styles/_variables.scss +6 -0
- package/lib/{styles → client/styles}/arrow.scss +4 -6
- package/lib/client/styles/badge.scss +34 -0
- package/lib/{styles → client/styles}/code-group.scss +9 -2
- package/lib/{styles → client/styles}/code.scss +35 -49
- package/lib/client/styles/custom-container.scss +140 -0
- package/lib/{styles → client/styles}/home.scss +32 -24
- package/lib/{styles → client/styles}/index.scss +4 -4
- package/lib/client/styles/layout.scss +199 -0
- package/lib/{styles/dropdown.scss → client/styles/navbar-dropdown.scss} +36 -50
- package/lib/client/styles/navbar.scss +197 -0
- package/lib/client/styles/normalize.scss +200 -0
- package/lib/{styles → client/styles}/page.scss +24 -8
- package/lib/client/styles/sidebar.scss +134 -0
- package/lib/client/styles/transitions.scss +22 -0
- package/lib/client/styles/vars-dark.scss +68 -0
- package/lib/client/styles/vars.scss +149 -0
- package/lib/client/utils/index.d.ts +3 -0
- package/lib/client/utils/index.js +3 -0
- package/lib/client/utils/isActiveSidebarItem.d.ts +3 -0
- package/lib/client/utils/isActiveSidebarItem.js +20 -0
- package/lib/{utils → client/utils}/resolveEditLink.d.ts +2 -2
- package/lib/{utils → client/utils}/resolveEditLink.js +15 -9
- package/lib/client/utils/resolveRepoType.d.ts +2 -0
- package/lib/{utils → client/utils}/resolveRepoType.js +3 -1
- package/lib/node/defaultTheme.d.ts +10 -0
- package/lib/node/defaultTheme.js +117 -0
- package/lib/node/index.d.ts +5 -5
- package/lib/node/index.js +5 -17
- package/lib/node/utils/assignDefaultLocaleOptions.d.ts +7 -0
- package/lib/node/{assignDefaultLocaleOptions.js → utils/assignDefaultLocaleOptions.js} +13 -13
- package/lib/node/utils/index.d.ts +2 -0
- package/lib/node/utils/index.js +2 -0
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +8 -0
- package/lib/node/utils/resolveContainerPluginOptions.js +17 -0
- package/lib/shared/index.d.ts +3 -0
- package/lib/shared/index.js +3 -0
- package/lib/shared/nav.d.ts +42 -0
- package/lib/shared/nav.js +1 -0
- package/lib/{types → shared}/options.d.ts +51 -13
- package/lib/shared/options.js +1 -0
- package/lib/{types → shared}/page.d.ts +15 -6
- package/lib/shared/page.js +1 -0
- package/package.json +49 -29
- package/templates/build.html +33 -0
- package/CHANGELOG.md +0 -376
- package/lib/clientAppEnhance.d.ts +0 -3
- package/lib/clientAppEnhance.js +0 -30
- package/lib/clientAppSetup.d.ts +0 -2
- package/lib/clientAppSetup.js +0 -11
- package/lib/components/DropdownLink.vue +0 -141
- package/lib/components/DropdownTransition.vue +0 -34
- package/lib/components/Home.vue +0 -133
- package/lib/components/NavLink.vue +0 -115
- package/lib/components/Navbar.vue +0 -114
- package/lib/components/Sidebar.vue +0 -38
- package/lib/components/SidebarChild.d.ts +0 -6
- package/lib/components/SidebarChild.js +0 -91
- package/lib/components/ToggleSidebarButton.vue +0 -27
- package/lib/components/global/Badge.vue +0 -37
- package/lib/components/global/CodeGroup.d.ts +0 -5
- package/lib/components/global/CodeGroup.js +0 -52
- package/lib/components/global/CodeGroupItem.vue +0 -25
- package/lib/components/global/OutboundLink.vue +0 -30
- package/lib/composables/index.d.ts +0 -5
- package/lib/composables/index.js +0 -5
- package/lib/composables/useSidebarItems.d.ts +0 -31
- package/lib/composables/useSidebarItems.js +0 -114
- package/lib/index.d.ts +0 -6
- package/lib/index.js +0 -67
- package/lib/layouts/404.vue +0 -38
- package/lib/layouts/Layout.vue +0 -152
- package/lib/node/assignDefaultLocaleOptions.d.ts +0 -5
- package/lib/node/resolveActiveHeaderLinksPluginOptions.d.ts +0 -6
- package/lib/node/resolveActiveHeaderLinksPluginOptions.js +0 -16
- package/lib/node/resolveContainerPluginOptions.d.ts +0 -26
- package/lib/node/resolveContainerPluginOptions.js +0 -79
- package/lib/node/resolveGitPluginOptions.d.ts +0 -6
- package/lib/node/resolveGitPluginOptions.js +0 -22
- package/lib/node/resolveMediumZoomPluginOptions.d.ts +0 -6
- package/lib/node/resolveMediumZoomPluginOptions.js +0 -17
- package/lib/styles/_normalize.scss +0 -148
- package/lib/styles/_variables.scss +0 -34
- package/lib/styles/badge.scss +0 -33
- package/lib/styles/custom-container.scss +0 -78
- package/lib/styles/layout.scss +0 -194
- package/lib/styles/navbar.scss +0 -141
- package/lib/styles/plugins.scss +0 -18
- package/lib/styles/sidebar.scss +0 -152
- package/lib/styles/sr-only.scss +0 -12
- package/lib/styles/transitions.scss +0 -13
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -15
- package/lib/types/nav.d.ts +0 -44
- package/lib/types/nav.js +0 -2
- package/lib/types/options.js +0 -2
- package/lib/types/page.js +0 -2
- package/lib/utils/index.d.ts +0 -2
- package/lib/utils/index.js +0 -2
- package/lib/utils/resolveRepoType.d.ts +0 -2
- /package/lib/{composables → client/composables}/useScrollPromise.d.ts +0 -0
- /package/lib/{shim.d.ts → client/shim.d.ts} +0 -0
- /package/lib/{styles → client/styles}/toc.scss +0 -0
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { h } from 'vue';
|
|
2
|
-
import { useRoute } from 'vue-router';
|
|
3
|
-
import NavLink from './NavLink.vue';
|
|
4
|
-
const normalizePath = (path) => decodeURI(path)
|
|
5
|
-
.replace(/#.*$/, '')
|
|
6
|
-
.replace(/(index)?\.(md|html)$/, '');
|
|
7
|
-
const isActiveLink = (route, link) => {
|
|
8
|
-
if (link === undefined) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
if (route.hash === link) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
const currentPath = normalizePath(route.path);
|
|
15
|
-
const targetPath = normalizePath(link);
|
|
16
|
-
return currentPath === targetPath;
|
|
17
|
-
};
|
|
18
|
-
const isActiveItem = (route, item) => {
|
|
19
|
-
if (isActiveLink(route, item.link)) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
if (item.children) {
|
|
23
|
-
return item.children.some((child) => isActiveItem(route, child));
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
};
|
|
27
|
-
const renderItem = (item, props) => {
|
|
28
|
-
// if the item has link, render it as `<NavLink>`
|
|
29
|
-
if (item.link) {
|
|
30
|
-
return h(NavLink, {
|
|
31
|
-
...props,
|
|
32
|
-
item,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
// if the item only has text, render it as `<p>`
|
|
36
|
-
return h('p', props, item.text);
|
|
37
|
-
};
|
|
38
|
-
const renderChildren = (item, depth) => {
|
|
39
|
-
var _a;
|
|
40
|
-
if (!((_a = item.children) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
return h('ul', {
|
|
44
|
-
class: {
|
|
45
|
-
'sidebar-sub-headers': depth > 0,
|
|
46
|
-
},
|
|
47
|
-
}, item.children.map((child) => h('li', h(SidebarChild, {
|
|
48
|
-
item: child,
|
|
49
|
-
depth: depth + 1,
|
|
50
|
-
}))));
|
|
51
|
-
};
|
|
52
|
-
export const SidebarChild = ({ item, depth = 0 }) => {
|
|
53
|
-
const route = useRoute();
|
|
54
|
-
const active = isActiveItem(route, item);
|
|
55
|
-
if (item.isGroup) {
|
|
56
|
-
return [
|
|
57
|
-
h('section', {
|
|
58
|
-
class: 'sidebar-group',
|
|
59
|
-
}, [
|
|
60
|
-
renderItem(item, {
|
|
61
|
-
class: {
|
|
62
|
-
'sidebar-heading': true,
|
|
63
|
-
active,
|
|
64
|
-
},
|
|
65
|
-
}),
|
|
66
|
-
renderChildren(item, depth),
|
|
67
|
-
]),
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
return [
|
|
71
|
-
renderItem(item, {
|
|
72
|
-
class: {
|
|
73
|
-
'sidebar-link': true,
|
|
74
|
-
active,
|
|
75
|
-
},
|
|
76
|
-
}),
|
|
77
|
-
renderChildren(item, depth),
|
|
78
|
-
];
|
|
79
|
-
};
|
|
80
|
-
SidebarChild.displayName = 'SidebarChild';
|
|
81
|
-
SidebarChild.props = {
|
|
82
|
-
item: {
|
|
83
|
-
type: Object,
|
|
84
|
-
required: true,
|
|
85
|
-
},
|
|
86
|
-
depth: {
|
|
87
|
-
type: Number,
|
|
88
|
-
required: false,
|
|
89
|
-
default: 0,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="toggle-sidebar-button" @click="$emit('toggle')">
|
|
3
|
-
<svg
|
|
4
|
-
class="icon"
|
|
5
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
6
|
-
aria-hidden="true"
|
|
7
|
-
role="img"
|
|
8
|
-
viewBox="0 0 448 512"
|
|
9
|
-
>
|
|
10
|
-
<path
|
|
11
|
-
fill="currentColor"
|
|
12
|
-
d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"
|
|
13
|
-
class=""
|
|
14
|
-
/>
|
|
15
|
-
</svg>
|
|
16
|
-
</div>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<script lang="ts">
|
|
20
|
-
import { defineComponent } from 'vue'
|
|
21
|
-
|
|
22
|
-
export default defineComponent({
|
|
23
|
-
name: 'ToggleSidebarButton',
|
|
24
|
-
|
|
25
|
-
emits: ['toggle'],
|
|
26
|
-
})
|
|
27
|
-
</script>
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<span
|
|
3
|
-
class="badge"
|
|
4
|
-
:class="type"
|
|
5
|
-
:style="{
|
|
6
|
-
verticalAlign: vertical,
|
|
7
|
-
}"
|
|
8
|
-
>
|
|
9
|
-
<slot>{{ text }}</slot>
|
|
10
|
-
</span>
|
|
11
|
-
</template>
|
|
12
|
-
|
|
13
|
-
<script>
|
|
14
|
-
import { defineComponent } from 'vue'
|
|
15
|
-
|
|
16
|
-
export default defineComponent({
|
|
17
|
-
name: 'Badge',
|
|
18
|
-
|
|
19
|
-
props: {
|
|
20
|
-
type: {
|
|
21
|
-
type: String,
|
|
22
|
-
required: false,
|
|
23
|
-
default: 'tip',
|
|
24
|
-
},
|
|
25
|
-
text: {
|
|
26
|
-
type: String,
|
|
27
|
-
required: false,
|
|
28
|
-
default: '',
|
|
29
|
-
},
|
|
30
|
-
vertical: {
|
|
31
|
-
type: String,
|
|
32
|
-
required: false,
|
|
33
|
-
default: undefined,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
</script>
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { VNode } from 'vue';
|
|
2
|
-
declare const _default: import("vue").DefineComponent<{}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {}>, {}>;
|
|
5
|
-
export default _default;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { defineComponent, h, ref } from 'vue';
|
|
2
|
-
export default defineComponent({
|
|
3
|
-
name: 'CodeGroup',
|
|
4
|
-
setup(_, { slots }) {
|
|
5
|
-
// index of current active item
|
|
6
|
-
const activeIndex = ref(-1);
|
|
7
|
-
return () => {
|
|
8
|
-
// NOTICE: here we put the `slots.default()` inside the render function to make
|
|
9
|
-
// the slots reactive, otherwise the slot content won't be changed once the
|
|
10
|
-
// `setup()` function of current component is called
|
|
11
|
-
var _a;
|
|
12
|
-
// get children code-group-item
|
|
13
|
-
const items = (((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)) || [])
|
|
14
|
-
.filter((vnode) => vnode.type.name === 'CodeGroupItem')
|
|
15
|
-
.map((vnode) => {
|
|
16
|
-
if (vnode.props === null) {
|
|
17
|
-
vnode.props = {};
|
|
18
|
-
}
|
|
19
|
-
return vnode;
|
|
20
|
-
});
|
|
21
|
-
// do not render anything if there is no code-group-item
|
|
22
|
-
if (items.length === 0) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
if (activeIndex.value === -1) {
|
|
26
|
-
// initial state
|
|
27
|
-
// find the index of the code-group-item with `active` props
|
|
28
|
-
activeIndex.value = items.findIndex((vnode) => vnode.props.active === '' || vnode.props.active === true);
|
|
29
|
-
// if there is no `active` props on code-group-item, set the first item active
|
|
30
|
-
if (activeIndex.value === -1) {
|
|
31
|
-
activeIndex.value = 0;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
// re-render triggered by modifying `activeIndex` ref
|
|
36
|
-
// set the active item
|
|
37
|
-
items.forEach((vnode, i) => {
|
|
38
|
-
vnode.props.active = i === activeIndex.value;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return h('div', { class: 'code-group' }, [
|
|
42
|
-
h('div', { class: 'code-group__nav' }, h('ul', { class: 'code-group__ul' }, items.map((vnode, i) => h('li', { class: 'code-group__li' }, h('button', {
|
|
43
|
-
class: `code-group__nav-tab${i === activeIndex.value
|
|
44
|
-
? ' code-group__nav-tab-active'
|
|
45
|
-
: ''}`,
|
|
46
|
-
onClick: () => (activeIndex.value = i),
|
|
47
|
-
}, vnode.props.title))))),
|
|
48
|
-
items,
|
|
49
|
-
]);
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="code-group-item" :class="{ 'code-group-item__active': active }">
|
|
3
|
-
<slot />
|
|
4
|
-
</div>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script>
|
|
8
|
-
import { defineComponent } from 'vue'
|
|
9
|
-
|
|
10
|
-
export default defineComponent({
|
|
11
|
-
name: 'CodeGroupItem',
|
|
12
|
-
|
|
13
|
-
props: {
|
|
14
|
-
title: {
|
|
15
|
-
type: String,
|
|
16
|
-
required: true,
|
|
17
|
-
},
|
|
18
|
-
active: {
|
|
19
|
-
type: Boolean,
|
|
20
|
-
required: false,
|
|
21
|
-
default: false,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
})
|
|
25
|
-
</script>
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<RawOutboundLink>
|
|
3
|
-
<span class="sr-only">{{ themeLocale.openInNewWindow }}</span>
|
|
4
|
-
</RawOutboundLink>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script>
|
|
8
|
-
import { defineComponent } from 'vue'
|
|
9
|
-
import { OutboundLink } from '@vuepress/client'
|
|
10
|
-
import { useThemeLocaleData } from '../../composables'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Override the built-in `<OutboundLink>` for a11y
|
|
14
|
-
*/
|
|
15
|
-
export default defineComponent({
|
|
16
|
-
name: 'OutboundLink',
|
|
17
|
-
|
|
18
|
-
components: {
|
|
19
|
-
RawOutboundLink: OutboundLink,
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
setup() {
|
|
23
|
-
const themeLocale = useThemeLocaleData()
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
themeLocale,
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
})
|
|
30
|
-
</script>
|
package/lib/composables/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ComputedRef, InjectionKey } from 'vue';
|
|
2
|
-
import type { PageHeader } from '@vuepress/client';
|
|
3
|
-
import type { DefaultThemeData, DefaultThemePageFrontmatter, SidebarConfigArray, SidebarConfigObject, ResolvedSidebarItem } from '../types';
|
|
4
|
-
export declare type SidebarItemsRef = ComputedRef<ResolvedSidebarItem[]>;
|
|
5
|
-
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
6
|
-
/**
|
|
7
|
-
* Inject sidebar items global computed
|
|
8
|
-
*/
|
|
9
|
-
export declare const useSidebarItems: () => SidebarItemsRef;
|
|
10
|
-
/**
|
|
11
|
-
* Resolve sidebar items global computed
|
|
12
|
-
*
|
|
13
|
-
* It should only be resolved and provided once
|
|
14
|
-
*/
|
|
15
|
-
export declare const resolveSidebarItems: (frontmatter: DefaultThemePageFrontmatter, themeLocale: DefaultThemeData) => ResolvedSidebarItem[];
|
|
16
|
-
/**
|
|
17
|
-
* Util to transform page header to sidebar item
|
|
18
|
-
*/
|
|
19
|
-
export declare const headerToSidebarItem: (header: PageHeader) => ResolvedSidebarItem;
|
|
20
|
-
/**
|
|
21
|
-
* Resolve sidebar items if the config is `auto`
|
|
22
|
-
*/
|
|
23
|
-
export declare const resolveAutoSidebarItems: () => ResolvedSidebarItem[];
|
|
24
|
-
/**
|
|
25
|
-
* Resolve sidebar items if the config is an array
|
|
26
|
-
*/
|
|
27
|
-
export declare const resolveArraySidebarItems: (sidebarConfig: SidebarConfigArray) => ResolvedSidebarItem[];
|
|
28
|
-
/**
|
|
29
|
-
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
30
|
-
*/
|
|
31
|
-
export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarConfigObject) => ResolvedSidebarItem[];
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { inject } from 'vue';
|
|
2
|
-
import { useRoute } from 'vue-router';
|
|
3
|
-
import { usePageData } from '@vuepress/client';
|
|
4
|
-
import { isArray, isPlainObject, isString, resolveLocalePath, } from '@vuepress/shared';
|
|
5
|
-
import { useNavLink } from './useNavLink';
|
|
6
|
-
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
7
|
-
/**
|
|
8
|
-
* Inject sidebar items global computed
|
|
9
|
-
*/
|
|
10
|
-
export const useSidebarItems = () => {
|
|
11
|
-
const sidebarItems = inject(sidebarItemsSymbol);
|
|
12
|
-
if (!sidebarItems) {
|
|
13
|
-
throw new Error('useSidebarItems() is called without provider.');
|
|
14
|
-
}
|
|
15
|
-
return sidebarItems;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Resolve sidebar items global computed
|
|
19
|
-
*
|
|
20
|
-
* It should only be resolved and provided once
|
|
21
|
-
*/
|
|
22
|
-
export const resolveSidebarItems = (frontmatter, themeLocale) => {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
// get sidebar config from frontmatter > themeConfig
|
|
25
|
-
const sidebarConfig = (_b = (_a = frontmatter.sidebar) !== null && _a !== void 0 ? _a : themeLocale.sidebar) !== null && _b !== void 0 ? _b : 'auto';
|
|
26
|
-
// resolve sidebar items according to the config
|
|
27
|
-
if (frontmatter.home === true || sidebarConfig === false) {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
if (sidebarConfig === 'auto') {
|
|
31
|
-
return resolveAutoSidebarItems();
|
|
32
|
-
}
|
|
33
|
-
if (isArray(sidebarConfig)) {
|
|
34
|
-
return resolveArraySidebarItems(sidebarConfig);
|
|
35
|
-
}
|
|
36
|
-
if (isPlainObject(sidebarConfig)) {
|
|
37
|
-
return resolveMultiSidebarItems(sidebarConfig);
|
|
38
|
-
}
|
|
39
|
-
return [];
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Util to transform page header to sidebar item
|
|
43
|
-
*/
|
|
44
|
-
export const headerToSidebarItem = (header) => ({
|
|
45
|
-
text: header.title,
|
|
46
|
-
link: `#${header.slug}`,
|
|
47
|
-
children: header.children.map(headerToSidebarItem),
|
|
48
|
-
});
|
|
49
|
-
/**
|
|
50
|
-
* Resolve sidebar items if the config is `auto`
|
|
51
|
-
*/
|
|
52
|
-
export const resolveAutoSidebarItems = () => {
|
|
53
|
-
const page = usePageData();
|
|
54
|
-
return [
|
|
55
|
-
{
|
|
56
|
-
isGroup: true,
|
|
57
|
-
text: page.value.title,
|
|
58
|
-
children: page.value.headers.map(headerToSidebarItem),
|
|
59
|
-
},
|
|
60
|
-
];
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Resolve sidebar items if the config is an array
|
|
64
|
-
*/
|
|
65
|
-
export const resolveArraySidebarItems = (sidebarConfig) => {
|
|
66
|
-
const route = useRoute();
|
|
67
|
-
const page = usePageData();
|
|
68
|
-
const handleChildItem = (item) => {
|
|
69
|
-
let childItem;
|
|
70
|
-
if (isString(item)) {
|
|
71
|
-
childItem = useNavLink(item);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
childItem = item;
|
|
75
|
-
}
|
|
76
|
-
if (childItem.isGroup && childItem.children) {
|
|
77
|
-
return {
|
|
78
|
-
...childItem,
|
|
79
|
-
children: childItem.children.map(handleChildItem),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
// if the sidebar item is current page and children is not set
|
|
83
|
-
// use headers of current page as children
|
|
84
|
-
if (childItem.link === route.path && childItem.children === undefined) {
|
|
85
|
-
return {
|
|
86
|
-
...childItem,
|
|
87
|
-
children: page.value.headers.map(headerToSidebarItem),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
return childItem;
|
|
91
|
-
};
|
|
92
|
-
return sidebarConfig.map((item) => {
|
|
93
|
-
if (isString(item)) {
|
|
94
|
-
return useNavLink(item);
|
|
95
|
-
}
|
|
96
|
-
if (!item.isGroup) {
|
|
97
|
-
return item;
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
...item,
|
|
101
|
-
children: item.children.map(handleChildItem),
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
107
|
-
*/
|
|
108
|
-
export const resolveMultiSidebarItems = (sidebarConfig) => {
|
|
109
|
-
var _a;
|
|
110
|
-
const route = useRoute();
|
|
111
|
-
const sidebarPath = resolveLocalePath(sidebarConfig, route.path);
|
|
112
|
-
const matchedSidebarConfig = (_a = sidebarConfig[sidebarPath]) !== null && _a !== void 0 ? _a : [];
|
|
113
|
-
return resolveArraySidebarItems(matchedSidebarConfig);
|
|
114
|
-
};
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.defaultTheme = void 0;
|
|
14
|
-
const utils_1 = require("@vuepress/utils");
|
|
15
|
-
const node_1 = require("./node");
|
|
16
|
-
__exportStar(require("./node"), exports);
|
|
17
|
-
__exportStar(require("./types"), exports);
|
|
18
|
-
const defaultTheme = ({ themePlugins = {}, ...localeOptions }) => {
|
|
19
|
-
node_1.assignDefaultLocaleOptions(localeOptions);
|
|
20
|
-
return {
|
|
21
|
-
name: '@vuepress/theme-default',
|
|
22
|
-
layouts: utils_1.path.resolve(__dirname, './layouts'),
|
|
23
|
-
clientAppEnhanceFiles: utils_1.path.resolve(__dirname, './clientAppEnhance.js'),
|
|
24
|
-
clientAppSetupFiles: utils_1.path.resolve(__dirname, './clientAppSetup.js'),
|
|
25
|
-
// use the relative file path to generate edit link
|
|
26
|
-
extendsPageData: ({ filePathRelative }) => ({ filePathRelative }),
|
|
27
|
-
plugins: [
|
|
28
|
-
[
|
|
29
|
-
'@vuepress/active-header-links',
|
|
30
|
-
node_1.resolveActiveHeaderLinksPluginOptions(themePlugins),
|
|
31
|
-
],
|
|
32
|
-
['@vuepress/back-to-top', themePlugins.backToTop !== false],
|
|
33
|
-
[
|
|
34
|
-
'@vuepress/container',
|
|
35
|
-
node_1.resolveContainerPluginOptions(themePlugins, localeOptions, 'tip'),
|
|
36
|
-
],
|
|
37
|
-
[
|
|
38
|
-
'@vuepress/container',
|
|
39
|
-
node_1.resolveContainerPluginOptions(themePlugins, localeOptions, 'warning'),
|
|
40
|
-
],
|
|
41
|
-
[
|
|
42
|
-
'@vuepress/container',
|
|
43
|
-
node_1.resolveContainerPluginOptions(themePlugins, localeOptions, 'danger'),
|
|
44
|
-
],
|
|
45
|
-
[
|
|
46
|
-
'@vuepress/container',
|
|
47
|
-
node_1.resolveContainerPluginOptionsForDetails(themePlugins),
|
|
48
|
-
],
|
|
49
|
-
[
|
|
50
|
-
'@vuepress/container',
|
|
51
|
-
node_1.resolveContainerPluginOptionsForCodeGroup(themePlugins),
|
|
52
|
-
],
|
|
53
|
-
[
|
|
54
|
-
'@vuepress/container',
|
|
55
|
-
node_1.resolveContainerPluginOptionsForCodeGroupItem(themePlugins),
|
|
56
|
-
],
|
|
57
|
-
['@vuepress/git', node_1.resolveGitPluginOptions(themePlugins, localeOptions)],
|
|
58
|
-
['@vuepress/medium-zoom', node_1.resolveMediumZoomPluginOptions(themePlugins)],
|
|
59
|
-
['@vuepress/nprogress', themePlugins.nprogress !== false],
|
|
60
|
-
['@vuepress/palette', { preset: 'sass' }],
|
|
61
|
-
['@vuepress/prismjs', themePlugins.prismjs !== false],
|
|
62
|
-
['@vuepress/theme-data', { themeData: localeOptions }],
|
|
63
|
-
],
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
exports.defaultTheme = defaultTheme;
|
|
67
|
-
exports.default = exports.defaultTheme;
|
package/lib/layouts/404.vue
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="theme-container">
|
|
3
|
-
<div class="theme-default-content">
|
|
4
|
-
<h1>404</h1>
|
|
5
|
-
|
|
6
|
-
<blockquote>{{ getMsg() }}</blockquote>
|
|
7
|
-
|
|
8
|
-
<RouterLink :to="homeLink">{{ homeText }}</RouterLink>
|
|
9
|
-
</div>
|
|
10
|
-
</div>
|
|
11
|
-
</template>
|
|
12
|
-
|
|
13
|
-
<script lang="ts">
|
|
14
|
-
import { defineComponent } from 'vue'
|
|
15
|
-
import { useRouteLocale } from '@vuepress/client'
|
|
16
|
-
import { useThemeLocaleData } from '../composables'
|
|
17
|
-
|
|
18
|
-
export default defineComponent({
|
|
19
|
-
name: '404',
|
|
20
|
-
|
|
21
|
-
setup() {
|
|
22
|
-
const routeLocale = useRouteLocale()
|
|
23
|
-
const themeLocale = useThemeLocaleData()
|
|
24
|
-
|
|
25
|
-
const messages = themeLocale.value.notFound ?? ['Not Found']
|
|
26
|
-
const getMsg = (): string =>
|
|
27
|
-
messages[Math.floor(Math.random() * messages.length)]
|
|
28
|
-
const homeLink = themeLocale.value.home ?? routeLocale.value
|
|
29
|
-
const homeText = themeLocale.value.backToHome ?? 'Back to home'
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
getMsg,
|
|
33
|
-
homeLink,
|
|
34
|
-
homeText,
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
})
|
|
38
|
-
</script>
|