summaryrefslogtreecommitdiff
path: root/smoke/docs-main/src/components/PageContent/PageContent.astro
blob: 849ff4de4cd0e31256a40b6e16c70d3ca2bb88e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
import MoreMenu from '../RightSidebar/MoreMenu.astro';
import ArticleNavigationButton from './ArticleNavigationButton.astro';
import TableOfContents from '../RightSidebar/TableOfContents.tsx';
import { getLanguageFromURL } from '../../util.ts';
import { SIDEBAR } from '../../config.ts';
const { content, githubEditUrl, currentPage } = Astro.props;
const title = content.title;
const headers = content.astro?.headers;
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;
---

<article id="article" class="content">
	<section class="main-section">
		<h1 class="content-title" id="overview">{title}</h1>
		{headers && (
			<nav class="block lg-hidden">
				<TableOfContents client:media="(max-width: 50em)" headers={headers} />
				<MoreMenu editHref={githubEditUrl} />
			</nav>
		)}
		<slot />
	</section>
	{(previous || next) && (
		<aside class="next-previous-nav">
			{previous && <ArticleNavigationButton rel="prev" item={previous} />}
			{next && <ArticleNavigationButton rel="next" item={next} />}
		</aside>
	)}
</article>

<style>
	.content {
		padding: 0;
		max-width: 75ch;
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		margin: auto;
	}
	.content > section {
		margin-bottom: 4rem;
	}
	.block {
		display: block;
	}
	.next-previous-nav {
		display: flex;
		flex-wrap: wrap;
		width: auto;
		gap: 1rem;
		margin-bottom: 1.5rem;
	}

	@media (min-width: 72em) {
		.lg-hidden {
			display: none;
		}
	}
</style>