Skip to content

Commit 1483afd

Browse files
Hdd87d0rich
andauthored
[DO-525] Implement breadcrumbs (#38)
* define breadcrumbs and call in slug * create an array of parents paths for current pg * create promises array with path and titles * add v-for to slug , and use Nuxtlink * replace div with span * adjust spacing and add a / * added if statement for when in home page * remove button * remove slash * improve formatting * remove variable route * update names * update loop for creating directory * return breadcrumbs instead of promises * change name to pathDirectory and update comments * fix error , unable to access docs in local * underline and text color for breadcrumbs * change from getBreadCrumbs to useBreadCrumbs * remove last crumb to show only previous paths * removed utils file, created composables file * display current page, separator and lintfix * adjust spacing * add the home icon to slug * use icon separator, default size for home * Update composables/useBreadcrumbs.ts Co-authored-by: Nikolai Dorofeev <[email protected]> * assign variable to useAsyncData * add template tag to separate v-for and v-if * convert breadcrumbs into synchronous function * remove first element of path array * display crumbs * add icon border , adjust spacing * fix type check error * add border with hover in color accent * border color black * border to nuxt link instead add bottom spacing * border color gray 600 * Apply suggestions from code review improve home icon's border , transform data into new variables Co-authored-by: Nikolai Dorofeev <[email protected]> * fix error _path doesnot exist * create breadcrumbs component * Add breadcrumbs component to slug * pass a prop to the component * add a required=true * remove unnecessary variables * lint fix, remove comments * remove unnecessary div * Apply suggestions from code review remove comments , add v-if statement to the Breadcrumbs component when assigning prop Co-authored-by: Nikolai Dorofeev <[email protected]> * update to w to new variable name * remove v-if from vue comp, as v-if is in props * fix bug by removing all empty strings * Update composables/breadcrumbs.ts Co-authored-by: Nikolai Dorofeev <[email protected]> --------- Co-authored-by: Nikolai Dorofeev <[email protected]>
1 parent c8223fe commit 1483afd

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
<template>
18+
<nav class="mb-4 flex flex-wrap items-center gap-x-2">
19+
<NuxtLink
20+
class="border border-solid rounded text-gray-600 border-gray-600 hover:border-accent-600 hover:text-accent-600 transition-colors p-1 inline-flex"
21+
to="/"
22+
>
23+
<Icon name="heroicons:home-20-solid" size="1.2em" />
24+
</NuxtLink>
25+
<Icon name="heroicons:chevron-right" />
26+
27+
<template v-for="(crumb, index) in breadcrumbs" :key="crumb._path">
28+
<template v-if="index < breadcrumbs.length - 1">
29+
<NuxtLink class="underline text-accent-600" :to="crumb.path">
30+
{{ crumb.title }}
31+
</NuxtLink>
32+
<Icon name="heroicons:chevron-right" />
33+
</template>
34+
<span v-else>
35+
{{ crumb.title }}
36+
</span>
37+
</template>
38+
</nav>
39+
</template>
40+
41+
<script lang="ts">
42+
export interface Breadcrumb {
43+
path: string
44+
title: string
45+
}
46+
47+
export default {
48+
props: {
49+
breadcrumbs: {
50+
type: Array as () => Breadcrumb[],
51+
required: true
52+
}
53+
}
54+
}
55+
</script>

composables/breadcrumbs.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
import { withTrailingSlash } from 'ufo'
18+
19+
export const useBreadcrumbs = () => {
20+
const currentPath = useRoute().path
21+
22+
const currentPathSections = currentPath.split('/').filter((el) => !!el)
23+
24+
const pathDirectory: string[] = []
25+
26+
// fill the pathDirectory with all paths
27+
let pathToAdd = ''
28+
if (currentPath !== '/') {
29+
for (let i = 0; i < currentPathSections?.length; i++) {
30+
pathToAdd = withTrailingSlash(pathToAdd + currentPathSections[i])
31+
pathDirectory.push(pathToAdd)
32+
}
33+
}
34+
35+
// extract titles and its path and create breadcrumbs object
36+
const breadcrumbs = useAsyncData(
37+
() => {
38+
return Promise.all(
39+
pathDirectory.map((path) =>
40+
queryContent(path).only(['_path', 'title']).findOne()
41+
)
42+
)
43+
},
44+
{
45+
transform: (data) =>
46+
data.map((item) => ({
47+
path: item._path,
48+
title: item.title
49+
}))
50+
}
51+
)
52+
return breadcrumbs
53+
}

pages/[...slug].vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<EpPageMeta :doc="doc" />
1919
<NuxtLayout>
2020
<div class="px-4 md:pr-6 print:px-8 mt-10 mb-96 print:mb-0">
21+
<EpLayoutBreadcrumbs v-if="breadcrumbs" :breadcrumbs="breadcrumbs" />
2122
<article class="mb-10">
2223
<ContentRenderer v-if="doc && doc._type === 'markdown'" :value="doc">
2324
<ContentRendererMarkdown :value="doc" class="gevamu-prose" />
@@ -65,6 +66,7 @@ export default defineComponent({
6566
definePageMeta({
6667
layout: 'docs'
6768
})
69+
6870
const route = useRoute()
6971
7072
const { data: doc } = useAsyncData('page-data' + route.path, async () => {
@@ -86,8 +88,11 @@ export default defineComponent({
8688
8789
useTocUpdate(doc)
8890
91+
const { data: breadcrumbs } = useBreadcrumbs()
92+
8993
return {
90-
doc
94+
doc,
95+
breadcrumbs
9196
}
9297
}
9398
})

0 commit comments

Comments
 (0)