From 8c69275f035c3ddf2d8770b4a16ea47718d97c29 Mon Sep 17 00:00:00 2001 From: Sam Chen Date: Sun, 5 Sep 2021 23:16:44 +0800 Subject: [PATCH] docs: add a link to next article (#1308) --- .../components/PageContent/PageContent.astro | 20 ++++++++++++++++++- docs/src/layouts/MainLayout.astro | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/src/components/PageContent/PageContent.astro b/docs/src/components/PageContent/PageContent.astro index fd1e9d2423..564b8485bf 100644 --- a/docs/src/components/PageContent/PageContent.astro +++ b/docs/src/components/PageContent/PageContent.astro @@ -1,9 +1,17 @@ --- -const {content, githubEditUrl} = Astro.props; +const {content, githubEditUrl, currentPage} = Astro.props; const title = content.title; const headers = content.astro.headers; import MoreMenu from '../RightSidebar/MoreMenu.astro'; import TableOfContents from '../RightSidebar/TableOfContents.tsx'; +import {getLanguageFromURL} from '../../util.ts'; +import {SIDEBAR} from '../../config.ts'; +const langCode = getLanguageFromURL(currentPage); +const links = SIDEBAR[langCode].filter(x => x.link && typeof x.header === 'undefined'); +// handle cases with a trailing slash or not +const index = links.findIndex(x => `/${x.link}/` === currentPage || `/${x.link}` === currentPage); +const next = index !== -1 ? (index === links.length - 1 ? null : links[index + 1]) : null; +const previous = index !== -1 ? (index === 0 ? null : links[index - 1]) : null; ---