Skip to content

Commit c8223fe

Browse files
StanG4313d0rich
andauthored
[DO-557] handle trailing slashes (#42)
* Functionality implemented * Type error fix * util function renamed * util function file renamed * undefined input disabled * make linter happy * Update components/ep/layout/SurroundDocCard.vue --------- Co-authored-by: Nikolai Dorofeev <[email protected]>
1 parent 028a6ca commit c8223fe

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

components/content/ProseA.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 setup lang="ts">
18+
import { withTrailingSlash } from '../../utils/navigation'
19+
20+
defineProps({
21+
href: {
22+
type: String,
23+
default: ''
24+
},
25+
target: {
26+
type: String,
27+
default: undefined,
28+
required: false
29+
}
30+
})
31+
</script>
32+
33+
<template>
34+
<NuxtLink :href="withTrailingSlash(href)" :target="target">
35+
<slot />
36+
</NuxtLink>
37+
</template>

components/ep/layout/ContentNavigationItem.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@click="showChildren = !showChildren"
3333
/>
3434
<NuxtLink
35-
:to="navItem._path"
35+
:to="withTrailingSlash(navItem._path)"
3636
class="w-full"
3737
@click="showContentTree = false"
3838
>
@@ -55,6 +55,7 @@
5555
<script lang="ts">
5656
import { defineComponent } from 'vue'
5757
import { NavItem } from '@nuxt/content/dist/runtime/types'
58+
import { withTrailingSlash } from '../../../utils/navigation'
5859
5960
export default defineComponent({
6061
name: 'ContentNavigationItem',
@@ -71,7 +72,8 @@ export default defineComponent({
7172
setup() {
7273
return {
7374
showChildren: ref(false),
74-
showContentTree: useShowContentTree()
75+
showContentTree: useShowContentTree(),
76+
withTrailingSlash
7577
}
7678
},
7779
computed: {

components/ep/layout/SurroundDocCard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<script lang="ts">
1818
import { ParsedContent } from '@nuxt/content/dist/runtime/types'
19+
import { withTrailingSlash } from '../../../utils/navigation'
1920
export default {
2021
name: 'EpLayoutSurroundDocCard'
2122
}
@@ -30,7 +31,7 @@ defineProps<{
3031

3132
<template>
3233
<NuxtLink
33-
:to="doc._path"
34+
:to="withTrailingSlash(doc._path ?? '')"
3435
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"
3536
>
3637
<div>

server/routes/sitemap.xml.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { SitemapStream, streamToPromise } from 'sitemap'
1818
import { joinURL, parseURL, withProtocol } from 'ufo'
19+
import { withTrailingSlash } from '../../utils/navigation'
1920
import { serverQueryContent } from '#content/server'
2021
const appConfig = useAppConfig()
2122

@@ -38,7 +39,7 @@ export default defineEventHandler(async (event) => {
3839
continue
3940
}
4041
sitemap.write({
41-
url: joinURL(path.pathname, doc._path),
42+
url: withTrailingSlash(joinURL(path.pathname, doc._path)),
4243
changefreq: 'monthly'
4344
})
4445
}

utils/navigation.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 as ufoWithTrailingSlash } from 'ufo'
18+
19+
export function withTrailingSlash(str: string): string {
20+
return ufoWithTrailingSlash(str)
21+
}

0 commit comments

Comments
 (0)