-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathMarkdown.vue
More file actions
57 lines (50 loc) · 1.68 KB
/
Markdown.vue
File metadata and controls
57 lines (50 loc) · 1.68 KB
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
<script setup lang="ts">
const { info, goToVersion, tpTarget, resolveVersionPending } = defineProps<{
info: ChangelogMarkdownInfo
goToVersion: string | null | undefined
tpTarget?: HTMLElement | null
resolveVersionPending?: boolean
}>()
const route = useRoute()
const { data, error } = await useLazyFetch(
() => `/api/changelog/md/${info.provider}/${info.repo}/${info.path}`,
)
if (import.meta.client) {
const { settings } = useSettings()
// doing this server side can make it that we go to the homepage
const stopWatching = watchEffect(
() => {
if (resolveVersionPending) {
return // need to wait till resolving is finished
}
const toc = data.value?.toc
if (toc && route.hash) {
// scroll if there is a hash in the url
return navigateTo(route.hash)
}
// don't allow auto scrolling when disabled and there was no hash before
if (!settings.value.changelogAutoScroll || !toc || !goToVersion || route.hash) {
return
}
// lc = lower case
const lcRequestedVersion = goToVersion.toLowerCase()
for (const item of toc) {
if (item.text.toLowerCase().includes(lcRequestedVersion)) {
navigateTo(`#${item.id}`)
return
}
}
},
{ flush: 'post' },
)
// stops watchEffect from trigger just before navigating
onBeforeRouteLeave(stopWatching)
}
</script>
<template>
<Teleport v-if="data?.toc && data.toc.length > 1 && !!tpTarget" :to="tpTarget">
<ReadmeTocDropdown :toc="data.toc" class="justify-self-end" />
</Teleport>
<Readme v-if="data?.html" :html="data.html" class="pt-4"></Readme>
<slot v-else-if="error" name="error"></slot>
</template>