Skip to content

Commit acd60c7

Browse files
StanG4313d0rich
andauthored
21 implement next and previous pages links (#26)
* cards added * type fix * partial content fix * styles added * styles correction * trailing slash * Configure dark mode --------- Co-authored-by: Nikolay Dorofeev <[email protected]>
1 parent b6af57c commit acd60c7

File tree

3 files changed

+103
-3
lines changed

3 files changed

+103
-3
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!--
2+
~ Copyright 2023 Exactpro (Exactpro Systems Limited)
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<script lang="ts">
18+
import { ParsedContent } from '@nuxt/content/dist/runtime/types'
19+
export default {
20+
name: 'EpLayoutSurroundDocCard'
21+
}
22+
</script>
23+
24+
<script setup lang="ts">
25+
defineProps<{
26+
doc: ParsedContent
27+
direction: 'before' | 'after'
28+
}>()
29+
</script>
30+
31+
<template>
32+
<NuxtLink
33+
:to="doc._path"
34+
class="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700"
35+
>
36+
<div>
37+
<div v-if="direction === 'before'" class="mb-2">
38+
<span
39+
class="bg-secondary-100 text-gray-800 font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-gray-300"
40+
>
41+
<Icon name="ic:sharp-arrow-back-ios" class="leading-4 mb-1" />Previous
42+
<!--TODO: shink flexbox -->
43+
</span>
44+
</div>
45+
<div v-else class="mb-2">
46+
<span
47+
class="bg-secondary-100 text-gray-800 font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-gray-300"
48+
>Next
49+
50+
<Icon name="ic:sharp-arrow-forward-ios" class="leading-4 mb-1" />
51+
</span>
52+
</div>
53+
<h4 class="text-xl font-bold">{{ doc.title }}</h4>
54+
<p>{{ doc.description }}</p>
55+
</div>
56+
</NuxtLink>
57+
</template>

pages/[...slug].vue

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
<article class="mb-10">
2222
<ContentRenderer v-if="doc && doc._type === 'markdown'" :value="doc">
2323
<ContentRendererMarkdown :value="doc" class="gevamu-prose" />
24+
<nav
25+
class="justify-center grid sm:grid-cols-2 gap-8 items-start mt-32"
26+
>
27+
<EpLayoutSurroundDocCard
28+
v-if="doc.before"
29+
:doc="doc.before"
30+
direction="before"
31+
/>
32+
<EpLayoutSurroundDocCard
33+
v-if="doc.after"
34+
:doc="doc.after"
35+
direction="after"
36+
/>
37+
</nav>
2438
</ContentRenderer>
2539
<div v-else-if="doc" class="gevamu-prose w-screen">
2640
<h1>{{ doc._dir.title }} pages</h1>
@@ -33,16 +47,44 @@
3347
</template>
3448

3549
<script lang="ts">
50+
import {
51+
ParsedContent,
52+
MarkdownParsedContent
53+
} from '@nuxt/content/dist/runtime/types'
54+
55+
// TODO: check how to use native type instead of DocParsedContent
56+
interface DocParsedContent extends MarkdownParsedContent {
57+
_dir: { title: string }
58+
}
59+
function removeTrailingSlash(path: string) {
60+
if (path.endsWith('/')) {
61+
return path.slice(0, -1)
62+
}
63+
return path
64+
}
3665
export default defineComponent({
3766
name: 'ContentPage',
38-
async setup() {
67+
setup() {
3968
definePageMeta({
4069
layout: 'docs'
4170
})
4271
const route = useRoute()
4372
const toc = useToc()
44-
const { data: doc } = await useAsyncData('page-data' + route.path, () => {
45-
return queryContent(route.path).findOne()
73+
const { data: doc } = useAsyncData('page-data' + route.path, async () => {
74+
const docPromise = queryContent<DocParsedContent>(route.path).findOne()
75+
const surroundPromise = queryContent()
76+
.only(['_path', 'title', 'description', '_partial'])
77+
.where({ _partial: false })
78+
.findSurround(removeTrailingSlash(route.path), {
79+
before: 1,
80+
after: 1
81+
})
82+
const [doc, surround] = await Promise.all([docPromise, surroundPromise])
83+
return {
84+
...doc,
85+
before: surround[0] as ParsedContent,
86+
after: surround[1] as ParsedContent
87+
}
4688
})
4789
toc.value = doc.value?.body?.toc ?? null
4890

tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const defaultTheme = require('tailwindcss/defaultTheme') // eslint-disable-line
2020

2121
/** @type {import('tailwindcss').Config} */
2222
module.exports = {
23+
darkMode: 'class',
2324
theme: {
2425
extend: {
2526
fontFamily: {

0 commit comments

Comments
 (0)