0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

docs: add a link to next article (#1308)

This commit is contained in:
Sam Chen 2021-09-05 23:16:44 +08:00 committed by GitHub
parent 1953c6113f
commit 8c69275f03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -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;
---
<style>
.content {
@ -38,4 +46,14 @@ import TableOfContents from '../RightSidebar/TableOfContents.tsx';
<nav class="block sm:hidden">
<MoreMenu editHref={githubEditUrl}/>
</nav>
{
(previous || next) && <aside>
{
previous && <div>Previous Article: <a rel="prev" href={new URL(previous.link, Astro.site).pathname}>{previous.text}</a></div>
}
{
next && <div>Next Article: <a rel="next" href={new URL(next.link, Astro.site).pathname}>{next.text}</a></div>
}
</aside>
}
</article>

View file

@ -111,7 +111,7 @@ const formatTitle = (content, SITE) => content.title ? `${content.title} 🚀 ${
<LeftSidebar currentPage={currentPage} />
</aside>
<div id="grid-main">
<PageContent content={content} githubEditUrl={githubEditUrl}>
<PageContent content={content} githubEditUrl={githubEditUrl} currentPage={currentPage}>
<slot />
</PageContent>
</div>