From 07d8163649965a24480463da9320b2aa3652a219 Mon Sep 17 00:00:00 2001 From: Kia King Ishii Date: Thu, 19 Nov 2020 02:00:22 +0900 Subject: [PATCH 1/4] fix: fix next and prev links not working --- .../theme-default/components/EditLink.vue | 1 + .../components/NextAndPrevLinks.ts | 61 ------------- .../components/NextAndPrevLinks.vue | 32 ++++--- .../composables/nextAndPrevLinks.ts | 86 +++++++++++-------- src/node/server.ts | 57 +----------- types/shared.d.ts | 2 - 6 files changed, 69 insertions(+), 170 deletions(-) delete mode 100644 src/client/theme-default/components/NextAndPrevLinks.ts diff --git a/src/client/theme-default/components/EditLink.vue b/src/client/theme-default/components/EditLink.vue index df2a9aa3259f..7a464e16a243 100644 --- a/src/client/theme-default/components/EditLink.vue +++ b/src/client/theme-default/components/EditLink.vue @@ -49,5 +49,6 @@ export default defineComponent({ margin-left: 4px; width: 1rem; height: 1rem; + transform: translateY(-1px); } diff --git a/src/client/theme-default/components/NextAndPrevLinks.ts b/src/client/theme-default/components/NextAndPrevLinks.ts deleted file mode 100644 index 09572b88c0f9..000000000000 --- a/src/client/theme-default/components/NextAndPrevLinks.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { computed } from 'vue' -import { useRoute, useSiteData } from 'vitepress' -import { DefaultTheme } from '../config' - -export default { - setup() { - const route = useRoute() - // TODO: could this be useSiteData or is the siteData - // resolved and has a different structure? - const siteData = useSiteData() - - const resolveLink = (targetLink: string) => { - let target: DefaultTheme.SideBarLink | undefined - Object.keys(siteData.value.themeConfig.sidebar).some((k) => { - return siteData.value.themeConfig.sidebar[k].some( - (v: { children: any }) => { - if (Array.isArray(v.children)) { - target = v.children.find((value: any) => { - return value.link === targetLink - }) - } - return !!target - } - ) - }) - return target - } - - const next = computed(() => { - const pageData = route.data - if (pageData.frontmatter.next === false) { - return undefined - } - if (typeof pageData.frontmatter.next === 'string') { - return resolveLink(pageData.frontmatter.next) - } - return pageData.next - }) - - const prev = computed(() => { - const pageData = route.data - if (pageData.frontmatter.prev === false) { - return undefined - } - if (typeof pageData.frontmatter.prev === 'string') { - return resolveLink(pageData.frontmatter.prev) - } - return pageData.prev - }) - - const hasLinks = computed(() => { - return !!next || !!prev - }) - - return { - next, - prev, - hasLinks - } - } -} diff --git a/src/client/theme-default/components/NextAndPrevLinks.vue b/src/client/theme-default/components/NextAndPrevLinks.vue index f8879fa6fe38..3ebaa70eaa65 100644 --- a/src/client/theme-default/components/NextAndPrevLinks.vue +++ b/src/client/theme-default/components/NextAndPrevLinks.vue @@ -1,16 +1,18 @@ @@ -41,6 +43,10 @@ export default defineComponent({