Skip to content

Commit 4433716

Browse files
committed
added padding to changelog markdown component
fixed hash being applied when navigating to main added setting to en-/disable auto scrolling updated focus styling in packageHeader header anchor is now by default not visible changelog release cards are lazy & hydrate on interaction using useLazyFetch to prevent blocking
1 parent 44fffff commit 4433716

File tree

10 files changed

+1604
-1558
lines changed

10 files changed

+1604
-1558
lines changed

app/components/Changelog/Card.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ function navigateToTitle() {
5555
/>
5656
<!-- :active-id="activeTocId" -->
5757
</div>
58-
<DateTime v-if="release.publishedAt" :datetime="release.publishedAt" date-style="medium" />
58+
<DateTime
59+
v-if="release.publishedAt"
60+
:datetime="release.publishedAt"
61+
date-style="medium"
62+
class="mb-2 block"
63+
/>
5964
<Readme v-if="release.html" :html="release.html"></Readme>
6065
</section>
6166
</template>
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11
<script setup lang="ts">
2-
const { info, requestedVersion, tpTarget } = defineProps<{
2+
const { info, goToVersion, tpTarget } = defineProps<{
33
info: ChangelogMarkdownInfo
4-
requestedVersion: string | null | undefined
4+
goToVersion: string | null | undefined
55
tpTarget?: HTMLElement | null
66
}>()
77
88
const route = useRoute()
99
10-
const { data, error } = await useFetch(
10+
const { data, error } = await useLazyFetch(
1111
() => `/api/changelog/md/${info.provider}/${info.repo}/${info.path}`,
1212
)
1313
1414
if (import.meta.client) {
15+
const { settings } = useSettings()
16+
1517
// doing this server side can make it that we go to the homepage
16-
watchEffect(() => {
18+
const stopWatching = watchEffect(() => {
1719
const toc = data.value?.toc
1820
1921
if (toc && route.hash) {
20-
navigateTo(route.hash)
21-
return
22+
// scroll if there is a hash in the url
23+
return navigateTo(route.hash)
2224
}
23-
if (!toc || !requestedVersion || route.hash) {
25+
26+
// don't allow auto scrolling when disabled and there was no hash before
27+
if (!settings.value.changelogAutoScroll || !toc || !goToVersion || route.hash) {
2428
return
2529
}
2630
// lc = lower case
27-
const lcRequestedVersion = requestedVersion.toLowerCase()
31+
const lcRequestedVersion = goToVersion.toLowerCase()
2832
for (const item of toc) {
2933
if (item.text.toLowerCase().includes(lcRequestedVersion)) {
3034
navigateTo(`#${item.id}`)
3135
return
3236
}
3337
}
3438
})
39+
40+
// stops watchEffect from trigger just before navigating
41+
onBeforeRouteLeave(stopWatching)
3542
}
3643
</script>
3744
<template>
3845
<Teleport v-if="data?.toc && data.toc.length > 1 && !!tpTarget" :to="tpTarget">
3946
<ReadmeTocDropdown :toc="data.toc" class="justify-self-end" />
4047
</Teleport>
41-
<Readme v-if="data?.html" :html="data.html"></Readme>
48+
<Readme v-if="data?.html" :html="data.html" class="pt-4"></Readme>
4249
<slot v-else-if="error" name="error"></slot>
4350
</template>

app/components/Changelog/Releases.vue

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script setup lang="ts">
22
import { slugify } from '~~/shared/utils/html'
33
4-
const { info, requestedDate, requestedVersion } = defineProps<{
4+
const { info, requestedDate, goToVersion } = defineProps<{
55
info: ChangelogReleaseInfo
66
requestedDate?: string
7-
requestedVersion?: string | null | undefined
7+
goToVersion?: string | null | undefined
88
}>()
99
10-
const { data: releases, error } = await useFetch<ReleaseData[]>(
10+
const { data: releases, error } = await useLazyFetch<ReleaseData[]>(
1111
() => `/api/changelog/releases/${info.provider}/${info.repo}`,
1212
)
1313
@@ -27,15 +27,22 @@ const matchingDateReleases = computed(() => {
2727
})
2828
2929
if (import.meta.client) {
30+
const { settings } = useSettings()
31+
3032
// doing this server side can make it that we go to the homepage
31-
watchEffect(() => {
33+
const stopWatching = watchEffect(() => {
3234
const uReleases = releases.value
3335
if (route.hash && uReleases) {
36+
// scroll if there is a hash in the url
3437
navigateTo(route.hash, { replace: true })
3538
return
3639
}
40+
// don't allow auto scrolling when disabled and there was no hash before
41+
if (!settings.value.changelogAutoScroll) {
42+
return
43+
}
3744
const date = requestedDate?.toLowerCase()
38-
if (route.hash || !date || !uReleases) {
45+
if (route.hash || !date || !uReleases || !goToVersion) {
3946
return
4047
}
4148
const uMatchingDateReleases = matchingDateReleases.value
@@ -44,21 +51,28 @@ if (import.meta.client) {
4451
return
4552
}
4653
47-
if (requestedVersion) {
54+
if (goToVersion) {
4855
for (const match of uMatchingDateReleases) {
49-
if (match.title.toLowerCase().includes(requestedVersion)) {
56+
if (match.title.toLowerCase().includes(goToVersion)) {
5057
navigateTo(`#release-${slugify(match.title)}`, { replace: true })
5158
return
5259
}
5360
}
5461
}
5562
navigateTo(`#date-${date}`, { replace: true })
5663
})
64+
// stops watchEffect from trigger just before navigating
65+
onBeforeRouteLeave(stopWatching)
5766
}
5867
</script>
5968
<template>
6069
<div class="flex flex-col gap-2 py-3" v-if="releases">
61-
<ChangelogCard v-for="release of releases" :release :key="release.id" />
70+
<LazyChangelogCard
71+
v-for="release of releases"
72+
:release
73+
:key="release.id"
74+
hydrate-on-interaction
75+
/>
6276
</div>
6377
<slot v-else-if="error" name="error"></slot>
6478
</template>

app/components/Package/Header.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ const fundingUrl = computed(() => {
382382
v-if="changelogLink"
383383
:to="changelogLink"
384384
aria-keyshortcuts="-"
385-
class="decoration-none border-b-2 p-1 hover:border-accent/50"
385+
class="decoration-none border-b-2 p-1 hover:border-accent/50 focus-visible:[outline-offset:-2px]!"
386386
:class="page === 'changelog' ? 'border-accent text-accent!' : 'border-transparent'"
387387
>
388388
{{ $t('package.links.changelog') }}

app/composables/useSettings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface AppSettings {
3333
instantSearch: boolean
3434
/** Enable/disable keyboard shortcuts */
3535
keyboardShortcuts: boolean
36+
/** Enable/disable auto scrolling to requested version at package changelog */
37+
changelogAutoScroll: boolean
3638
/** Connector preferences */
3739
connector: {
3840
/** Automatically open the web auth page in the browser */
@@ -60,6 +62,7 @@ const DEFAULT_SETTINGS: AppSettings = {
6062
searchProvider: import.meta.test ? 'npm' : 'algolia',
6163
instantSearch: true,
6264
keyboardShortcuts: true,
65+
changelogAutoScroll: true,
6366
connector: {
6467
autoOpenURL: false,
6568
},

app/pages/package-changelog/[[org]]/[name].vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ defineOgImageComponent('Default', {
131131
<LazyChangelogReleases
132132
v-if="changelog?.type === 'release'"
133133
:info="changelog"
134-
:requestedDate="versionDate"
135-
:requested-version="version"
134+
:requested-date="versionDate"
135+
:goToVersion="requestedVersion && version"
136136
#error
137137
>
138138
<LazyChangelogErrorMsg
@@ -145,7 +145,7 @@ defineOgImageComponent('Default', {
145145
v-else-if="changelog?.type === 'md'"
146146
:info="changelog"
147147
:tpTarget="tptoc"
148-
:requested-version="version"
148+
:goToVersion="requestedVersion && version"
149149
#error
150150
>
151151
<LazyChangelogErrorMsg
@@ -180,6 +180,6 @@ defineOgImageComponent('Default', {
180180

181181
<style module>
182182
.changelog :global(.readme) :is(h1, h2, h3, h4, h5, h6) a[href^='#']::after {
183-
content: unset !important;
183+
/* content: unset !important; */
184184
}
185185
</style>

app/pages/settings.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ const setLocale: typeof setNuxti18nLocale = newLocale => {
143143
:description="$t('settings.enable_graph_pulse_loop_description')"
144144
v-model="settings.enableGraphPulseLooping"
145145
/>
146+
147+
<div class="border-t border-border my-4" />
148+
149+
<!-- Enable auto scrolling to requested version at package changelog -->
150+
<SettingsToggle
151+
:label="$t('settings.enable_changelog_autoscroll')"
152+
:description="$t('settings.enable_changelog_autoscroll_description')"
153+
v-model="settings.changelogAutoScroll"
154+
/>
146155
</div>
147156
</section>
148157

0 commit comments

Comments
 (0)