From f52b1d576b024443f737604d2220a0edb1571355 Mon Sep 17 00:00:00 2001 From: Yugo Ogura Date: Thu, 3 Sep 2020 12:15:18 +0900 Subject: [PATCH] feat: add prev/next links (#56) * feat: set Prev/Next to page data * feat: set links at the bottom of page * feat: hide next/prev links when themeConfig expressly set false --- .../components/NextAndPrevLinks.ts | 22 ++++++++++ .../components/NextAndPrevLinks.vue | 25 +++++++++++ src/client/theme-default/components/Page.vue | 8 ++++ src/node/server.ts | 41 ++++++++++++++++++- types/shared.d.ts | 2 + 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/client/theme-default/components/NextAndPrevLinks.ts create mode 100644 src/client/theme-default/components/NextAndPrevLinks.vue diff --git a/src/client/theme-default/components/NextAndPrevLinks.ts b/src/client/theme-default/components/NextAndPrevLinks.ts new file mode 100644 index 000000000000..9080a73ff9c1 --- /dev/null +++ b/src/client/theme-default/components/NextAndPrevLinks.ts @@ -0,0 +1,22 @@ +import { defineComponent, computed } from 'vue' +import { usePageData } from 'vitepress' + +export default defineComponent({ + setup() { + const pageData = usePageData() + const next = computed(() => { + return pageData.value.next + }) + const prev = computed(() => { + return pageData.value.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 new file mode 100644 index 000000000000..f15b9b079fe7 --- /dev/null +++ b/src/client/theme-default/components/NextAndPrevLinks.vue @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/src/client/theme-default/components/Page.vue b/src/client/theme-default/components/Page.vue index c2c3536c36e4..676886eaede5 100644 --- a/src/client/theme-default/components/Page.vue +++ b/src/client/theme-default/components/Page.vue @@ -1,9 +1,17 @@ + +